LUA 351
V2+ Rock The Vote - Skip 5.0 By xdedeone on 26th February 2019 04:32:26 PM
  1. --[[ ###    Rock-The-Vote v5  ###]]--
  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 48 thru 92
  6. -- re-formed to allow use as persistent or non-persistent and to be reloadable for compatibility with other scripts without error
  7. -- re-worked to be less spammy in the chat
  8.  
  9. -- prefix globals
  10. default_script_prefix = "\171 RTV \187 "
  11. phasor_privatesay = privatesay
  12. phasor_say = say
  13.  
  14. function GetRequiredVersion()
  15.         return 200
  16. end
  17.  
  18. function OnScriptLoad(processId, game, persistent)
  19.         map_reset = false
  20.         game_started = false
  21.     GAME = game
  22.         GetGameAddresses(game)
  23.     ScriptLoad()
  24. end
  25.  
  26. function ScriptLoad()
  27.        
  28.         -- don't edit ---
  29.         GetGameAddresses(GAME)
  30.         writeword(special_chars, 0x9090)
  31.         rockthevote = {}
  32.         rtv_required = {}
  33.         rtv_table = {}
  34.         cur_players = 0
  35.         rtv_timeout = 1
  36.         rtv_initiated = 0
  37.         game_started = true
  38.         for i = 0,15 do
  39.                 if getplayer(i) then   
  40.                         cur_players = cur_players + 1
  41.                 end
  42.         end
  43.         if map_reset == true then
  44.                 map_reset = false
  45.                 game_started = true
  46.         end            
  47.        
  48.         -- ------------------ Edit Below This Line --------------------------
  49.         -- enable rtv on this map                                                       Edit Boolean: enable = true, disable = false
  50.         rockthevote.                    beavercreek             =               true                   
  51.         rockthevote.                    bloodgulch                      =               true                           
  52.         rockthevote.                    boardingaction          =               true   
  53.         rockthevote.                    carousel                        =               true                   
  54.         rockthevote.                    chillout                        =               true   
  55.         rockthevote.                    damnation                       =               true   
  56.         rockthevote.                    dangercanyon            =               true                           
  57.         rockthevote.                    deathisland             =               true                   
  58.         rockthevote.                    gephyrophobia           =               true   
  59.         rockthevote.                    hangemhigh                      =               true                           
  60.         rockthevote.                    icefields                       =               true                           
  61.         rockthevote.                    infinity                        =               true                           
  62.         rockthevote.                    longest                         =               true                           
  63.         rockthevote.                    prisoner                        =               true                           
  64.         rockthevote.                    putput                          =               true                   
  65.         rockthevote.                    ratrace                         =               true                           
  66.         rockthevote.                    sidewinder                      =               true                           
  67.         rockthevote.                    timberland                      =               true                           
  68.         rockthevote.                    wizard                          =               true
  69.  
  70.  
  71.         -- vote % of players required to skip the map           Edit Percent Required (decimal value)
  72.         rtv_required.                   beavercreek             =               0.7                    
  73.         rtv_required.                   bloodgulch                      =               0.8                            
  74.         rtv_required.                   boardingaction          =               0.6                            
  75.         rtv_required.                   carousel                        =               0.7                    
  76.         rtv_required.                   chillout                        =               0.7            
  77.         rtv_required.                   damnation                       =               0.7            
  78.         rtv_required.                   dangercanyon            =               0.7                            
  79.         rtv_required.                   deathisland             =               0.6                    
  80.         rtv_required.                   gephyrophobia           =               0.8            
  81.         rtv_required.                   hangemhigh                      =               0.7                            
  82.         rtv_required.                   icefields                       =               0.7                            
  83.         rtv_required.                   infinity                        =               0.6                            
  84.         rtv_required.                   longest                         =               0.7                            
  85.         rtv_required.                   prisoner                        =               0.6                            
  86.         rtv_required.                   putput                          =               0.7                    
  87.         rtv_required.                   ratrace                         =               0.7                            
  88.         rtv_required.                   sidewinder                      =               0.7                            
  89.         rtv_required.                   timberland                      =               0.7                            
  90.         rtv_required.                   wizard                          =               0.7
  91.                
  92.         -- ------------------ Edit Above This Line --------------------------
  93.        
  94.         -- don't edit ---      
  95.         if map_name then rockthevote[map_name] = rockthevote[map_name] or true end
  96.         if map_name then rtv_required[map_name] = rtv_required[map_name] or 0.6 end            
  97.  
  98. end
  99.  
  100. function OnNewGame(map)
  101.         ScriptLoad()
  102.         game_started = true
  103. end
  104.  
  105. function OnServerCommand(player, command)
  106.         local allow = nil
  107.         local cmd = tokenizecmdstring(command)
  108.         local tokencount = #cmd
  109.         if tokencount > 0 then
  110.        
  111.                 if cmd[1] == "sv_map_reset" then
  112.                         map_reset = true
  113.                         game_started = true                    
  114.                         ScriptLoad()                                   
  115.                         allow = true
  116.                        
  117.                 elseif cmd[1] == "sv_script_reload" then
  118.                         map_reset = true
  119.                         game_started = true
  120.                         ScriptLoad()           
  121.                         allow = true
  122.                 end
  123.                
  124.         end
  125.         return allow
  126. end
  127.  
  128. function GetGameAddresses(game)
  129.         if game == "PC" or GAME == "PC" then
  130.                 map_name = readstring(0x698F21)
  131.                 network_base = 0x745BA8
  132.                 special_chars = 0x517D6B
  133.         else
  134.                 map_name = readstring(0x61D151)
  135.                 network_base = 0x6C7988
  136.                 special_chars = 0x4CE0CD
  137.         end
  138. end
  139.  
  140. function OnPlayerJoin(player)
  141.         if getplayer(player) then
  142.                 cur_players = cur_players + 1
  143.                 announce = registertimer(20000, "announcement", player)
  144.         end    
  145. end
  146.  
  147. function OnPlayerLeave(player)
  148.         if getplayer(player) then
  149.                 cur_players = cur_players - 1
  150.         end            
  151. end
  152.  
  153. function announcement(id, count, player)
  154.         if getplayer(player) and game_started then
  155.                 privatesay(player, "Map skipping is enabled. Type SKIP or RTV to vote to skip the map.")
  156.         end
  157.         return false   
  158. end
  159.  
  160. function privatesay(player, message, script_prefix)
  161.     if GAME == "PC" then
  162.         phasor_privatesay(player, (script_prefix or default_script_prefix) .. " " .. message, false)
  163.     else
  164.         phasor_privatesay(player, message, false)
  165.     end
  166. end
  167.  
  168. function say(message, script_prefix)
  169.     if GAME == "PC" then
  170.         phasor_say((script_prefix or default_script_prefix) .. " " .. message, false)
  171.     else
  172.         phasor_say(message, false)
  173.     end
  174. end
  175.  
  176. function killmessage(message, killer) -- Self-explanatory
  177.         for player=0,15 do
  178.                 if getplayer(player) and player ~= killer then
  179.                         phasor_privatesay(player, message, false)
  180.                 end
  181.         end
  182. end
  183.  
  184. function OnServerChat(player, type, message)
  185.         local response = nil
  186.         if player then
  187.                 local name = getname(player)
  188.                 local hash = gethash(player)
  189.        
  190.                 local t = tokenizecmdstring(message)
  191.                 local count = #t
  192.                 if t[1] == nil then
  193.                         return true
  194.                 end
  195.  
  196.                 if string.lower(t[1]) == "rtv" or string.lower(t[1]) == "skip" then
  197.                         response = false
  198.                         if count == 1 and rockthevote[map_name] then
  199.                                 if rtv_initiated >= 0 then
  200.                                         local rtv_count = 0
  201.                                         local rtv_number = round(cur_players * rtv_required[map_name], 0)
  202.                                         for i = 0,15 do
  203.                                                 if getplayer(i) then
  204.                                                         if rtv_table[gethash(i)] == 1 then
  205.                                                                 rtv_count = rtv_count + 1
  206.                                                         end
  207.                                                 end
  208.                                         end
  209.                                         if game_started then
  210.                                                 if rtv_count == 0 then
  211.                                                         rtv_initiated = 1
  212.                                                         rtv_table[hash] = 1
  213.                                                         rtv_count = rtv_count + 1
  214.                                                         say(name .. " has voted to skip this map! " .. rtv_count .. " of " .. rtv_number .. " votes required, type \"skip\" to join the vote.")
  215.                                                         rtvtimer = registertimer(120000, "rtvTimer")
  216.                                                 else
  217.                                                         if rtv_table[hash] == 1 then
  218.                                                                 privatesay(player, "You have already voted.")
  219.                                                         elseif rtv_table[hash] == nil then
  220.                                                                 rtv_table[hash] = 1
  221.                                                                 rtv_count = rtv_count + 1
  222.                                                                 say(name .. " has voted to skip this map! " .. rtv_count .. " of " .. rtv_number .. " votes required, type \"skip\" to join the vote.")
  223.                                                         end
  224.                                                 end
  225.                                                 if rtv_count >= rtv_number then
  226.                                                         removetimer(rtvtimer)
  227.                                                         rtvtimer = nil
  228.                                                         rtv_initiated = rtv_timeout
  229.                                                         svcmd("sv_map_next")
  230.                                                 end
  231.                                         else
  232.                                                 privatesay(player, "The game has already ended.")
  233.                                         end
  234.                                 else
  235.                                         privatesay(player, "You cannot initiate a vote a this time.")
  236.                                 end
  237.                         elseif count == 1 and not rockthevote[map_name] then
  238.                                 privatesay(player, "Voting is disabled for this map.")
  239.                         end
  240.                         return response
  241.                 end
  242.                 return response
  243.         end            
  244.         return response
  245. end
  246.  
  247. function OnGameEnd(stage)
  248.         if stage == 1 then
  249.                 game_started = false
  250.                 if rtvtimer then
  251.                         rtvtimer = nil
  252.                 end
  253.                 if announce then
  254.                         announce = nil
  255.                 end
  256.                 rtv_initiated = -1
  257.         end    
  258. end
  259.  
  260. function rtvTimer(id, count)
  261.         if count == 1 then
  262.                 rtv_initiated = rtv_timeout
  263.                 rtv_table = {}
  264.                 say("The current vote to skip the map has expired!")
  265.                 return false
  266.         else
  267.                 return true
  268.         end
  269. end
  270.  
  271. function round(num)
  272.     under = math.floor(num)
  273.     upper = math.floor(num) + 1
  274.     underV = -(under - num)
  275.     upperV = upper - num
  276.     if (upperV > underV) then
  277.         return under
  278.     else
  279.         return upper
  280.     end
  281. end
  282.  
  283. --[[ Created by H® Shaft.
  284. Thanks to Oxide, AelitePrime, Nugget & Wizard.
  285. Visit http://halorace.org/forum/index.php?topic=514.0 or
  286. Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
  287. ]]

HaloNet.Net is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.