SA-MP Forums Archive
OnPlayerUpdate- This or this? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerUpdate- This or this? (/showthread.php?tid=366692)



OnPlayerUpdate- This or this? - Roko_foko - 07.08.2012

What is better from this two examples:
What makes less lag?
I will give you rep+ if you convince me in something.
pawn Код:
public OnPlayerUpdate(playerid)
{
    new weapon=GetPlayerWeapon(playerid);
    if(weapon!=0)//No only 0 but every weapon that does not have ammo
    {
        new Str[45+MAX_PLAYER_NAME];
        new Ammo=GetPlayerAmmo(playerid);
        if(!DoesPlayerHaveWeapon(playerid,weapon))
        {
            format(Str,45+MAX_PLAYER_NAME,"Server: Possible weapon hack by %s[%d]!",RealisticName(gPlayerCharName[playerid]),playerid);
            SendClientMessageToAll(COLOR_RED,Str);
        }
        if(PlayerGunAmmo[playerid][weapon]<Ammo)
        {
            format(Str,43+MAX_PLAYER_NAME,"Server: Possible ammo hack by %s[%d]!",RealisticName(gPlayerCharName[playerid]),playerid);
            SendClientMessageToAll(COLOR_RED,Str);
        }
        //_______________________________________THIS-a)_____________________________________
        else if(PlayerGunAmmo[playerid][weapon]<Ammo)PlayerGunAmmo[playerid][weapon]=Ammo;//-
        //-----------------------------------------------------------------------------------
        //_______________________________________or THIS-b)_________________________________
        else PlayerGunAmmo[playerid][weapon]=Ammo;//---------------------------------------
        //----------------------------------------------------------------------------------
    }
}



Re: OnPlayerUpdate- This or this? - Dragony92 - 07.08.2012

Show us this public DoesPlayerHaveWeapon

This... Because if he have more ammo after B solution that ammo will be legal...
else if(PlayerGunAmmo[playerid][weapon]<ammo)PlayerGunAmmo[playerid][weapon]=Ammo;//-


Re: OnPlayerUpdate- This or this? - Ballu Miaa - 07.08.2012

Difference of time between those lines will only be fraction of milliseconds i guess.

If both of them accomplishes the tasks for what they are coded for. Then use the Line B. Less code = Less Time for Conversion/Execution.


Re: OnPlayerUpdate- This or this? - Roko_foko - 07.08.2012

pawn Код:
bool: DoesPlayerHaveWeapon(playerid,id)
{
    if(id<31)
    {
        if(PlayerHaveWeapon[playerid]&floatround(floatpower(2,id-1)))return true;
    }
    else if(PlayerHaveWeapon2[playerid]&floatround(floatpower(2,id-31)))return true;
    return false;
}
I know this won't help you much. You need more information about PlayerHaveWeapon(2). This function does just what it is said to. returns if player has specific weapon. And this function works fine. To make this easier for you I will ask the same question in different example:
what will be faster processed
pawn Код:
if(Var1!=Var2)
Var1=Var2;
or
pawn Код:
Var1=Var2;
Note: Mostly Var1==Var2( 99999 times of 100000 )


Re: OnPlayerUpdate- This or this? - Dragony92 - 07.08.2012

We are talking about 0,0000001 parts of second... However...