SA-MP Forums Archive
What is prefered ? Timer or 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: What is prefered ? Timer or OnPlayerUpdate. (/showthread.php?tid=456740)



What is prefered ? Timer or OnPlayerUpdate. - sKgaL - 07.08.2013

Hello,
I want to know what is prefered.

Lets take a example,
I want to update player's score by player's money.
So here is the code -

Код:
new pMoney = GetPlayerMoney(playerid);
new pScore = GetPlayerScore(playerid);
if(pMoney != pScore)SetPlayerScore(playerid,pMoney);
now here is the quastion ,
what's preferd - doing this check on Timer that will run for 1 second all the time,
Or just put that code inside OnPlayerUpdate public ?


Thanks.


Re: What is prefered ? Timer or OnPlayerUpdate. - Misiur - 07.08.2013

I'd say timer every ~10 seconds - "(OnPlayerUpdate) is called very frequently per second per player" - way too much, and 1 second is still too much


Re: What is prefered ? Timer or OnPlayerUpdate. - doreto - 07.08.2013

OnPlayerUpdate is called 8-10 times in second and you don't need that many times to save those scores and money , timer will be called every 1 second and it's great for saving stuff (showing from your code above)


Re: What is prefered ? Timer or OnPlayerUpdate. - Nirzor - 07.08.2013

Every 1 second is perfect but OnPlayerUpdate is really good.


Re: What is prefered ? Timer or OnPlayerUpdate. - Konstantinos - 07.08.2013

Quote:
Originally Posted by Nirzor
Посмотреть сообщение
Every 1 second is perfect but OnPlayerUpdate is really good.
Why is it good to check for the score and money 30 times per second? It's not good at 1 second timer either, 2 or 3 is fine.


Re: What is prefered ? Timer or OnPlayerUpdate. - sKgaL - 07.08.2013

Ok so for that example Timer is preferd,
but if I check for money cheat ?

like -
Код:
if(GetPlayerMoney(playerid)>GetPVarInt(playerid, "Money"))return ..... // Money hack
For that exmple ,
Timer for every second or OnPlayerUpdate , what is preferd ?


Re: What is prefered ? Timer or OnPlayerUpdate. - Konstantinos - 07.08.2013

I've a better way! Use server-side money, they cannot use their fake money as long as your variables stores their real money. ****** it, you'll find many results and it's really useful.


Re: What is prefered ? Timer or OnPlayerUpdate. - cessil - 07.08.2013

Quote:
Originally Posted by sKgaL
Посмотреть сообщение
Код:
new pMoney = GetPlayerMoney(playerid);
new pScore = GetPlayerScore(playerid);
if(pMoney != pScore)SetPlayerScore(playerid,pMoney);
now here is the quastion ,
what's preferd - doing this check on Timer that will run for 1 second all the time,
Or just put that code inside OnPlayerUpdate public ?

Thanks.
for this example, neither, you should do it when it changes, so I'd create a stock, function or hook for changing the players money

Quote:
Originally Posted by sKgaL
Посмотреть сообщение
Ok so for that example Timer is preferd,
but if I check for money cheat ?

like -
Код:
if(GetPlayerMoney(playerid)>GetPVarInt(playerid, "Money"))return ..... // Money hack
For that exmple ,
Timer for every second or OnPlayerUpdate , what is preferd ?
I'd recommend reading this before you ban innocent players
https://sampforum.blast.hk/showthread.php?tid=220089
the thread also covers using OPU for money checks


Re: What is prefered ? Timer or OnPlayerUpdate. - Edix - 07.08.2013

I think you should mostly use a timer or even create a timer that goes every 100 miliseconds which will loop through all players as OnPlayerUpdate gets called about 30 times a second which makes OnPLayerUpdate get called 33 times in 1 second.