Better, faster function?
#5

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;
        }
    }
}
Reply


Messages In This Thread
Better, faster function? - by ||123|| - 17.07.2011, 18:09
Re: Better, faster function? - by Mauzen - 17.07.2011, 18:21
Re: Better, faster function? - by ||123|| - 17.07.2011, 18:32
Re: Better, faster function? - by Mauzen - 17.07.2011, 19:01
Re: Better, faster function? - by MoroDan - 17.07.2011, 19:15
Re: Better, faster function? - by MrDeath537 - 17.07.2011, 19:36
Re: Better, faster function? - by ||123|| - 17.07.2011, 21:12

Forum Jump:


Users browsing this thread: 1 Guest(s)