HR_Shaft

Rock-The-Vote 3.4 for Phasor V2

Oct 11th, 2013
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.73 KB | None | 0 0
  1. --[[ ###    Rock-The-Vote    ###]]--
  2. --[[ ###     by H® Shaft     ###]]--
  3. --[[ ###    for Phasor v2    ###]]--
  4. --[[ ###     version 3.4     ###]]--
  5.  
  6.  
  7. -- don't edit --
  8. cur_players = 0
  9. rtv_table = {}
  10. rtv_timeout = 1
  11. rtv_initiated = 0
  12. rock_the_vote = {}
  13. rtv_required = {}
  14.  
  15. -- Toggle Rock the Vote on = True, Off = False
  16.                 --map                       true/false
  17. rock_the_vote.  beavercreek         =       true -- battle creek
  18. rock_the_vote.  bloodgulch          =       true               
  19. rock_the_vote.  boardingaction      =       true               
  20. rock_the_vote.  carousel            =       true -- derelict
  21. rock_the_vote.  chillout            =       true               
  22. rock_the_vote.  damnation           =       true               
  23. rock_the_vote.  dangercanyon        =       true               
  24. rock_the_vote.  deathisland         =       true           
  25. rock_the_vote.  gephyrophobia       =       true               
  26. rock_the_vote.  hangemhigh          =       true               
  27. rock_the_vote.  icefields           =       true               
  28. rock_the_vote.  infinity            =       true               
  29. rock_the_vote.  longest             =       true               
  30. rock_the_vote.  prisoner            =       true               
  31. rock_the_vote.  putput              =       true -- chiron tl34
  32. rock_the_vote.  ratrace             =       true               
  33. rock_the_vote.  sidewinder          =       true               
  34. rock_the_vote.  timberland          =       true               
  35. rock_the_vote.  wizard              =       true
  36.  
  37. -- Set Map Specific Voting Requirements, expressed in decimal max = 1, min = 0.1  -  % of players or more will allow skipping the current map
  38. -- (higher for your favorite map ,lower for less popular maps)
  39.                 --map                       % Required
  40. rtv_required.   beavercreek         =       0.6 -- battle creek
  41. rtv_required.   bloodgulch          =       0.75               
  42. rtv_required.   boardingaction      =       0.6            
  43. rtv_required.   carousel            =       0.6 -- derelict
  44. rtv_required.   chillout            =       0.6            
  45. rtv_required.   damnation           =       0.6            
  46. rtv_required.   dangercanyon        =       0.75               
  47. rtv_required.   deathisland         =       0.6        
  48. rtv_required.   gephyrophobia       =       0.75               
  49. rtv_required.   hangemhigh          =       0.75               
  50. rtv_required.   icefields           =       0.75           
  51. rtv_required.   infinity            =       0.5            
  52. rtv_required.   longest             =       0.6            
  53. rtv_required.   prisoner            =       0.6            
  54. rtv_required.   putput              =       0.6 -- chiron tl34
  55. rtv_required.   ratrace             =       0.6            
  56. rtv_required.   sidewinder          =       0.75               
  57. rtv_required.   timberland          =       0.75           
  58. rtv_required.   wizard              =       0.6
  59.    
  60. function GetRequiredVersion()
  61.     return 200
  62. end
  63.  
  64. function OnScriptLoad(processId, game, persistent)
  65.     if game == true or game == "PC" then
  66.         GAME = "PC"
  67.         map_name = readstring(0x698F21)
  68.         network_base = 0x745BA8
  69.         cur_players = readword(network_base, 0x1A0)
  70.     else
  71.         GAME = "CE"
  72.         map_name = readstring(0x61D151)
  73.         network_base = 0x6C7988
  74.         cur_players = readword(network_base, 0x1A0)    
  75.     end
  76.     rtv_initiated = 0
  77.     rtv_table = {}
  78.     rock_the_vote = {}
  79. end
  80.  
  81. function OnNewGame(map)
  82.     if GAME == "PC" then
  83.         map_name = readstring(0x698F21)
  84.         network_base = 0x745BA8
  85.         cur_players = readword(network_base, 0x1A0)
  86.     elseif GAME == "CE" then
  87.         map_name = readstring(0x61D151)
  88.         network_base = 0x6C7988
  89.         cur_players = readword(network_base, 0x1A0)
  90.     end
  91.     rtv_initiated = 0
  92.     rtv_table = {}
  93.     rock_the_vote = {}
  94. end
  95.  
  96. function OnGameEnd(stage)
  97.     if stage == 1 then
  98.         if rtvtimer then
  99.             removetimer(rtvtimer)
  100.             rtvtimer = nil
  101.         end
  102.         rtv_initiated = -1
  103.     end
  104. end
  105.  
  106. function OnPlayerJoin(player)
  107.     cur_players = cur_players + 1  
  108. end
  109.  
  110. function OnPlayerLeave(player)
  111.     cur_players = cur_players - 1
  112. end
  113.  
  114. function OnServerChat(player, type, message)
  115.     if player then
  116.         name = getname(player)
  117.         hash = gethash(player)
  118.     end
  119.    
  120.     local t = tokenizestring(message, " ")
  121.     local count = #t
  122.     if t[1] == nil then
  123.         return true
  124.     end
  125.  
  126.     if t[1] == "rtv" then
  127.         if count == 1 and rock_the_vote[map_name] then
  128.             if rtv_initiated >= 0 then
  129.                 local rtv_count = 0
  130.                 local rtv_number = round(cur_players * rtv_required[map_name], 0)
  131.                 for i = 0,15 do
  132.                     if getplayer(i) then
  133.                         if rtv_table[gethash(i)] == 1 then
  134.                             rtv_count = rtv_count + 1
  135.                         end
  136.                     end
  137.                 end
  138.                 if rtv_count == 0 then
  139.                     rtv_initiated = 1
  140.                     rtv_table[hash] = 1
  141.                     rtv_count = rtv_count + 1
  142.                     say(name .. " has initiated Rock-The-Vote (rtv) to skip this map!")
  143.                     say("Type \"rtv\" to join the vote to skip this map.")
  144.                     rtvtimer = registertimer(120000, "rtvTimer")
  145.                 else
  146.                     if rtv_table[hash] == 1 then
  147.                         privatesay(player, "You have already voted for Rock-The-Vote.")
  148.                     elseif rtv_table[hash] == nil then
  149.                         rtv_table[hash] = 1
  150.                         rtv_count = rtv_count + 1
  151.                         say(name .. " has voted for Rock-The-Vote")
  152.                         say(rtv_count .. " of " .. rtv_number .. " votes required for Rock-The-Vote")
  153.                     end
  154.                 end
  155.                 if rtv_count >= rtv_number then
  156.                     removetimer(rtvtimer)
  157.                     rtvtimer = nil
  158.                     rtv_initiated = rtv_timeout
  159.                     say("Enough votes for Rock-The-Vote, skipping to next map.")
  160.                     svcmd("sv_map_next")
  161.                 end
  162.             else
  163.                 privatesay(player, "You cannot initiate Rock-The-Vote at this time")
  164.             end
  165.             return false
  166.         elseif count == 1 and not rock_the_vote[map_name] then
  167.             privatesay(player, "Rock-The-Vote is disabled for this map.")
  168.             return false
  169.         end
  170.     end
  171.    
  172.     return nil
  173. end
  174.  
  175. function rtvTimer(id, count)
  176.     if count == 1 then
  177.         rtv_initiated = rtv_timeout
  178.         rtv_table = {}
  179.         say("The current rtv has expired!")
  180.         return false
  181.     else
  182.         return true
  183.     end
  184. end
  185.  
  186. function round(num)
  187.     under = math.floor(num)
  188.     upper = math.floor(num) + 1
  189.     underV = -(under - num)
  190.     upperV = upper - num
  191.     if (upperV > underV) then
  192.         return under
  193.     else
  194.         return upper
  195.     end
  196. end
  197.  
  198.  
  199. -- Script originated from Wizard and AelitePrime - extracted and adapted as a stand alone feature by H® Shaft
  200. -- Created by H® Shaft thank you to Oxide, AelitePrime, Nugget & Wizard.
  201. -- Visit http://halorace.org/forum/index.php?topic=514.0 or
  202. -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment