Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Script by giraffe
- api_version = "1.6.0.0"
- -- In seconds the time required of time played before you can vote to skip
- required_time = 300
- -- In seconds the amount of time of inactivity required to be considered afk
- -- While afk, time is not added to time played and player is not included in the total player count
- afk_time = 90
- -- In seconds the amount of time of inactivity required to be considered idle
- -- While idle, time is not added to time played
- idle_time = 10
- -- Percent value between 0 through 100 of the non-afk players required to vote skip before a map skips
- required_percent = 50
- -- In seconds how often to check if map should be skipped
- skip_check_time = 1.5
- -- DO NOT EDIT THESE VARIABLES --
- has_voted_to_skip = {}
- time_waited = {}
- map_skipped = false
- function OnScriptLoad()
- timer(1000, "AddTime")
- timer(skip_check_time * 1000, "SkipCheck")
- register_callback(cb['EVENT_GAME_START'], "OnGameStart")
- register_callback(cb['EVENT_CHAT'], "OnChatMessage")
- register_callback(cb['EVENT_LEAVE'], "OnPlayerLeave")
- register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
- end
- function OnScriptUnload() end
- function OnGameStart()
- map_skipped = false
- has_voted_to_skip = {}
- time_waited = {}
- end
- function OnChatMessage(PlayerIndex, Message)
- if(Message:lower() == "skip") then
- if(map_skipped) then
- say(PlayerIndex, "Map is already changing.")
- elseif(has_voted_to_skip[PlayerIndex] == true) then
- say(PlayerIndex, "You have already voted to skip")
- elseif(get_var(PlayerIndex, "$afk") ~= nil and tonumber(get_var(PlayerIndex, "$afk")) > idle_time) then
- say(PlayerIndex, "You cannot vote to skip while idle/afk.")
- elseif((required_time - time_waited[PlayerIndex]) <= 0) then
- has_voted_to_skip[PlayerIndex] = true
- players_needed = playersNeeded()
- say_all(get_var(PlayerIndex, "$name") .. " has voted to skip this map.")
- if(players_needed == 0) then
- elseif(players_needed == 1) then
- say_all("1 more player vote is needed to skip the map.")
- else
- say_all(players_needed .. " more player votes are needed to skip the map.")
- end
- else
- say(PlayerIndex, "You must wait " .. (required_time - time_waited[PlayerIndex]) .. " more seconds before voting to skip.")
- end
- return false
- end
- return true
- end
- function OnPlayerLeave(PlayerIndex)
- time_waited[PlayerIndex] = 0
- has_voted_to_skip[PlayerIndex] = false
- end
- function OnGameEnd()
- map_skipped = true
- end
- function AddTime()
- for i=1,16 do
- if(player_present(i) and (get_var(i, "$afk") == nil or tonumber(get_var(i, "$afk")) <= idle_time) and (time_waited[i] == nil or time_waited[i] < required_time)) then
- if(time_waited[i] == nil) then
- time_waited[i] = 1
- else
- time_waited[i] = time_waited[i] + 1
- end
- end
- end
- return true
- end
- function playersNeeded()
- active_players = 0
- players_voted_skip = 0
- for i=1,16 do
- if(get_var(i, "$afk") == nil or tonumber(get_var(i, "$afk")) <= afk_time) then
- if(player_present(i)) then
- active_players = active_players + 1
- end
- if(has_voted_to_skip[i] ~= nil and has_voted_to_skip[i] == true) then
- players_voted_skip = players_voted_skip + 1
- end
- end
- end
- return math.ceil((active_players) * (required_percent / 100)) - players_voted_skip
- end
- function SkipCheck()
- if(not map_skipped) then
- active_players = 0
- players_voted_skip = 0
- for i=1,16 do
- if(get_var(i, "$afk") == nil or tonumber(get_var(i, "$afk")) <= afk_time) then
- if(player_present(i)) then
- active_players = active_players + 1
- end
- if(has_voted_to_skip[i] ~= nil and has_voted_to_skip[i] == true) then
- players_voted_skip = players_voted_skip + 1
- end
- end
- end
- if((players_voted_skip / active_players) >= (required_percent / 100)) then
- say_all("Enough players have voted to skip. Map is changing.")
- execute_command("sv_map_next")
- map_skipped = true
- end
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment