Advertisement
Samp-Pawn

OnPlayerPause

May 23rd, 2012
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. /*-
  2.  
  3. OnPlayerPause - Another release by Steve "$teVe" 2011,
  4. Please leave the credits.
  5.  
  6. I know, there are other releases, but when i look at them, I think they are to big.
  7. My version is very small.
  8.  
  9. Installation:
  10. Put "OnPlayerPause.inc" to your ServerDirectory/pawno/include folder.
  11. Open your GAMEMODE and include "OnPlayerPause" in it (#include <OnPlayerPause>).
  12. Add PAUSE_OnGameModeInit() to your OnGameModeInit() callback.
  13. Add PAUSE_OnPlayerConnect(playerid) to your PAUSE_OnPlayerConnect(playerid) callback.
  14. Add PAUSE_OnPlayerDisconnect(playerid, reason) to your PAUSE_OnPlayerDisconnect(playerid, reason) callback.
  15. Add PAUSE_OnPlayerUpdate(playerid) to your PAUSE_OnPlayerUpdate(playerid) callback.
  16.  
  17. -*/
  18.  
  19.  
  20. /*----------: Includes :----------*/
  21. #include <a_samp>
  22.  
  23. /*----------: Defines :----------*/
  24. #define MAX_AFK_TIME 20000
  25.  
  26. /*----------: Enums :----------*/
  27. enum e_STATE
  28. {
  29. e_STATE_UPDATING,
  30. e_STATE_NONE,
  31. e_STATE_CONNECTED
  32. };
  33.  
  34. /*----------: Veriables :----------*/
  35. new gLastUpdate[MAX_PLAYERS], e_STATE:gState[MAX_PLAYERS] = {e_STATE_NONE, ...};
  36.  
  37. /*----------: Forwards :-----------*/
  38. forward PAUSE_CheckPlayers();
  39. forward OnPlayerPause(playerid);
  40. forward PAUSE_OnGameModeInit();
  41. forward PAUSE_OnPlayerConnect(playerid);
  42. forward PAUSE_OnPlayerDisconnect(playerid, reason);
  43. forward PAUSE_OnPlayerUpdate(playerid);
  44.  
  45. /*-----: OnGameModeInit :-----*/
  46. public PAUSE_OnGameModeInit()
  47. {
  48. SetTimer("CheckPlayers", 1000, 1);
  49. return 1;
  50. }
  51.  
  52. /*-----: OnPlayerConnect :-----*/
  53. public PAUSE_OnPlayerConnect(playerid)
  54. {
  55. gState[playerid] = e_STATE_CONNECTED;
  56. return 1;
  57. }
  58.  
  59. /*-----: OnPlayerDisconnect :-----*/
  60. public PAUSE_OnPlayerDisconnect(playerid, reason)
  61. {
  62. gState[playerid] = e_STATE_NONE;
  63. return 1;
  64. }
  65.  
  66. /*-----: OnPlayerUpdate(playerid) :-----*/
  67. public PAUSE_OnPlayerUpdate(playerid)
  68. {
  69. gLastUpdate[playerid] = GetTickCount();
  70. gState[playerid] = e_STATE_UPDATING;
  71. return 1;
  72. }
  73.  
  74. /*-----: CheckPlayers() :-----*/
  75. public PAUSE_CheckPlayers()
  76. {
  77. for(new i; i < MAX_PLAYERS; ++i)
  78. {
  79. if((gState[i] == e_STATE_UPDATING) && (GetTickCount() - MAX_AFK_TIME >= gLastUpdate[i]))
  80. {
  81. CallLocalFunction("OnPlayerPause", "d", i);
  82. }
  83. }
  84. return 1;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement