Advertisement
Guest User

afkSystem.pwn -> by greentarch.

a guest
Feb 17th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.87 KB | None | 0 0
  1. /*
  2.     "afkSystem"
  3.         A simple AFK system
  4.        
  5.     Made by greentarch -> 2/10/2013
  6. */
  7.  
  8. #include    < a_samp >
  9. #include    < zcmd >
  10.  
  11. new
  12.     bool: gPlayerAFK[ MAX_PLAYERS char ],
  13.     afkReason[ MAX_PLAYERS ][ 128 ],
  14.     pVirtualWorld[ MAX_PLAYERS ]
  15. ;
  16.  
  17. public OnPlayerConnect( playerid )
  18.     return gPlayerAFK{ playerid } = false;
  19.    
  20. public OnPlayerText( playerid, text[ ] ) {
  21.     if ( gPlayerAFK{ playerid } ) {
  22.         SendClientMessage( playerid, -1, "You cannot chat if you are in AFK status." );
  23.         SendClientMessage( playerid, -1, "Use {00FFFF}/back {FFFFFF}if you are back from AFK." );
  24.         return 0;
  25.     }
  26.     return 1;
  27. }
  28.    
  29. CMD:afk( playerid, params[ ] ) {
  30.     if ( gPlayerAFK{ playerid } )
  31.         return SendClientMessage( playerid, -1, "You are already AFK. Use {00FFFF}/back {FFFFFF}instead." ), 1;
  32.        
  33.     if ( isnull( params ) )
  34.         return SendClientMessage( playerid, -1, "Valid syntax : {00FFFF}/afk < reason >" );
  35.  
  36.     gPlayerAFK{ playerid } = true;
  37.    
  38.     new
  39.         str[ 128 ],
  40.         pName[ MAX_PLAYER_NAME ]
  41.     ;
  42.    
  43.     format( afkReason[ playerid ], 128, "%s", params );
  44.    
  45.     GetPlayerName( playerid, pName, sizeof pName );
  46.  
  47.     format( str, sizeof str, "AFK >> {00FFFF}%s ( %d ) {FFFFFF}is now AFK. Reason : {00FFFF}%s",
  48.     pName, playerid, params );
  49.    
  50.     SendClientMessageToAll( -1, str );
  51.     SendClientMessage( playerid, -1, "You are now AFK. Use {00FFFF}/back {FFFFFF}if you have returned." );
  52.    
  53.     TogglePlayerControllable( playerid, 0 );
  54.    
  55.     pVirtualWorld[ playerid ] = GetPlayerVirtualWorld( playerid );
  56.    
  57.     SetPlayerVirtualWorld( playerid, playerid );
  58.    
  59.     return 1;
  60. }
  61.  
  62. CMD:back( playerid, params[ ] ) {
  63.     if ( !gPlayerAFK{ playerid } )
  64.         return SendClientMessage( playerid, -1, "You are not in AFK status." );
  65.  
  66.     gPlayerAFK{ playerid } = false;
  67.    
  68.     new
  69.         str[ 128 ],
  70.         pName[ MAX_PLAYER_NAME ]
  71.     ;
  72.  
  73.     GetPlayerName( playerid, pName, sizeof pName );
  74.    
  75.     format( str, sizeof str, "AFK >> {00FFFF}%s ( %d ) {FFFFFF}is now back. Reason : {00FFFF}%s",
  76.     pName, playerid, afkReason[ playerid ] );
  77.    
  78.     SendClientMessageToAll( -1, str );
  79.    
  80.     TogglePlayerControllable( playerid, 1 );
  81.    
  82.     SetPlayerVirtualWorld( playerid, pVirtualWorld[ playerid ] );
  83.    
  84.     return 1;
  85. }
  86.  
  87. CMD:afklist( playerid, params[ ] ) {
  88.     new
  89.         count,
  90.         pName[ MAX_PLAYER_NAME ],
  91.         str[ 128 ]
  92.     ;
  93.    
  94.     SendClientMessage( playerid, -1, "-------------------------------------" );
  95.     for ( new i, j = GetMaxPlayers( ); i < j; ++ i ) {
  96.         if ( i == INVALID_PLAYER_ID )
  97.             continue;
  98.            
  99.         if ( !gPlayerAFK{ i } )
  100.             continue;
  101.  
  102.         ++ count;
  103.        
  104.         GetPlayerName( i, pName, sizeof pName );
  105.        
  106.         format( str, 128, "%d) %s ( %d ) - {00FFFF}Reason : %s",
  107.         count, pName[ i ], i, afkReason[ i ] );
  108.        
  109.         SendClientMessage( playerid, -1, str );
  110.     }
  111.  
  112.     if ( !count )
  113.         SendClientMessage( playerid, -1, "No players AFK." );
  114.        
  115.     SendClientMessage( playerid, -1, "-------------------------------------" );
  116.        
  117.     return 1;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement