SA-MP Forums Archive
Question with OnPlayerUpdate - 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: Question with OnPlayerUpdate (/showthread.php?tid=287474)



Question with OnPlayerUpdate - BuLLeT[LTU] - 03.10.2011

Hello, I have 1 question. I want to use this on OnPlayerUpdate:

pawn Код:
public OnPlayerUpdate(playerid)
{
     new weaponid = GetPlayerWeapon(playerid);
     new ammo = GetPlayerAmmo(playerid);
     if(ammo !- lastammo[playerid])
     {
          OnPlayerChangeAmmo(playerid,oldammo,newammo,weaponid);
          lastammo[playerid] = ammo;
     }
     return 1;
}
Because OnPlayerUpdate gets called many times, is it possible that my callback OnPlayerChangeAmmo will be called on next player update, but wouldn't ended on the last ? Because earlier i had a bug with familiar script.


Re: Question with OnPlayerUpdate - Universal - 03.10.2011

I dont understand what you meant by saying: "... will be called on next player update, but wouldnt ended on the last one ..." ?

PS. Gal geriau lietuviškai pasakyk.


Re: Question with OnPlayerUpdate - BuLLeT[LTU] - 03.10.2011

Quote:
Originally Posted by Universal
Посмотреть сообщение
I dont understand what you meant by saying: "... will be called on next player update, but wouldnt ended on the last one ..." ?

PS. Gal geriau lietuviљkai pasakyk.
Nu per pirma update bus issauktas OnPlayerChangeAmmo ir prasidejus kitam update jis wel bus issauktas. Tai ar gali but kad dar nebus pasibaiges OnPlayerChangeAmmo visas perskaitymas sename patikrinime (nes kadangi OnPlayerUpdate yra issaukiamas labai daznai)?


Re: Question with OnPlayerUpdate - Universal - 03.10.2011

Quote:
Originally Posted by BuLLeT[LTU]
Посмотреть сообщение
Nu per pirma update bus issauktas OnPlayerChangeAmmo ir prasidejus kitam update jis wel bus issauktas. Tai ar gali but kad dar nebus pasibaiges OnPlayerChangeAmmo visas perskaitymas sename patikrinime (nes kadangi OnPlayerUpdate yra issaukiamas labai daznai)?
Tada gali padaryti taip pries tos funkcijos issaukima:
pawn Код:
if(GetPVarInt(playerid, "function") != 1)
{
      // issauk ta funkcija
}
O pacioje funkcijoje gali:
pawn Код:
stock Funkcija(playerid)
{
         SetPVarInt(playerid, "function", 1);
         // ta visa funkcija

         // kai funkcija baigiasi:
         SetPVarInt(playerid, "function", 0);
}



Re: Question with OnPlayerUpdate - BuLLeT[LTU] - 03.10.2011

O tau nera buve kad skaitytu funkcijos koda ne is eiles? pvz yra 4 eilutes ir perskaito koda: 3 2 4 1 eilutemis o ne is eiles (del lag) ?


Re: Question with OnPlayerUpdate - Jafet_Macario - 03.10.2011

This is NOT Languages section.


Re: Question with OnPlayerUpdate - BuLLeT[LTU] - 03.10.2011

Quote:
Originally Posted by Jafet_Macario
Посмотреть сообщение
This is NOT Languages section.
Sorry.


Re: Question with OnPlayerUpdate - KoczkaHUN - 03.10.2011

PAWN scripts are single-threaded.
This means that when your callback is running, the server won't fire any other callbacks. When your callback is done, it does everything again (sync, for example).
This is why if you put a large code in OnPlayerUpdate, your server will lag.


Re: Question with OnPlayerUpdate - Universal - 04.10.2011

Quote:
Originally Posted by BuLLeT[LTU]
Посмотреть сообщение
O tau nera buve kad skaitytu funkcijos koda ne is eiles? pvz yra 4 eilutes ir perskaito koda: 3 2 4 1 eilutemis o ne is eiles (del lag) ?
No, functions are read from the first line to last. Otherwise, it would have no sense...