11.02.2014, 18:55
My bad. Forgot that switch case needs constants, not variables.
If you used an array to store those vehicle id's, it would be simpler and shorter:
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.
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;
}
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;
}
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.