there is any samp function to detect if player pic...
# support-forum
c
I have this anti jetpack hack system, that is working, but it interate all players to check if player cheat a jetpack there is any other better way to check it?
Copy code
c++
SetTimer("AntiJetpackHack", 32000, true);
Copy code
c++
forward AntiJetpackHack();
public AntiJetpackHack() {
    foreach(new i : Player) {
        if(paused[i] == false && Logged[i] > 0)
        {
            if(GetPlayerSpecialAction(i) == SPECIAL_ACTION_USEJETPACK && serverJetpack[i] == false)
            {
                StopAnim(i);
                ApplyAnimation(i,"ped","FALL_COLLAPSE",4.1,0,1,1,0,0,1);
                new danospeedhack = GetPlayerSpeedKM(i);
                danospeedhack -= 25;
                new dmgstring[20];
                format(dmgstring, sizeof(dmgstring), "~r~%i.0", danospeedhack );
                GameTextForPlayerEx(i, dmgstring, 1000, 3);
                SetPlayerHealthEx(i, -danospeedhack);
                MSG_AntiCheatAdmAviso(i, "JETPACK HACK");
            }
        }
    }
}
g
OnPlayerUpdate().
c
This callback is called, on average, 30 times per second, per player The frequency with which this callback is called for each player varies, depending on what the player is doing. Driving or shooting will trigger a lot more updates than idling. https://team.sa-mp.com/wiki/OnPlayerUpdate.html
are u sure? i my function interate in every player each 32 secs onplayerupdate looks atlest 960 times high then my function (30×32) i'm wrong?
g
Probably u need to put there, the function u made its every 32s, if he gets a jetpack and destroy it in that delay, how will u be able do detect it?
c
my whole question is about to get a way to uses less CPU
i just wanna know from someone with experience if there is a better way to do it instead of timers
onplayerupdate should make use 960x more CPU
g
I mean
g
Is it noticeably slow using OnPlayerUpdate?
g
your timer is ok, it wont get so much CPU, as its made every 32s and its not a extensive function, but can u answer my question?
c
what are u mean?
g
you'll need to check every player anyway so
it wont get THAT much cpu "960x"
do a test and see in the html profile include.
c
i could check 1 time per second instead of 30 times per second with
i just asking for a native way to do it on samp
put functions like that on OnPlayerupdate, get more then 400 players online and you will see what profile gives you
g
you'll need to check the players dude
. if someone gets the jetpack in the delay time u wouldnt be able to detect it xd
c
so check it 50 times per second
put this kinda of script on onplayerupdate with 430 players online and check your profile html files like u suggest me
g
That's how I check for jetpack cheats, and weapons. A timer may not be accurate enough
c
you check it on onplayerupdate?
g
yeah
s
I use an update counter in OnPlayerUpdate. Then use modulo (or reset the counter after X) to check for certain things every X updates. That way it doesn't do unncessary things too often and the "load" is spread out to multiple calls per player
c
i did think that onplayerupdate was heavy and i should avoid it
i'm wrong?
i just trying to understand why with 50 players i'm using 70% of my CPU
when i run the profile u suggest me
the higher self time -> % was OnPlayerUpdate with 15.13%
what are u mean? doing your way in onplayerupdate is better to creating loop like in did on AntiJetpackHack function?
could u show me more about that?
s
That is generally true for resource intensive stuff, like file operations, long string formatting, extensive loops etc. In this specific case I wouldn't worry about it unless you already have a lot of stuff in there. Especially because your Jetpack detection only calls GetPlayerSpecialAction 99.9% of the time. It only executes the rest if the player actually has a jetpack so it's not going to make a difference
g
You're wrong if your "OnPlayerUpdate" is extensive like Naseband said. But as you're just searching for jetpack, the problem isnt your code, instead should be other thing thats lagging the public.
c
https://discord.com/channels/231799104731217931/1089736888056815647/1089736888056815647 but guys, look this topic, its only a set value with gettime, and profile is showing that its eating my CPU up, what would u do to make it ligther?
g
do without it and see in the profiler
it can be a include thats doing it, like nex-ac
c
i'm not using any lib look the first and the second lines that uses more CPU first is onplayerupdate second is gettime
g
But you already tested with the profiler how much it'd be the CPU usage doing the jetpack thing?