SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/07/2020, 11:29 PM   #1
LetsDoItPerfect
Little Clucker
 
Join Date: Mar 2020
Posts: 27
Reputation: 0
Default OnPlayerStateChange SPAM

Hello,
While making AFK check system, adding some debug messages, I see that OnPlayerUpdate is called so much times in 1 second even if player isn't touching keyboard. How is that?

PHP Code:
hook OnPlayerUpdate(playerid)
{
    
AFK[playerid] = 0;
    new 
string[128];
    
format(stringsizeof(string), "DEBUG: Player %s(%i) state changed and is no longer AFK"PlayerName(playerid), playerid);
    
SendClientMessageToAll(COLOR_WHITEstring);

LetsDoItPerfect is offline   Reply With Quote
Old 14/07/2020, 12:55 AM   #2
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,151
Reputation: 215
Default Re: OnPlayerStateChange SPAM

Thats what it does...about 10 times a second (depending on many things starting with ping).
DRIFT_HUNTER is offline   Reply With Quote
Old 14/07/2020, 02:07 AM   #3
Lexless
Little Clucker
 
Join Date: May 2020
Posts: 38
Reputation: 14
Default Re: OnPlayerStateChange SPAM

Why don't use a timer?
Lexless is offline   Reply With Quote
Old 14/07/2020, 03:58 AM   #4
GameOvr
Huge Clucker
 
GameOvr's Avatar
 
Join Date: Jun 2018
Posts: 296
Reputation: 9
Default Re: OnPlayerStateChange SPAM

OnPlayerUpdate is like a premade iterative timer. If you wanna really do this, detect player velocity.. if its not equal to 0 in one ofl the 3 axes. That means player is moving.

Code:
hook OnPlayerUpdate(playerid)
{
    if(AFK[playerid])
    {
          new Float:v1, Float:v2, Float:v3;
          GetPlayerVelocity(playerid, v1, v2, v3);
          if(v1 != 0 || v2 != 0 || v3 != 0)
          {
                 AFK[playerid] = 0; 
                 new string[128]; 
                 format(string, sizeof(string), "DEBUG: Player %s(%i) state changed and is no longer AFK", PlayerName(playerid),   playerid);
                 SendClientMessageToAll(COLOR_WHITE, string); 
          }
    }
    return 1;
}
__________________
GameOvr is offline   Reply With Quote
Old 14/07/2020, 03:07 PM   #5
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,151
Reputation: 215
Default Re: OnPlayerStateChange SPAM

Quote:
Originally Posted by GameOvr View Post
OnPlayerUpdate is like a premade iterative timer. If you wanna really do this, detect player velocity.. if its not equal to 0 in one ofl the 3 axes. That means player is moving.

Code:
hook OnPlayerUpdate(playerid)
{
    if(AFK[playerid])
    {
          new Float:v1, Float:v2, Float:v3;
          GetPlayerVelocity(playerid, v1, v2, v3);
          if(v1 != 0 || v2 != 0 || v3 != 0)
          {
                 AFK[playerid] = 0; 
                 new string[128]; 
                 format(string, sizeof(string), "DEBUG: Player %s(%i) state changed and is no longer AFK", PlayerName(playerid),   playerid);
                 SendClientMessageToAll(COLOR_WHITE, string); 
          }
    }
    return 1;
}
No need, just save time when OnPlayerUpdate was called. If player is AFK, OnPlayerUpdate is not called (he does not send any packets)
DRIFT_HUNTER is offline   Reply With Quote
Old 14/07/2020, 07:32 PM   #6
LetsDoItPerfect
Little Clucker
 
Join Date: Mar 2020
Posts: 27
Reputation: 0
Default Re: OnPlayerStateChange SPAM

Thanks, I will do that. +rep
LetsDoItPerfect is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OnPlayerStateChange playstores Scripting Help 2 17/08/2018 10:00 AM
OnPlayerStateChange help.. Pettersen Scripting Help 2 18/05/2013 11:22 AM
OnPlayerStateChange stormchaser206 Scripting Help 3 13/07/2012 06:07 PM
[FilterScript] Spam Prevention System (Anti Spam) Luka P. Filterscripts 9 14/09/2011 12:56 PM
OnPlayerStateChange Jakku Help Archive 2 08/01/2010 01:09 PM


All times are GMT. The time now is 03:40 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.