What is prefered ? Timer or OnPlayerUpdate.
#1

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

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

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

Every 1 second is perfect but OnPlayerUpdate is really good.
Reply
#5

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

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 ?
Reply
#7

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

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
Reply
#9

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


Forum Jump:


Users browsing this thread: 1 Guest(s)