Advertisement
HR_Shaft

Dynamic AFK Kick Times v1.1 for SAPP

Feb 14th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.63 KB | None | 0 0
  1. -- Dynamic AFK Kick Times v1.1
  2. -- by H® Shaft
  3. -- Requested by jakallan3
  4.  
  5. -- 2/14/2016 - corrected typo error, and added OnNewGame and OnGameEnd
  6.  
  7. -- Script allows server admins to dynamically change AFK Kick times based on the number of players
  8. -- Editable AFK Time and # of Players
  9.  
  10. -- Full Number: if 12 slot server, set to 10, if 16 slots, set to 14 - should not be set equal to the maximum amount of players
  11. -- how many players constitutes FULL number of players or almost full?
  12. Full_Players = 10
  13.  
  14. -- how many players constitutes medium number of players?  
  15. Medium_Players = 8
  16.  
  17. -- how many players constitutes low number of players?
  18. Low_Players = 6
  19.  
  20. -- how many players constitutes few number of players?
  21. Few_Players = 4
  22.  
  23. ------------
  24. -- Kick Times Strategy: to Keep the server active and have less afk players, the MORE players there are, the LOWER the AFK time:
  25. -- how quickly in seconds to kick AFKs during a FULL player server?
  26. Full_Players_AFK_Time = 90
  27.  
  28. -- how quickly in seconds to kick AFKs during a MEDIUM player server?
  29. Medium_Players_AFK_Time = 180
  30.  
  31. -- how quickly in seconds to kick AFKs during a LOW player server?
  32. Low_Players_AFK_Time = 360
  33.  
  34. -- how quickly in seconds to kick AFKs during a FEW player server?
  35. Few_Players_AFK_Time = 0
  36.  
  37. -- if the script is UNLOADED, reset the afk kick time to this DEFAULT
  38. Default_AFK_Time = 0
  39.  
  40. -- don't edit --
  41. api_version = "1.9.0.0"
  42. Amt_Players = 0
  43.  
  44. function OnScriptLoad()
  45.     register_callback(cb['EVENT_JOIN'], "OnPlayerJoin")
  46.     register_callback(cb['EVENT_LEAVE'], "OnPlayerLeave")
  47.     register_callback(cb['EVENT_GAME_START'], "OnNewGame")
  48.     register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
  49.     if get_var(0, "$gt") ~= "n/a" then
  50.         Amt_Players = tonumber(get_var(0, "$pn"))
  51.         if (Amt_Players <= Few_Players) then
  52.             execute_command("afk_kick Few_Players_AFK_Time")
  53.             cprint("AFK Kick time was changed to " .. Few_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  54.         elseif (Amt_Players <= Low_Players) then
  55.             execute_command("afk_kick Low_Players_AFK_Time")
  56.             cprint("AFK Kick time was changed to " .. Low_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  57.         elseif (Amt_Players > Low_Players) and (Amt_Players <= Medium_Players) then
  58.             execute_command("afk_kick Medium_Players_AFK_Time")
  59.             cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  60.         elseif (Amt_Players > Medium_Players) and (Amt_Players <= Full_Players) then
  61.             execute_command("afk_kick Full_Players_AFK_Time")
  62.             cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  63.         end
  64.     end    
  65. end
  66.  
  67. function OnPlayerJoin(PlayerIndex)
  68.     Amt_Players = tonumber(get_var(0, "$pn"))
  69.     if (Amt_Players <= Few_Players) then
  70.         execute_command("afk_kick Few_Players_AFK_Time")
  71.         cprint("AFK Kick time was changed to " .. Few_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  72.     elseif (Amt_Players <= Low_Players) then
  73.         execute_command("afk_kick Low_Players_AFK_Time")
  74.         cprint("AFK Kick time was changed to " .. Low_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  75.     elseif (Amt_Players > Low_Players) and (Amt_Players <= Medium_Players) then
  76.         execute_command("afk_kick Medium_Players_AFK_Time")
  77.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  78.     elseif (Amt_Players > Medium_Players) and (Amt_Players <= Full_Players) then
  79.         execute_command("afk_kick Full_Players_AFK_Time")
  80.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  81.     end
  82. end
  83.  
  84. function OnPlayerLeave(PlayerIndex)
  85.     Amt_Players = tonumber(get_var(0, "$pn"))
  86.     if (Amt_Players <= Few_Players) then
  87.         execute_command("afk_kick Few_Players_AFK_Time")
  88.         cprint("AFK Kick time was changed to " .. Few_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  89.     elseif (Amt_Players <= Low_Players) then
  90.         execute_command("afk_kick Low_Players_AFK_Time")
  91.         cprint("AFK Kick time was changed to " .. Low_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  92.     elseif (Amt_Players > Low_Players) and (Amt_Players <= Medium_Players) then
  93.         execute_command("afk_kick Medium_Players_AFK_Time")
  94.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  95.     elseif (Amt_Players > Medium_Players) and (Amt_Players <= Full_Players) then
  96.         execute_command("afk_kick Full_Players_AFK_Time")
  97.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  98.     end
  99. end
  100.  
  101. function OnNewGame()
  102.     Amt_Players = tonumber(get_var(0, "$pn"))
  103.     if (Amt_Players <= Few_Players) then
  104.         execute_command("afk_kick Few_Players_AFK_Time")
  105.         cprint("AFK Kick time was changed to " .. Few_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  106.     elseif (Amt_Players <= Low_Players) then
  107.         execute_command("afk_kick Low_Players_AFK_Time")
  108.         cprint("AFK Kick time was changed to " .. Low_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  109.     elseif (Amt_Players > Low_Players) and (Amt_Players <= Medium_Players) then
  110.         execute_command("afk_kick Medium_Players_AFK_Time")
  111.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  112.     elseif (Amt_Players > Medium_Players) and (Amt_Players <= Full_Players) then
  113.         execute_command("afk_kick Full_Players_AFK_Time")
  114.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  115.     end
  116. end
  117.  
  118. function OnGameEnd()
  119.     Amt_Players = tonumber(get_var(0, "$pn"))
  120.     if (Amt_Players <= Few_Players) then
  121.         execute_command("afk_kick Few_Players_AFK_Time")
  122.         cprint("AFK Kick time was changed to " .. Few_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  123.     elseif (Amt_Players <= Low_Players) then
  124.         execute_command("afk_kick Low_Players_AFK_Time")
  125.         cprint("AFK Kick time was changed to " .. Low_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  126.     elseif (Amt_Players > Low_Players) and (Amt_Players <= Medium_Players) then
  127.         execute_command("afk_kick Medium_Players_AFK_Time")
  128.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  129.     elseif (Amt_Players > Medium_Players) and (Amt_Players <= Full_Players) then
  130.         execute_command("afk_kick Full_Players_AFK_Time")
  131.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  132.     end
  133. end
  134.  
  135. function OnScriptUnload()
  136.     execute_command("afk_kick Default_AFK_Time")
  137.     cprint("AFK Kick time was changed to default of " .. Default_AFK_Time)
  138. end
  139.  
  140. function OnError(Message)
  141.     print(debug.traceback())
  142. end
  143.  
  144. -- Created by H® Shaft
  145. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement