Advertisement
Guest User

AFK Script

a guest
Dec 26th, 2011
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define AFKTime 60 //How many seconds it takes to go AFK
  4. #define AFKWorld 1 //if you don't understand virtual worlds, don't touch this
  5. #define AFKColor 0x000000FF
  6. new AFK[MAX_PLAYERS];
  7. new Float:AFKPos[MAX_PLAYERS][3];
  8. new Esc[MAX_PLAYERS];
  9.  
  10. public OnFilterScriptInit()
  11. {
  12. SetTimer("AFKCheck",1000,true);
  13. return 1;
  14. }
  15.  
  16. public OnFilterScriptExit()
  17. {
  18. return 1;
  19. }
  20.  
  21. public OnPlayerConnect(playerid)
  22. {
  23. AFK[playerid] = 0;
  24. Esc[playerid] = 0;
  25. return 1;
  26. }
  27.  
  28. public OnPlayerDisconnect(playerid, reason)
  29. {
  30. BackFromAFK(playerid);
  31. Esc[playerid] = 0;
  32. return 1;
  33. }
  34.  
  35. public OnPlayerText(playerid, text[])
  36. {
  37. BackFromAFK(playerid);
  38. return 1;
  39. }
  40.  
  41. public OnPlayerCommandText(playerid, cmdtext[])
  42. {
  43. BackFromAFK(playerid);
  44. return 0;
  45. }
  46. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  47. {
  48. Esc[playerid] = 0;
  49. return 1;
  50. }
  51. public OnPlayerUpdate(playerid)
  52. {
  53. Esc[playerid] = 0;
  54. return 1;
  55. }
  56. forward AFKCheck();
  57. public AFKCheck()
  58. {
  59. new Float:Pos[3];
  60. for(new i = 0; i < MAX_PLAYERS; i++)
  61. {
  62. Esc[i] += 1;
  63. GetPlayerPos(i,Pos[0],Pos[1],Pos[2]);
  64. if(Esc[i] >= 30)
  65. {
  66. AFK[i] += 120;
  67. AFKMode(i);
  68. }
  69. if(Pos[0] != AFKPos[i][0] || Pos[1] != AFKPos[i][1] || Pos[2] != AFKPos[i][2])
  70. {
  71. BackFromAFK(i);
  72.  
  73. }
  74. else
  75. {
  76. AFK[i] += 1;
  77. AFKMode(i);
  78. }
  79. GetPlayerPos(i,AFKPos[i][0],AFKPos[i][1],AFKPos[i][2]);
  80. }
  81. return 1;
  82. }
  83. stock BackFromAFK(playerid)
  84. {
  85. if(AFK[playerid] >= AFKTime)
  86. {
  87. SetPlayerColor(playerid,GetPVarInt(playerid,"OldCol"));
  88. SetPlayerVirtualWorld(playerid,GetPVarInt(playerid,"OldVW"));
  89. }
  90. AFK[playerid] = 0;
  91. return 1;
  92. }
  93. stock AFKMode(playerid)
  94. {
  95. if(AFK[playerid] >= AFKTime)
  96. {
  97. SetPVarInt(playerid,"OldCol",GetPlayerColor(playerid));
  98. SetPVarInt(playerid,"OldVW",GetPlayerVirtualWorld(playerid));
  99. SetPlayerColor(playerid,AFKColor);
  100. SetPlayerVirtualWorld(playerid,AFKWorld);
  101. }
  102. return 1;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement