Vehicles Owned by 1 person, Script Bug
#6

My bad. Forgot that switch case needs constants, not variables.

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if ((vehicleid == gcar) || (vehicleid == gcar2) || (vehicleid == gcar3) || (vehicleid == gcar4) || (vehicleid == gcar5) || (vehicleid == gcar6) || (vehicleid == gcar7) || (vehicleid == gcar8) || (vehicleid == gcar9))
    {
            new PlayerName[24];
            GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
            if (strcmp(PlayerName,"Jason_Budley",true))
            {
                ClearAnimations(playerid);
                return 1;
            }
    }

    return 1;
}
If you used an array to store those vehicle id's, it would be simpler and shorter:
pawn Код:
new gcars[10];

// Somewhere:
gcars[0] = CreateVehicle(...
gcars[1] = Createvehicle(...
...
gcars[9] = CreateVehicle(...





public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    for (new i; i < sizeof(gcars); i++)
    {
        if (vehicleid == gcars[i])
        {
            new PlayerName[24];
            GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
            if (strcmp(PlayerName,"Jason_Budley",true))
            {
                ClearAnimations(playerid);
                return 1;
            }
        }
    }

    return 1;
}
If you increased the size of gcars to 20 for example, you don't even have to modify this code, as it loops through the entire array and checks if the vehicle you're trying to enter is one of those gcars.

With the first example, you would need to add 10 extra checks to that code and you risk another error to indicate your line has become too long.
Reply


Messages In This Thread
Vehicles Owned by 1 person, Script Bug - by Aerotactics - 11.02.2014, 18:30
Re: Vehicles Owned by 1 person, Script Bug - by PowerPC603 - 11.02.2014, 18:38
Re: Vehicles Owned by 1 person, Script Bug - by Aerotactics - 11.02.2014, 18:42
Re: Vehicles Owned by 1 person, Script Bug - by PowerPC603 - 11.02.2014, 18:46
Re: Vehicles Owned by 1 person, Script Bug - by Aerotactics - 11.02.2014, 18:46
Re: Vehicles Owned by 1 person, Script Bug - by PowerPC603 - 11.02.2014, 18:55
Re: Vehicles Owned by 1 person, Script Bug - by Aerotactics - 11.02.2014, 19:30

Forum Jump:


Users browsing this thread: 1 Guest(s)