Guest User

Untitled

a guest
Mar 29th, 2011
1,275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Lach's Multi AFK System v1.0 //
  4. // by Antonio [G-RP] //
  5. //
  6. ////////////////////////////////////////////////////////////////////////////////
  7. //
  8. // FEEL FREE TO EDIT THIS FILTERSCRIPT - BUT LEAVE THE CREDITS IN IT!
  9. //
  10.  
  11. #include <a_samp>
  12. #define MAX_AFKTIME 6 // In Minutes
  13.  
  14. forward StartAFK(playerid);
  15. forward StopAFK(playerid);
  16. forward Check();
  17.  
  18. new Float:Pos[MAX_PLAYERS][3];
  19.  
  20. public OnFilterScriptInit()
  21. {
  22. print("\n--------------------------------------");
  23. print(" Multi AFK System v1.0 by Antonio[G-RP]");
  24. print("--------------------------------------\n");
  25.  
  26. SetTimer("Check", 1000, 1);
  27. return 1;
  28. }
  29.  
  30. public OnFilterScriptExit()
  31. {
  32. for(new i=0; i<MAX_PLAYERS; i++) {
  33. StopAFK(i);
  34. }
  35. return 1;
  36. }
  37.  
  38. public Check()
  39. {
  40. for(new i=0; i<MAX_PLAYERS; i++) {
  41. if(!IsPlayerConnected(i)) continue;
  42. new Float:x, Float:y, Float:z;
  43. GetPlayerPos(i, x, y, z);
  44.  
  45. if(!GetPVarInt(i,"TabbedOut"))
  46. {
  47. if((GetTickCount() - GetPVarInt(i, "LastUpdate")) >= 1000) {
  48. SetPVarInt(i, "TabbedOut", 1);
  49. CallLocalFunction("StartAFK", "i", i);
  50. }
  51. if(x != 0) {
  52. if(Pos[i][0] == x && Pos[i][1] == y && Pos[i][2] == z) {
  53. SetPVarInt(i, "AFKTime", GetPVarInt(i, "AFKTime") + 1);
  54. }
  55. }
  56.  
  57. if(!(Pos[i][0] == x && Pos[i][1] == y && Pos[i][2] == z)) {
  58. CallLocalFunction("StopAFK", "i", i);
  59. }
  60. }
  61. if(GetPVarInt(i, "TabbedOut"))
  62. {
  63. SetPVarInt(i, "AFKTime", GetPVarInt(i, "AFKTime") + 1);
  64. }
  65.  
  66. if(GetPVarInt(i, "AFKTime") == 300) {
  67. CallLocalFunction("StartAFK", "i", i);
  68. }
  69.  
  70. if(GetPVarInt(i, "AFKTime") >= MAX_AFKTIME*60) {
  71. printf("Player AFK time %d", GetPVarInt(i, "AFKTime"));
  72. new string[70], name[24];
  73. GetPlayerName(i, name, 24);
  74. format(string, sizeof(string), "%s was kicked by system for being AFK for %d minute(s).", name, MAX_AFKTIME);
  75. SendClientMessageToAll(0xFFFFFFFF, string);
  76. Kick(i);
  77. }
  78. GetPlayerPos(i, Pos[i][0], Pos[i][1], Pos[i][2]);
  79. }
  80. return 1;
  81. }
  82.  
  83. public OnPlayerConnect(playerid)
  84. {
  85. for(new i=0; i<3; i++) {
  86. Pos[playerid][i] = 0;
  87. }
  88. return 1;
  89. }
  90.  
  91. public OnPlayerDisconnect(playerid, reason)
  92. {
  93. DeletePVar(playerid, "TabbedOut");
  94. DeletePVar(playerid, "LastUpdate");
  95. return 1;
  96. }
  97.  
  98. public OnPlayerUpdate(playerid)
  99. {
  100. SetPVarInt(playerid, "LastUpdate", GetTickCount());
  101. if(GetPVarInt(playerid, "TabbedOut")) {
  102. SetPVarInt(playerid, "TabbedOut", 0);
  103. CallLocalFunction("StopAFK", "i", playerid);
  104. }
  105. return 1;
  106. }
  107.  
  108. public StartAFK(playerid)
  109. {
  110. if(GetPVarInt(playerid, "AFKText")) Delete3DTextLabel(Text3D:GetPVarInt(playerid, "AFKText"));
  111. SetPVarInt(playerid, "AFKText", _:Create3DTextLabel("Player is AFK", 0xFF0000FF, 0.0, 0.0, 0.0, 25.0, GetPlayerVirtualWorld(playerid), 1));
  112. Attach3DTextLabelToPlayer(Text3D:GetPVarInt(playerid, "AFKText"), playerid, 0.0, 0.0, 0.3);
  113. SetPlayerColor(playerid, 0xFF0000FF);
  114. return 1;
  115. }
  116.  
  117. public StopAFK(playerid)
  118. {
  119. if(GetPVarInt(playerid, "AFKText")) Delete3DTextLabel(Text3D:GetPVarInt(playerid, "AFKText"));
  120. if(GetPVarInt(playerid, "AFKTime")) DeletePVar(playerid, "AFKTime");
  121. SetPlayerColor(playerid, 0xFFFFFFFF);
  122. return 1;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment