SHARE
TWEET

Votekick for Sapp

it300 Nov 10th, 2014 (edited) 203 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. -- Votekick
  3. -- SAPP Compatability: 8.6+
  4. -- Script by: Skylace aka Devieth
  5. -- Discord: https://discord.gg/Mxmuxgm
  6.  
  7. start_votekick_command = "/votekick" -- Command used to start a votekick
  8. vote_yes_command = "/kick" -- Command to vote yes to kick the player.
  9. votekick_needed = 0.7 -- Persentage of total players needed.
  10. votekick_timeout = 5 -- Minutes before a votekick expires.
  11.  
  12. votes = 0
  13. voted = {}
  14.  
  15. api_version = "1.6.0.0"
  16.  
  17. function OnScriptLoad()
  18.     victim = nil
  19.     victim_name = nil
  20.     excute_command("setcmd pl -1") -- Allows all players to use /pl command.
  21.     register_callback(cb['EVENT_CHAT'], "OnChat")
  22.     register_callback(cb['EVENT_JOIN'], "OnJoin")
  23.     register_callback(cb['EVENT_LEAVE'], "OnLeave")
  24. end
  25.  
  26. function OnJoin(PlayerIndex)
  27.     voted[PlayerIndex] = false
  28. end
  29.  
  30. function OnJoin(PlayerIndex)
  31.     if voted[PlayerIndex] then votes = votes -1 end
  32. end
  33.  
  34. function OnChat(PlayerIndex, Message)
  35.     local allow = true
  36.     if PlayerIndex ~= "-1" then
  37.         local t = tokenizestring(string.lower(Message), " ")
  38.         if t[1] == start_votekick_command then
  39.             allow = false
  40.             if tonumber(get_var(PlayerIndex, "$pn")) > 2 then
  41.                 if tonumber(t[2]) ~= nil then -- Make sure they didnt forget to add the victim's player number.
  42.                     if tonumber(t[2]) > 0 and tonumber(t[2]) < 17 then -- Make sure its within a valid player number range.
  43.                         victim_name = get_var(t[2], "$name")
  44.                         victim = t[2]
  45.                         if votes == 0 then
  46.                             local needed = math.floor(tonumber(get_var(PlayerIndex, "$pn")) * votekick_needed)
  47.                             if PlayerIndex ~= t[2] then
  48.                                 say_all(get_var(PlayerIndex, "$name") .. " has started a votekick on " .. victim_name .. "! 1 of " .. needed .. " votes needed to kick!")
  49.                             else
  50.                                 say_all(get_var(PlayerIndex, "$name") .. " has started a votekick on himself! 1 of " .. needed .. " votes needed to kick!") -- Yep, if they want to kick themselves, let them.
  51.                             end
  52.                             say_all("Type "..vote_yes_command.." in chat to votekick " .. victim_name.. "!")
  53.                             timer(votekick_timeout*60*1000, "timeout", false)
  54.                             voted[PlayerIndex] = true
  55.                             votes = votes + 1
  56.                         else
  57.                             say(PlayerIndex, "A votekick on " .. victim_name .. " is already active. Try again latter.")
  58.                         end
  59.                     else
  60.                         say(PlayerIndex, "Invalid player! Use /pl to get valid players.")
  61.                     end
  62.                 else
  63.                     say(PlayerIndex, "Error: Please use the player's number. Use /pl to display player numbers.")
  64.                 end
  65.             else
  66.                 say(PlayerIndex, "Error: Not enough players to start a votekick")
  67.             end
  68.         elseif t[1] == vote_yes_command then
  69.             if votes ~= 0 then
  70.                 if not voted[PlayerIndex] then
  71.                     votes = votes + 1
  72.                     voted[PlayerIndex] = true
  73.                     local needed = math.floor(tonumber(get_var(PlayerIndex, "$pn")) * votekick_needed)
  74.                     if tonumber(votes) >= tonumber(needed) then
  75.                         say_all("Enough votes to kick " .. victim_name .. "!")
  76.                         execute_command("k ".. victim .." 'Votekick'")
  77.                         timeout(true)
  78.                     else
  79.                         say_all(votes .. "of " .. needed .. " votes needed to kick " .. victim_name .. "!")
  80.                     end
  81.                 else
  82.                     say(PlayerIndex, "You have already voted to kick "..victim_name..".")
  83.                 end
  84.             else
  85.                 say(PlayerIndex, "There are no currently active votekicks.")
  86.             end
  87.         end
  88.     end
  89.     return allow
  90. end
  91.  
  92. function timeout(Kicked)
  93.     if victim ~= nil then
  94.         if not Kicked then
  95.             for i = 1,16 do voted[i] = false end
  96.             say_all("The votekick on "..victim_name.." has expired!")
  97.             victim = nil
  98.             victim_name = nil
  99.             votes = 0
  100.         else
  101.             for i = 1,16 do voted[i] = false end
  102.             victim = nil
  103.             victim_name = nil
  104.             votes = 0
  105.         end
  106.     end
  107. end
  108.  
  109. function tokenizestring(inputstr, sep)
  110.     if sep == nil then
  111.         sep = "%s"
  112.     end
  113.     local t={} ; i=1
  114.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  115.         t[i] = str
  116.         i = i + 1
  117.     end
  118.     return t
  119. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top