Advertisement
Guest User

AutoAFK by Manyula

a guest
Jul 10th, 2014
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.34 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define AUTO_AFK_CHECK_INTERVAL 5 //in minutes
  4. #define AUTO_AFK_TOLERANCE 5 //in minutes
  5.  
  6. #define C_LIGHT_BLUE 0x00FFFFFF
  7. #define C_LIGHT_BLUE_E   "{00FFFF}"
  8.  
  9. enum
  10. {
  11.     DIALOG_AFK
  12. }
  13.  
  14. enum HPandAP
  15. {
  16.     Float:health,
  17.     Float:armour
  18. }
  19.  
  20. new bool:AutoAFK_Detected[MAX_PLAYERS],
  21.     Float:Position[MAX_PLAYERS][3],
  22.     AutoAFK_Timer[MAX_PLAYERS],
  23.     StartGodModeTimer[MAX_PLAYERS],
  24.     bool:IsPlayerAFK[MAX_PLAYERS] = false,
  25.     Float:PlayerHPandAP[MAX_PLAYERS][HPandAP];
  26.  
  27. #define FILTERSCRIPT
  28. #if defined FILTERSCRIPT
  29.  
  30. public OnFilterScriptInit()
  31. {
  32.     print("+--------------------+");
  33.     print("| AutoAFK by Manyula |");
  34.     print("+--------------------+");
  35.    
  36.     SetTimer("AutoAFK_Check", AUTO_AFK_CHECK_INTERVAL*1000, true);
  37.     return 1;
  38. }
  39.  
  40. public OnFilterScriptExit()
  41. {
  42.     print("AutoAFK has been unloaded.");
  43.     return 1;
  44. }
  45.  
  46. public OnPlayerSpawn(playerid)
  47. {
  48.     GetPlayerPos(playerid, Position[playerid][0], Position[playerid][1], Position[playerid][2]);
  49.     return 1;
  50. }
  51.  
  52. public OnPlayerText(playerid, text[])
  53. {
  54.     if(AutoAFK_Detected[playerid])
  55.     {
  56.         AutoAFK_Detected[playerid] = false;
  57.     }
  58.     return 1;
  59. }
  60.  
  61. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  62. {
  63.     if(dialogid == DIALOG_AFK)
  64.     {
  65.         if(response)
  66.         {
  67.             new PlayerWhoGoesBack[MAX_PLAYER_NAME],
  68.                 string[64];
  69.             KillTimer(StartGodModeTimer[playerid]);
  70.             ReturnPlayerHPandAP(playerid);
  71.             GetPlayerName(playerid, PlayerWhoGoesBack, sizeof(PlayerWhoGoesBack));
  72.             format(string, sizeof(string), "»PLAYERINFO« {%06x}%s "#C_LIGHT_BLUE_E"is playing again.", GetPlayerColor(playerid) >>> 8, PlayerWhoGoesBack);
  73.             SendClientMessageToAll(C_LIGHT_BLUE, string);
  74.             ClearAnimations(playerid);
  75.             IsPlayerAFK[playerid] = false;
  76.             return 1;
  77.         }
  78.         else ShowPlayerDialog(playerid, DIALOG_AFK, DIALOG_STYLE_MSGBOX, "Away From Keyboard", "You are now in the "#C_LIGHT_BLUE_E"AFK mode"#C_DIALOG_E".\nPress "#C_LIGHT_BLUE_E"Back"#C_DIALOG_E" to play again.", "Back", "");
  79.     }
  80.     return 1;
  81. }
  82.  
  83. forward AutoAFK_Processed(playerid);
  84. public AutoAFK_Processed(playerid)
  85. {
  86.     new PlayerWhoGoesAFK[MAX_PLAYER_NAME],
  87.         string[64+32];
  88.     ShowPlayerDialog(playerid, DIALOG_AFK, DIALOG_STYLE_MSGBOX, "Away From Keyboard", "You are now in the "#C_LIGHT_BLUE_E"AFK mode"#C_DIALOG_E".\nPress "#C_LIGHT_BLUE_E"Back"#C_DIALOG_E" to play again.", "Back", "");
  89.     SavePlayerHPandAP(playerid);
  90.     StartGodModeTimer[playerid] = SetTimerEx("StartGodMode", 250, true, "i", playerid);
  91.     GetPlayerName(playerid, PlayerWhoGoesAFK, sizeof(PlayerWhoGoesAFK));
  92.     format(string, sizeof(string), "»PLAYERINFO« {%06x}%s "#C_LIGHT_BLUE_E"is now AFK.", GetPlayerColor(playerid) >>> 8, PlayerWhoGoesAFK);
  93.     SendClientMessageToAll(C_LIGHT_BLUE, string);
  94.     ApplyAnimation(playerid, "SUNBATHE", "ParkSit_M_in", 4.1, 0, 1, 1, 1, 1);
  95.     IsPlayerAFK[playerid] = true;
  96.     return 1;
  97. }
  98.  
  99. forward AutoAFK_Check();
  100. public AutoAFK_Check()
  101. {
  102.     for(new i; i < MAX_PLAYERS; i++)
  103.     {
  104.         if(IsPlayerConnected(i))
  105.         {
  106.             if(!IsPlayerAFK[i])
  107.             {
  108.                 if(IsPlayerInRangeOfPoint(i, 0, Position[i][0], Position[i][1], Position[i][2]))
  109.                 {
  110.                     if(AutoAFK_Detected[i])
  111.                     {
  112.                         return 1;
  113.                     }
  114.                     else if(!AutoAFK_Detected[i])
  115.                     {
  116.                         AutoAFK_Detected[i] = true;
  117.                         AutoAFK_Timer[i] = SetTimerEx("AutoAFK_Processed", AUTO_AFK_TOLERANCE*60000, false, "i", i);
  118.                         return 1;
  119.                     }
  120.                 }
  121.                 else if(!IsPlayerInRangeOfPoint(i, 0, Position[i][0], Position[i][1], Position[i][2]))
  122.                 {
  123.                     if(AutoAFK_Detected[i])
  124.                     {
  125.                         KillTimer(AutoAFK_Timer[i]);
  126.                         AutoAFK_Detected[i] = false;
  127.                         GetPlayerPos(i, Position[i][0], Position[i][1], Position[i][2]);
  128.                         return 1;
  129.                     }
  130.                     else if(!AutoAFK_Detected[i])
  131.                     {
  132.                         AutoAFK_Detected[i] = false;
  133.                         GetPlayerPos(i, Position[i][0], Position[i][1], Position[i][2]);
  134.                         return 1;
  135.                     }
  136.                 }
  137.             }
  138.             else if(IsPlayerAFK[i])
  139.             {
  140.                 return 1;
  141.             }
  142.         }
  143.     }
  144.     return 1;
  145. }
  146.  
  147. forward StartGodMode(playerid);
  148. public StartGodMode(playerid) return SetPlayerHealth(playerid, 99999);
  149.  
  150. stock SavePlayerHPandAP(playerid)
  151. {
  152.     GetPlayerHealth(playerid, PlayerHPandAP[playerid][health]);
  153.     GetPlayerArmour(playerid, PlayerHPandAP[playerid][armour]);
  154.     return 1;
  155. }
  156.  
  157. stock ReturnPlayerHPandAP(playerid)
  158. {
  159.     SetPlayerHealth(playerid, PlayerHPandAP[playerid][health]);
  160.     SetPlayerArmour(playerid, PlayerHPandAP[playerid][armour]);
  161.     return 1;
  162. }
  163.  
  164. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement