Advertisement
HR_Shaft

Dynamic AFK Kick Times for SAPP

Feb 12th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.47 KB | None | 0 0
  1. -- Dynamic AFK Kick Times for SAPP
  2. -- by H® Shaft
  3. -- Requested by jakallan3
  4.  
  5. -- Script allows server admins to dynamically change AFK Kick times based on the number of players
  6. -- Editable AFK Time and # of Players
  7.  
  8. -- 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
  9. -- how many players constitutes FULL number of players or almost full?
  10. Full_Players = 10
  11.  
  12. -- how many players constitutes medium number of players?  
  13. Medium_Players = 8
  14.  
  15. -- how many players constitutes low number of players?
  16. Low_Players = 6
  17.  
  18. -- how many players constitutes few number of players?
  19. Few_Players = 4
  20.  
  21. ------------
  22. -- Kick Times Strategy: to Keep the server active and have less afk players, the MORE players there are, the LOWER the AFK time:
  23. -- how quickly in seconds to kick AFKs during a FULL player server?
  24. Full_Players_AFK_Time = 90
  25.  
  26. -- how quickly in seconds to kick AFKs during a MEDIUM player server?
  27. Medium_Players_AFK_Time = 180
  28.  
  29. -- how quickly in seconds to kick AFKs during a LOW player server?
  30. Low_Players_AFK_Time = 360
  31.  
  32. -- how quickly in seconds to kick AFKs during a FEW player server?
  33. Few_Players_AFK_Time = 0
  34.  
  35. -- if the script is UNLOADED, reset the afk kick time to this DEFAULT
  36. Default_AFK_Time = 0
  37.  
  38. -- don't edit --
  39. api_version = "1.9.0.0"
  40. Amt_Players = 0
  41.  
  42. function OnScriptLoad()
  43.     register_callback(cb['EVENT_JOIN'], "OnPlayerJoin")
  44.     register_callback(cb['EVENT_LEAVE'], "OnPlayerLeave")
  45.     if get_var(0, "$gt") ~= "n/a" then
  46.         Amt_Players = tonumber(get_var(0, "$pn"))
  47.         if (Amt_Players <= Few_Players) then
  48.             execute_command("afk_kick Few_Players_AFK_Time")
  49.             cprint("AFK Kick time was changed to " .. Few_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  50.         elseif (Amt_Players <= Low_Players) then
  51.             execute_command("afk_kick Low_Players_AFK_Time")
  52.             cprint("AFK Kick time was changed to " .. Low_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  53.         elseif (Amt_Players > Low_Players) and (Amt_Players <= Medium_Players) then
  54.             execute_command("afk_kick Medium_Players_AFK_Time")
  55.             cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  56.         elseif (Amt_Players > Medium_Players) and (Amt_Players <= Full_Players) then
  57.             execute_command("afk_kick Full_Players_AFK_Time")
  58.             cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  59.         end
  60.     end    
  61. end
  62.  
  63. function OnPlayerJoin(PlayerIndex)
  64.     Amt_Players = tonumber(get_var(0, "$pn"))
  65.     if (Amt_Players <= Few_Players) then
  66.         execute_command("afk_kick Few_Players_AFK_Time")
  67.         cprint("AFK Kick time was changed to " .. Few_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  68.     elseif (Amt_Players <= Low_Players) then
  69.         execute_command("afk_kick Low_Players_AFK_Time")
  70.         cprint("AFK Kick time was changed to " .. Low_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  71.     elseif (Amt_Players > Low_Players) and (Amt_Players <= Medium_Players) then
  72.         execute_command("afk_kick Medium_Players_AFK_Time")
  73.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  74.     elseif (Amt_Players > Medium_Players) and (Amt_Players <= Full_Players) then
  75.         execute_command("afk_kick Full_Players_AFK_Time")
  76.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  77.     end
  78. end
  79.  
  80. function OnPlayerLeave(PlayerIndex)
  81.     Amt_Players = tonumber(get_var(0, "$pn"))
  82.     if (Amt_Players =< Few_Players) then
  83.         execute_command("afk_kick Few_Players_AFK_Time")
  84.         cprint("AFK Kick time was changed to " .. Few_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  85.     elseif (Amt_Players =< Low_Players) then
  86.         execute_command("afk_kick Low_Players_AFK_Time")
  87.         cprint("AFK Kick time was changed to " .. Low_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  88.     elseif (Amt_Players > Low_Players) and (Amt_Players <= Medium_Players) then
  89.         execute_command("afk_kick Medium_Players_AFK_Time")
  90.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  91.     elseif (Amt_Players > Medium_Players) and (Amt_Players <= Full_Players) then
  92.         execute_command("afk_kick Full_Players_AFK_Time")
  93.         cprint("AFK Kick time was changed to " .. Medium_Players_AFK_Time .. " # of Players: " .. Amt_Players)
  94.     end
  95. end
  96.  
  97. function OnScriptUnload()
  98.     execute_command("afk_kick Default_AFK_Time")
  99.     cprint("AFK Kick time was changed to default of " .. Default_AFK_Time)
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement