SA-MP Forums Archive
Can the milliseconds difference between timers affect something? - 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: Can the milliseconds difference between timers affect something? (/showthread.php?tid=313751)



Can the milliseconds difference between timers affect something? - milanosie - 27.01.2012

So, My question is:

I have this anti cheat for moneyhack, jetpack, etc..
It checks every 30 seconds,

It works like this:

/giveplayermoney is now in a public called giveplayercash

public giveplayercash looks like this:

pawn Код:
forward GivePlayerCash(playerid, Amoney);
public GivePlayerCash(playerid, Amoney)
{
    realmoney[playerid] = realmoney[playerid] + Amoney;
    GivePlayerMoney(playerid, Amoney);
    return 1;
}
The public CheckMoney checks if realmoney[playerid] is equel to GetPlayerMoney

If it is, there is no problem.. but.
WHAT if it checks in the middle of the give player money?

so like this:

pawn Код:
forward GivePlayerCash(playerid, Amoney);
public GivePlayerCash(playerid, Amoney)
{
    money[playerid] = money[playerid] + Amoney;
       //PUBLIC CHECKMONEY STARTS CHECKING HERE BY BAD LUCK?
    GivePlayerMoney(playerid, Amoney);
    return 1;
}
Will that give false warnings/bans?
or is the time between
pawn Код:
money[playerid] = balbalba
and
pawn Код:
GivePlayerMoney
too small for this?
just curious


Re: Can the milliseconds difference between timers affect something? - Vince - 27.01.2012

God, all those things you're worrying about for nothing. It takes less than a nanosecond to execute a statement.


Re: Can the milliseconds difference between timers affect something? - MP2 - 27.01.2012

PAWN is single threaded, but I'm not sure if that affects whole callbacks. If someone could clarify for me that'd be appreciated.

Also, use

money[playerid] += Amoney;

And convert the public to a stock function or macro.


Re: Can the milliseconds difference between timers affect something? - milanosie - 27.01.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
God, all those things you're worrying about for nothing. It takes less than a nanosecond to execute a statement.
well not for nothing, I did not know how long it took and I don't want false bans etc.

anyway thanks...

about this:

[pawn]
realmoney[playerid] += Amoney;

And convert the public to a stock function or macro.


1. why += and not ==


2. Why convert it to a stock?


Re: Can the milliseconds difference between timers affect something? - MP2 - 27.01.2012

+= means 'add x to the variable'. It just looks better than "var = var + 1". I'm not sure if there's any performance difference.

Because 'public' is generally used for callbacks, not functions. Unless you want to call it from filterscripts.


Re: Can the milliseconds difference between timers affect something? - FUNExtreme - 27.01.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
PAWN is single threaded, but I'm not sure if that affects whole callbacks. If someone could clarify for me that'd be appreciated.
PAWN is single threaded, this means that only one thing is executed at each given time.
If your money check timer runs out while something else is executing it is delayed until the previous action is completed.

In short (answer to your question): "No"


Re: Can the milliseconds difference between timers affect something? - MP2 - 27.01.2012

So, there's absolutley no chance of it? Are you sure the threading isn't just per-function?


Re: Can the milliseconds difference between timers affect something? - FUNExtreme - 27.01.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
So, there's absolutley no chance of it? Are you sure the threading isn't just per-function?
I am 100% sure.


Re: Can the milliseconds difference between timers affect something? - Mauzen - 27.01.2012

Yep, script is executed line by line, a timer is only executed after the currently running function is finished. No chance that a function is suspended for a timer.


Re: Can the milliseconds difference between timers affect something? - MP2 - 27.01.2012

Okay. It's just that I used to have a problem with my AC, with it wrongfully banning players, guess it was another problem though.