- --[[ ### Rock-The-Vote v5 ###]]--
- --[[ ### by H® Shaft ###]]--
- --[[ ### for Phasor v2+ ###]]--
- -- changes: enabling rock the vote, and vote percentage required for skipping map is now editable per map, see lines 48 thru 92
- -- re-formed to allow use as persistent or non-persistent and to be reloadable for compatibility with other scripts without error
- -- re-worked to be less spammy in the chat
- -- prefix globals
- default_script_prefix = "\171 RTV \187 "
- phasor_privatesay = privatesay
- phasor_say = say
- function GetRequiredVersion()
- return 200
- end
- function OnScriptLoad(processId, game, persistent)
- map_reset = false
- game_started = false
- GAME = game
- GetGameAddresses(game)
- ScriptLoad()
- end
- function ScriptLoad()
- -- don't edit ---
- GetGameAddresses(GAME)
- writeword(special_chars, 0x9090)
- rockthevote = {}
- rtv_required = {}
- rtv_table = {}
- cur_players = 0
- rtv_timeout = 1
- rtv_initiated = 0
- game_started = true
- for i = 0,15 do
- if getplayer(i) then
- cur_players = cur_players + 1
- end
- end
- if map_reset == true then
- map_reset = false
- game_started = true
- end
- -- ------------------ Edit Below This Line --------------------------
- -- enable rtv on this map Edit Boolean: enable = true, disable = false
- rockthevote. beavercreek = true
- rockthevote. bloodgulch = true
- rockthevote. boardingaction = true
- rockthevote. carousel = true
- rockthevote. chillout = true
- rockthevote. damnation = true
- rockthevote. dangercanyon = true
- rockthevote. deathisland = true
- rockthevote. gephyrophobia = true
- rockthevote. hangemhigh = true
- rockthevote. icefields = true
- rockthevote. infinity = true
- rockthevote. longest = true
- rockthevote. prisoner = true
- rockthevote. putput = true
- rockthevote. ratrace = true
- rockthevote. sidewinder = true
- rockthevote. timberland = true
- rockthevote. wizard = true
- -- vote % of players required to skip the map Edit Percent Required (decimal value)
- rtv_required. beavercreek = 0.7
- rtv_required. bloodgulch = 0.8
- rtv_required. boardingaction = 0.6
- rtv_required. carousel = 0.7
- rtv_required. chillout = 0.7
- rtv_required. damnation = 0.7
- rtv_required. dangercanyon = 0.7
- rtv_required. deathisland = 0.6
- rtv_required. gephyrophobia = 0.8
- rtv_required. hangemhigh = 0.7
- rtv_required. icefields = 0.7
- rtv_required. infinity = 0.6
- rtv_required. longest = 0.7
- rtv_required. prisoner = 0.6
- rtv_required. putput = 0.7
- rtv_required. ratrace = 0.7
- rtv_required. sidewinder = 0.7
- rtv_required. timberland = 0.7
- rtv_required. wizard = 0.7
- -- ------------------ Edit Above This Line --------------------------
- -- don't edit ---
- if map_name then rockthevote[map_name] = rockthevote[map_name] or true end
- if map_name then rtv_required[map_name] = rtv_required[map_name] or 0.6 end
- end
- function OnNewGame(map)
- ScriptLoad()
- game_started = true
- end
- function OnServerCommand(player, command)
- local allow = nil
- local cmd = tokenizecmdstring(command)
- local tokencount = #cmd
- if tokencount > 0 then
- if cmd[1] == "sv_map_reset" then
- map_reset = true
- game_started = true
- ScriptLoad()
- allow = true
- elseif cmd[1] == "sv_script_reload" then
- map_reset = true
- game_started = true
- ScriptLoad()
- allow = true
- end
- end
- return allow
- end
- function GetGameAddresses(game)
- if game == "PC" or GAME == "PC" then
- map_name = readstring(0x698F21)
- network_base = 0x745BA8
- special_chars = 0x517D6B
- else
- map_name = readstring(0x61D151)
- network_base = 0x6C7988
- special_chars = 0x4CE0CD
- end
- end
- function OnPlayerJoin(player)
- if getplayer(player) then
- cur_players = cur_players + 1
- announce = registertimer(20000, "announcement", player)
- end
- end
- function OnPlayerLeave(player)
- if getplayer(player) then
- cur_players = cur_players - 1
- end
- end
- function announcement(id, count, player)
- if getplayer(player) and game_started then
- privatesay(player, "Map skipping is enabled. Type SKIP or RTV to vote to skip the map.")
- end
- return false
- end
- function privatesay(player, message, script_prefix)
- if GAME == "PC" then
- phasor_privatesay(player, (script_prefix or default_script_prefix) .. " " .. message, false)
- else
- phasor_privatesay(player, message, false)
- end
- end
- function say(message, script_prefix)
- if GAME == "PC" then
- phasor_say((script_prefix or default_script_prefix) .. " " .. message, false)
- else
- phasor_say(message, false)
- end
- end
- function killmessage(message, killer) -- Self-explanatory
- for player=0,15 do
- if getplayer(player) and player ~= killer then
- phasor_privatesay(player, message, false)
- end
- end
- end
- function OnServerChat(player, type, message)
- local response = nil
- if player then
- local name = getname(player)
- local hash = gethash(player)
- local t = tokenizecmdstring(message)
- local count = #t
- if t[1] == nil then
- return true
- end
- if string.lower(t[1]) == "rtv" or string.lower(t[1]) == "skip" then
- response = false
- if count == 1 and rockthevote[map_name] then
- if rtv_initiated >= 0 then
- local rtv_count = 0
- local rtv_number = round(cur_players * rtv_required[map_name], 0)
- for i = 0,15 do
- if getplayer(i) then
- if rtv_table[gethash(i)] == 1 then
- rtv_count = rtv_count + 1
- end
- end
- end
- if game_started then
- if rtv_count == 0 then
- rtv_initiated = 1
- rtv_table[hash] = 1
- rtv_count = rtv_count + 1
- say(name .. " has voted to skip this map! " .. rtv_count .. " of " .. rtv_number .. " votes required, type \"skip\" to join the vote.")
- rtvtimer = registertimer(120000, "rtvTimer")
- else
- if rtv_table[hash] == 1 then
- privatesay(player, "You have already voted.")
- elseif rtv_table[hash] == nil then
- rtv_table[hash] = 1
- rtv_count = rtv_count + 1
- say(name .. " has voted to skip this map! " .. rtv_count .. " of " .. rtv_number .. " votes required, type \"skip\" to join the vote.")
- end
- end
- if rtv_count >= rtv_number then
- removetimer(rtvtimer)
- rtvtimer = nil
- rtv_initiated = rtv_timeout
- svcmd("sv_map_next")
- end
- else
- privatesay(player, "The game has already ended.")
- end
- else
- privatesay(player, "You cannot initiate a vote a this time.")
- end
- elseif count == 1 and not rockthevote[map_name] then
- privatesay(player, "Voting is disabled for this map.")
- end
- return response
- end
- return response
- end
- return response
- end
- function OnGameEnd(stage)
- if stage == 1 then
- game_started = false
- if rtvtimer then
- rtvtimer = nil
- end
- if announce then
- announce = nil
- end
- rtv_initiated = -1
- end
- end
- function rtvTimer(id, count)
- if count == 1 then
- rtv_initiated = rtv_timeout
- rtv_table = {}
- say("The current vote to skip the map has expired!")
- return false
- else
- return true
- end
- end
- function round(num)
- under = math.floor(num)
- upper = math.floor(num) + 1
- underV = -(under - num)
- upperV = upper - num
- if (upperV > underV) then
- return under
- else
- return upper
- end
- end
- --[[ Created by H® Shaft.
- Thanks to Oxide, AelitePrime, Nugget & Wizard.
- Visit http://halorace.org/forum/index.php?topic=514.0 or
- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
- ]]
Recent Pastes