Quote:
Originally Posted by ||123||
Let's say I need to get a player's vehicle ID two times. Which version would be more faster and better and less memory consuming?
Version 1:
pawn Код:
if(GetPlayerVehicleID(playerid) == CPcar) { SetPlayerFacingAngle(playerid, 36.12); if(IsPlayerAdmin(playerid)) { SendClientMessage(playerid, This is a CP car!); return 1; } } if(GetPlayerVehicleID(playerid) == CPtruck) { SetPlayerFacingAngle(playerid, 31.13); if(IsPlayerAdmin(playerid)) { SendClientMessage(playerid, This is a CP truck!); return 1; } }
Version 2:
pawn Код:
new veh; veh = GetPlayerVehicleID(playerid); if(veh == CPcar) { SetPlayerFacingAngle(playerid, 36.12); if(IsPlayerAdmin(playerid)) { SendClientMessage(playerid, This is a CP car!); return 1; } } if(veh == CPtruck) { SetPlayerFacingAngle(playerid, 31.13); if(IsPlayerAdmin(playerid)) { SendClientMessage(playerid, This is a CP truck!); return 1; } }
I would also like to know, that in such a situation, should I use 'if' or 'else if' or 'else', in the second condition?
|
This it is:
pawn Код:
switch(GetPlayerVehicleID(playerid))
{
case CPcar:
{
SetPlayerFacingAngle(playerid, 36.12);
if(IsPlayerAdmin(playerid))
{
SendClientMessage(playerid, "This is a CP car!");
return 1;
}
}
case CPtruck:
{
SetPlayerFacingAngle(playerid, 31.13);
if(IsPlayerAdmin(playerid))
{
SendClientMessage(playerid, "This is a CP truck!");
return 1;
}
}
}