[Include] e_static ● Easily check player states ● Version 1
#10

Quote:
Originally Posted by Excel™
Посмотреть сообщение
Does that code works... LOLZzz
Quote:
Originally Posted by Basssiiie
Посмотреть сообщение
One of the problems is here (and it's in every IsPlayerOn-vehicle function):
pawn Код:
stock IsPlayerOnBike(playerid)
{
        if(!IsPlayerInAnyVehicle(playerid)) return false;
        new
            Bikes[12]=
            {   581,509,481,421,462,510,463,522,461,448,586,468 },
                vehicleid=GetPlayerVehicleID(playerid);
        for(new i = 0; i < 12; i++)
        {
        if(GetVehicleModel(vehicleid) == Bikes[i])
                {   return true;        } else return false;
        }
}
It will only check if the player model is equal to the first model in the array, then it quits the function. Please, don't release stuff you haven't tested. It bothers me a lot when people do this. Someone could be struggling for days to find out why his script doesn't work, until he discovers out it's your script that is the actual problem. That's very annoying! That guy trusted you to delivered functions that actually work!


Also, in addition to what Pottus suggested, this would even be better:
pawn Код:
stock IsPlayerOnBike(playerid)
{
    new veh = GetPlayerVehicleID(playerid);
   
    if (veh)
    {
        switch (GetVehicleModel(veh))
        {
            case 581, 509, 481, 421, 462, 510, 463, 522, 461, 448, 586, 468: return true;
        }
    }
    return false;
}
This way you only call two functions, instead of three in Pottus' version. Besides that, it looks much cleaner and avoids repetitive code.
Your right IsPlayerInAnyVehicle(playerid)) is useless check, I should have noticed it as for the switch() your method is a better way to do it in terms of compactness but I like to list each out on it's own line it's easier for me to read/update if I need to. When you write a lot of functions that have a switch() compacting them down like that can be very confusing since none of the case are marked by comments it's good to keep things easily editable even if it is repetitive.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)