Advertisement
HR_Shaft

Rock-The-Vote v4 Map Skipping for Phasor v2+

Jul 16th, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.00 KB | None | 0 0
  1. --[[ ###    Rock-The-Vote v4 ###]]--
  2. --[[ ###     by H® Shaft     ###]]--
  3. --[[ ###    for Phasor v2+   ###]]--
  4.  
  5. -- changes: enabling rock the vote, and vote percentage required for skipping map is now editable per map, see lines 43 thru 82
  6. -- re-formed to allow use as persistent or non-persistent and to be reloadable for compatibility with other scripts without error
  7.  
  8. function GetRequiredVersion()
  9.     return 200
  10. end
  11.  
  12. function OnScriptLoad(processId, game, persistent)
  13.     GAME = game
  14.     GetGameAddresses(game)
  15.     ScriptLoad()
  16. end
  17.  
  18. function ScriptLoad()
  19.    
  20.     -- don't edit ---
  21.     GetGameAddresses(GAME)
  22.     rockthevote = {}
  23.     rtv_required = {}
  24.     rtv_table = {}
  25.     cur_players = 0
  26.     rtv_timeout = 1
  27.     rtv_initiated = 0
  28.     game_started = false
  29.     for i = 0,15 do
  30.         if getplayer(i) then   
  31.             cur_players = cur_players + 1
  32.         end
  33.     end
  34.    
  35.     if map_reset == true then
  36.         map_reset = false
  37.         game_started = true
  38.     end
  39.    
  40.     -- ------------------ Edit Below This Line --------------------------
  41.     -- enable rtv on this map                           Edit Boolean: enable = true, disable = false
  42.     rockthevote.            beavercreek         =       true           
  43.     rockthevote.            bloodgulch          =       true               
  44.     rockthevote.            boardingaction      =       true   
  45.     rockthevote.            carousel            =       true           
  46.     rockthevote.            chillout            =       true   
  47.     rockthevote.            damnation           =       true   
  48.     rockthevote.            dangercanyon        =       true               
  49.     rockthevote.            deathisland         =       true           
  50.     rockthevote.            gephyrophobia       =       true   
  51.     rockthevote.            hangemhigh          =       true               
  52.     rockthevote.            icefields           =       true               
  53.     rockthevote.            infinity            =       true               
  54.     rockthevote.            longest             =       true               
  55.     rockthevote.            prisoner            =       true               
  56.     rockthevote.            putput              =       true           
  57.     rockthevote.            ratrace             =       true               
  58.     rockthevote.            sidewinder          =       true               
  59.     rockthevote.            timberland          =       true               
  60.     rockthevote.            wizard              =       true
  61.  
  62.     -- vote % of players required to skip the map       Edit Percent Required (decimal value)
  63.     rtv_required.           beavercreek         =       0.7            
  64.     rtv_required.           bloodgulch          =       0.8            
  65.     rtv_required.           boardingaction      =       0.6            
  66.     rtv_required.           carousel            =       0.7            
  67.     rtv_required.           chillout            =       0.7    
  68.     rtv_required.           damnation           =       0.7    
  69.     rtv_required.           dangercanyon        =       0.7            
  70.     rtv_required.           deathisland         =       0.6        
  71.     rtv_required.           gephyrophobia       =       0.8    
  72.     rtv_required.           hangemhigh          =       0.7            
  73.     rtv_required.           icefields           =       0.7            
  74.     rtv_required.           infinity            =       0.6            
  75.     rtv_required.           longest             =       0.7            
  76.     rtv_required.           prisoner            =       0.6            
  77.     rtv_required.           putput              =       0.7            
  78.     rtv_required.           ratrace             =       0.7            
  79.     rtv_required.           sidewinder          =       0.7            
  80.     rtv_required.           timberland          =       0.7            
  81.     rtv_required.           wizard              =       0.7
  82.     -- ------------------ Edit Above This Line --------------------------
  83.    
  84.     -- don't edit ---  
  85.     if map_name then rockthevote[map_name] = rockthevote[map_name] or true end
  86.     if map_name then rtv_required[map_name] = rtv_required[map_name] or 0.5 end    
  87.  
  88. end
  89.  
  90. function OnNewGame(map)
  91.     ScriptLoad()
  92.     game_started = true
  93. end
  94.  
  95. function OnServerCommand(player, command)
  96.     local allow = nil
  97.     local cmd = tokenizecmdstring(command)
  98.     local tokencount = #cmd
  99.     if tokencount > 0 then
  100.    
  101.         if cmd[1] == "sv_map_reset" then
  102.             map_reset = true       
  103.             ScriptLoad()                   
  104.             allow = true
  105.            
  106.         elseif cmd[1] == "sv_script_reload" then
  107.             map_reset = true
  108.             ScriptLoad()       
  109.             allow = true
  110.         end
  111.        
  112.     end
  113.     return allow
  114. end
  115.  
  116. function GetGameAddresses(game)
  117.     if game == "PC" or GAME == "PC" then
  118.         map_name = readstring(0x698F21)
  119.         network_base = 0x745BA8
  120.     else
  121.         map_name = readstring(0x61D151)
  122.         network_base = 0x6C7988
  123.     end
  124. end
  125.  
  126. function OnPlayerJoin(player)
  127.     if getplayer(player) then
  128.         cur_players = cur_players + 1
  129.         announce = registertimer(20000, "announcement", player)
  130.     end
  131. end
  132.  
  133. function OnPlayerLeave(player)
  134.     if getplayer(player) then
  135.         cur_players = cur_players - 1
  136.     end    
  137. end
  138.  
  139. function announcement(id, count, player)
  140.     if getplayer(player) and game_started then
  141.         privatesay(player, "Map skip voting is enabled (Rock-the-Vote). Type SKIP or RTV to vote to skip the map.")
  142.     end
  143.     return false   
  144. end
  145.  
  146. function OnServerChat(player, type, message)
  147.     if player then
  148.         name = getname(player)
  149.         hash = gethash(player)
  150.     end
  151.    
  152.     local t = tokenizestring(message, " ")
  153.     local count = #t
  154.     if t[1] == nil then
  155.         return true
  156.     end
  157.  
  158.     if string.lower(t[1]) == "rtv" or string.lower(t[1]) == "skip" then
  159.         if count == 1 and rockthevote[map_name] then
  160.             if rtv_initiated >= 0 then
  161.                 local rtv_count = 0
  162.                 local rtv_number = round(cur_players * rtv_required[map_name], 0)
  163.                 for i = 0,15 do
  164.                     if getplayer(i) then
  165.                         if rtv_table[gethash(i)] == 1 then
  166.                             rtv_count = rtv_count + 1
  167.                         end
  168.                     end
  169.                 end
  170.                 if rtv_count == 0 then
  171.                     rtv_initiated = 1
  172.                     rtv_table[hash] = 1
  173.                     rtv_count = rtv_count + 1
  174.                     say(name .. " has voted to skip this map! Type \"rtv\" or \"skip\" to join the vote to skip this map.")
  175.                     say(rtv_count .. " of " .. rtv_number .. " votes required to skip this map.")
  176.                     rtvtimer = registertimer(120000, "rtvTimer") -- two minutes before vote expires
  177.                 else
  178.                     if rtv_table[hash] == 1 then
  179.                         privatesay(player, "You have already voted.")
  180.                     elseif rtv_table[hash] == nil then
  181.                         rtv_table[hash] = 1
  182.                         rtv_count = rtv_count + 1
  183.                         say(name .. " has voted to skip this map! Type \"rtv\" or \"skip\" to join the vote to skip this map.")
  184.                         say(rtv_count .. " of " .. rtv_number .. " votes required to skip this map.")
  185.                     end
  186.                 end
  187.                 if rtv_count >= rtv_number then
  188.                     removetimer(rtvtimer)
  189.                     rtvtimer = nil
  190.                     rtv_initiated = rtv_timeout
  191.                     say("The number of required votes to skip this map has been reached. Skipping to next map.")
  192.                     svcmd("sv_map_next")
  193.                 end
  194.             else
  195.                 privatesay(player, "You cannot initiate a vote a this time.")
  196.             end
  197.             return false
  198.         elseif count == 1 and not rockthevote[map_name] then
  199.             privatesay(player, "Voting is disabled for this map.")
  200.             return false
  201.         end
  202.     end
  203.    
  204.     return nil
  205. end
  206.  
  207. function OnGameEnd(stage)
  208.     if stage == 1 then
  209.         game_started = false
  210.         if rtvtimer then
  211.             removetimer(rtvtimer)
  212.             rtvtimer = nil
  213.         end
  214.         if announce then
  215.             --removetimer(announce)
  216.             announce = nil
  217.         end
  218.         rtv_initiated = -1
  219.     end
  220. end
  221.  
  222. function rtvTimer(id, count)
  223.     if count == 1 then
  224.         rtv_initiated = rtv_timeout
  225.         rtv_table = {}
  226.         say("The current vote to skip the map has expired!")
  227.         return false
  228.     else
  229.         return true
  230.     end
  231. end
  232.  
  233. function round(num)
  234.     under = math.floor(num)
  235.     upper = math.floor(num) + 1
  236.     underV = -(under - num)
  237.     upperV = upper - num
  238.     if (upperV > underV) then
  239.         return under
  240.     else
  241.         return upper
  242.     end
  243. end
  244.  
  245. --[[ Created by H® Shaft. Original by various contributors, Wizard, Chalonic, CE=Chris
  246. Thanks to Oxide, AelitePrime, Nugget & Wizard.
  247. Visit http://halorace.org/forum/index.php?topic=514.0 or
  248. Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
  249. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement