Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * AFK system
- * Written by Ellis
- */
- // Including a_samp
- #include <a_samp>
- // Filterscript settings
- #define AFK_TIME 5 // minutes
- // Defining global variables
- new
- AFKCheck[ MAX_PLAYERS ],
- AFKTimer;
- forward CheckIfAFKing( );
- /*******************************************************************************
- *** SA:MP callbacks *****
- ******************************************************************************/
- public OnFilterScriptInit( )
- {
- // Callback: OnFilterScriptInit( )
- for ( new playerid = 0; playerid < MAX_PLAYERS; playerid++ )
- AFKCheck[ playerid ] = 0;
- AFKTimer = SetTimer( "CheckIfAFKing", 60000, true );
- return true;
- }
- public OnFilterScriptExit( )
- {
- // Callback: OnFilterScriptExit( )
- KillTimer( AFKTimer );
- return true;
- }
- public OnPlayerConnect( playerid )
- {
- // Callback: OnPlayerConnect( playerid )
- // Clearing player variable
- AFKCheck[ playerid ] = 0;
- return true;
- }
- public OnPlayerText( playerid, text[ ] )
- {
- // Callback: OnPlayerText( playerid, text[ ] )
- // Clearing player variable
- if ( AFKCheck[ playerid ] >= AFK_TIME )
- OnPlayerBackOfAFK( playerid );
- AFKCheck[ playerid ] = 0;
- return true;
- }
- public OnPlayerPrivmsg( playerid, recieverid, text[ ] )
- {
- // Callback: OnPlayerPrivmsg( playerid, recieverid, text[ ] )
- // Clearing player variable
- if ( AFKCheck[ playerid ] >= AFK_TIME )
- OnPlayerBackOfAFK( playerid );
- AFKCheck[ playerid ] = 0;
- return true;
- }
- public OnPlayerCommandText( playerid, cmdtext[ ] )
- {
- // Callback: OnPlayerCommandText( playerid, cmdtext[ ] )
- // Clearing player variable
- if ( AFKCheck[ playerid ] >= AFK_TIME )
- OnPlayerBackOfAFK( playerid );
- AFKCheck[ playerid ] = 0;
- return false;
- }
- /*******************************************************************************
- *** Custom functions and callbacks *****
- ******************************************************************************/
- public CheckIfAFKing( )
- {
- // Function: CheckIfAFKing( )
- // Checks if player is AFK. It's called every minute
- static
- Float:OldPosX[ MAX_PLAYERS ],
- Float:OldPosY[ MAX_PLAYERS ],
- Float:OldPosZ[ MAX_PLAYERS ];
- for ( new playerid = 0; playerid < MAX_PLAYERS; playerid++ )
- {
- if ( !IsPlayerConnected( playerid ) ) continue;
- new
- Float:NewPosX,
- Float:NewPosY,
- Float:NewPosZ;
- GetPlayerPos( playerid, NewPosX, NewPosY, NewPosZ );
- if ( NewPosX == OldPosX[ playerid ] && NewPosY == OldPosY[ playerid ] &&
- NewPosZ == OldPosZ[ playerid ] )
- {
- if ( AFKCheck[ playerid ] < AFK_TIME )
- {
- AFKCheck[ playerid ]++;
- if ( AFKCheck[ playerid ] == AFK_TIME )
- OnPlayerCaughtAFK( playerid );
- }
- }
- else
- {
- AFKCheck[ playerid ] = 0;
- OnPlayerBackOfAFK( playerid );
- }
- OldPosX[ playerid ] = NewPosX;
- OldPosY[ playerid ] = NewPosY;
- OldPosZ[ playerid ] = NewPosZ;
- }
- }
- stock OnPlayerCaughtAFK( playerid )
- {
- // Callback: OnPlayerCaughtAFK( playerid )
- // Adding [AFK] tag to player name
- new
- name[ MAX_PLAYER_NAME ];
- GetPlayerName( playerid, name, MAX_PLAYER_NAME );
- strins ( name, "[AFK]", 0, MAX_PLAYER_NAME );
- SetPlayerName( playerid, name );
- }
- stock OnPlayerBackOfAFK( playerid )
- {
- // Callback: OnPlayerBackOfAFK( playerid )
- // Removing [AFK] tag from player name
- new
- name[ MAX_PLAYER_NAME ];
- GetPlayerName( playerid, name, MAX_PLAYER_NAME );
- if ( !strcmp( name, "[AFK]", true, 5 ) )
- {
- strdel ( name, 0, 5 );
- SetPlayerName( playerid, name );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement