OnPlayerUpdate- This or this?
#1

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;//---------------------------------------
        //----------------------------------------------------------------------------------
    }
}
Reply
#2

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;//-
Reply
#3

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.
Reply
#4

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 )
Reply
#5

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


Forum Jump:


Users browsing this thread: 1 Guest(s)