Advertisement
HR_Shaft

Shields Up! 1.0 for Phasor v2

Nov 21st, 2013
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.83 KB | None | 0 0
  1. --[[ ###    Shields Up!   ###]]--
  2. --[[ ###    by H® Shaft   ###]]--
  3. --[[ ###   for Phasor v2  ###]]--
  4.  
  5. -- enables hog/ghost occupants to to activate a 10 second 'damage shield' by pressing their flashlight key
  6. -- Some portions made by AElitePrime, thanks!
  7.  
  8.  
  9. -- don't edit --
  10. calls, delay, regeneration_time, shield_duration, enable_shield, protected = {}, {}, {}, {}, {}, {}
  11.  
  12. ------ edit below -------
  13.  
  14.     shield_limit = 5    -- | Number of times a player can activate shields during one game.
  15.  
  16. -- Specify the amount of time between shield activations
  17. --                      Map:                        Edit Time(In Seconds):
  18.  
  19. regeneration_time.      beavercreek         =       30      -- battle creek
  20. regeneration_time.      bloodgulch          =       30
  21. regeneration_time.      boardingaction      =       30             
  22. regeneration_time.      carousel            =       30      -- derelict
  23. regeneration_time.      chillout            =       30             
  24. regeneration_time.      damnation           =       30             
  25. regeneration_time.      dangercanyon        =       30             
  26. regeneration_time.      deathisland         =       30         
  27. regeneration_time.      gephyrophobia       =       30             
  28. regeneration_time.      hangemhigh          =       30             
  29. regeneration_time.      icefields           =       30             
  30. regeneration_time.      infinity            =       30             
  31. regeneration_time.      longest             =       30             
  32. regeneration_time.      prisoner            =       30             
  33. regeneration_time.      putput              =       30      -- chiron tl34
  34. regeneration_time.      ratrace             =       30             
  35. regeneration_time.      sidewinder          =       30             
  36. regeneration_time.      timberland          =       30             
  37. regeneration_time.      wizard              =       30
  38. regeneration_time.      Hornets_Nest        =       30
  39. regeneration_time.      Launch_Bay_X        =       30
  40.  
  41. -- Specify the amount of time the shield will last
  42. --                      Map:                        Edit Time(In Seconds):
  43.  
  44. shield_duration.        beavercreek         =       0       -- battle creek
  45. shield_duration.        bloodgulch          =       10
  46. shield_duration.        boardingaction      =       0              
  47. shield_duration.        carousel            =       0       -- derelict
  48. shield_duration.        chillout            =       0              
  49. shield_duration.        damnation           =       0              
  50. shield_duration.        dangercanyon        =       10             
  51. shield_duration.        deathisland         =       10         
  52. shield_duration.        gephyrophobia       =       10             
  53. shield_duration.        hangemhigh          =       0              
  54. shield_duration.        icefields           =       10             
  55. shield_duration.        infinity            =       10             
  56. shield_duration.        longest             =       0              
  57. shield_duration.        prisoner            =       0              
  58. shield_duration.        putput              =       0       -- chiron tl310
  59. shield_duration.        ratrace             =       0              
  60. shield_duration.        sidewinder          =       10             
  61. shield_duration.        timberland          =       10             
  62. shield_duration.        wizard              =       0
  63. shield_duration.        Hornets_Nest        =       10
  64. shield_duration.        Launch_Bay_X        =       10
  65.  
  66. -- If the boolean is true for the map then shields up will be enabled
  67. --                      Map:                        edit boolean
  68.  
  69. enable_shield.          beavercreek         =       false       -- battle creek
  70. enable_shield.          bloodgulch          =       true
  71. enable_shield.          boardingaction      =       false              
  72. enable_shield.          carousel            =       false       -- derelict
  73. enable_shield.          chillout            =       false              
  74. enable_shield.          damnation           =       false              
  75. enable_shield.          dangercanyon        =       true               
  76. enable_shield.          deathisland         =       true           
  77. enable_shield.          gephyrophobia       =       true               
  78. enable_shield.          hangemhigh          =       false              
  79. enable_shield.          icefields           =       true               
  80. enable_shield.          infinity            =       true               
  81. enable_shield.          longest             =       false              
  82. enable_shield.          prisoner            =       false              
  83. enable_shield.          putput              =       false       -- chiron tl3true
  84. enable_shield.          ratrace             =       false              
  85. enable_shield.          sidewinder          =       true               
  86. enable_shield.          timberland          =       true               
  87. enable_shield.          wizard              =       false
  88. enable_shield.          Hornets_Nest        =       true
  89. enable_shield.          Launch_Bay_X        =       true
  90.  
  91. function GetRequiredVersion()
  92.     return 200
  93. end
  94.  
  95. function OnScriptLoad(process, game, persistent)
  96.     if game == "PC" then
  97.         Map = readstring(0x698F21)
  98.         GAME = game
  99.     else
  100.         Map = readstring(0x61D151)
  101.         GAME = game
  102.     end
  103.     for i=0,15 do
  104.         calls[i], delay[i] = 0, 0
  105.     end
  106. end
  107.  
  108. function OnNewGame(map)
  109.     if GAME == "PC" then
  110.         Map = readstring(0x698F21)
  111.     else
  112.         Map = readstring(0x61D151)
  113.     end
  114.     for i=0,15 do
  115.         calls[i], delay[i] = 0, 0
  116.     end
  117. end
  118.  
  119. function OnPlayerJoin(player)
  120.     calls[player], delay[player], protected[player] = 0, 0, false
  121.     registertimer(6000, "timedannounce", player)
  122. end
  123.  
  124. function OnClientUpdate(player)
  125.     if enable_shield[Map] then
  126.         if delay[player] > 0 then delay[player] = delay[player] - 1 end
  127.         local m_playerObjId = getplayerobjectid(player)
  128.         if m_playerObjId and isinvehicle(player) then
  129.             local m_vehicle = getobject(getvehicleobjectid(player))
  130.             if getdriverplayer(m_vehicle) == player and not protected[player] and readbit(getobject(m_playerObjId) + 0x208, 4) then
  131.                 OnShieldsUp(player, m_vehicle)
  132.             elseif getgunnerplayer(m_vehicle) == player and not protected[player] and readbit(getobject(m_playerObjId) + 0x208, 4) then
  133.                 OnShieldsUp(player, m_vehicle)
  134.             elseif getpassengerplayer(m_vehicle) == player and not protected[player] and readbit(getobject(m_playerObjId) + 0x208, 4) then
  135.                 OnShieldsUp(player, m_vehicle)
  136.             end        
  137.         end
  138.     end    
  139. end
  140.  
  141. function OnShieldsUp(player, m_vehicle)
  142.     if getplayer(player) then
  143.         local m_player = getplayer(player)
  144.         if m_player and validvehicle(m_vehicle) then
  145.             if not shield_limit or calls[player] < shield_limit then
  146.                 if (delay[player] or 0) == 0 then
  147.                     local m_objectId = getplayerobjectid(player)
  148.                     if m_objectId then
  149.                         local m_object = getobject(m_objectId)
  150.                         if m_object then
  151.                             if shield_duration[Map] and shield_duration[Map] > 0 then
  152.                                 protected[player] = true
  153.                                 registertimer(shield_duration[Map] * 1000, "RemoveShields", {m_object, player})
  154.                             end
  155.                         end
  156.                     end
  157.                     delay[player] = math.floor(regeneration_time[Map]*30)
  158.                     calls[player] = calls[player] + 1
  159.                     for i=0,15 do
  160.                         if getplayer(i) then
  161.                             sendconsoletext(i, getname(player) .. " activated temporary damage shields.")
  162.                         end
  163.                     end    
  164.                     sendconsoletext(player, "**Shields Up!** You have " .. shield_limit - calls[player] .. " shield calls remaining.")
  165.                 elseif (delay[player] or 0) > 0 then
  166.                     sendconsoletext(player, "Shields regenerating! Not available yet.")
  167.                     if delay[player] > 1 then
  168.                         sendconsoletext(player, "Wait another " .. round((delay[player]/30 or 0)) .. " seconds.")  
  169.                     else
  170.                         sendconsoletext(player, "Wait 1 more second.")  
  171.                     end                
  172.                 end
  173.             else
  174.                 sendconsoletext(player, "**Shields** You have reached the max amount of shield calls for this game.")
  175.             end
  176.         else
  177.             if delay[player] ~= 0 then    
  178.                 delay[player] = 0
  179.             end    
  180.         end
  181.     end
  182. end
  183.  
  184. function RemoveShields(id, count, arg)
  185.     protected[arg[2]] = false
  186.     sendconsoletext(arg[2], "Shield depleted.")
  187.     return false
  188. end
  189.  
  190. function validvehicle(m_vehicle)
  191.     local name = gettaginfo(readdword(m_vehicle))
  192.     if string.find(name, "warthog") or string.find(name, "ghost") then
  193.         return true
  194.     end
  195.     return false
  196. end
  197.  
  198. function OnPlayerLeave(player)
  199.     protected[player] = false
  200. end
  201.  
  202. function OnPlayerKill(killer, victim, mode)
  203.     protected[victim] = false
  204. end
  205.  
  206. function getplayervehicleid(player)
  207.     local m_objectId = getplayerobjectid(player)
  208.     if m_objectId then return readdword(getobject(m_objectId) + 0x11C) end
  209. end
  210.  
  211. function getvehicleobjectid(player)
  212.     local m_objectId = getplayerobjectid(player)
  213.     if m_objectId then return readdword(getobject(m_objectId) + 0x11C) end
  214. end
  215.  
  216. function getdriverplayer(m_vehicle)
  217.     local m_objectId = readdword(m_vehicle + 0x324)
  218.     if m_objectId and m_objectId ~= 0xFFFFFFFF then
  219.         return objectidtoplayer(m_objectId)
  220.     end
  221. end
  222.  
  223. function getgunnerplayer(m_vehicle)
  224.     local m_objectId = readdword(m_vehicle + 0x328)
  225.     if m_objectId and m_objectId ~= 0xFFFFFFFF then
  226.         return objectidtoplayer(m_objectId)
  227.     end
  228. end
  229.  
  230. function getpassengerplayer(m_vehicle)
  231.     local m_objectId = readdword(m_vehicle + 0x32c)
  232.     if m_objectId and m_objectId ~= 0xFFFFFFFF then
  233.         return objectidtoplayer(m_objectId)
  234.     end
  235. end
  236.  
  237. function OnVehicleEntry(player, m_vehicleId, seat, mapid, relevant)
  238.     if seat == 1 and validvehicle(getobject(m_vehicleId)) then
  239.         local player_obj_id = getplayerobjectid(player)
  240.         local m_object = getobject(player_obj_id)
  241.         registertimer(0, "assignpassenger", {player_obj_id, getobject(m_vehicleId)})       
  242.     end
  243.     return nil
  244. end
  245.  
  246. function assignpassenger(id, count, arg)
  247.     writedword(arg[2] + 0x32C, arg[1])
  248.     return false
  249. end
  250.  
  251. function OnVehicleEject(player, relevant)
  252.     if protected[player] then
  253.         protected[player] = false
  254.     end
  255.     return nil
  256. end
  257.  
  258. function timedannounce(id, count, player)
  259.     if getplayer(player) then
  260.         if enable_shield[Map] then sendconsoletext(player, "Shields Up!: Enabled/Flashlight Button activates a temporary damage shield.") end
  261.     end
  262.     return false   
  263. end
  264.  
  265. function OnDamageLookup(receiving, causing, tagid)
  266.     if receiving then
  267.         local r_player = objectidtoplayer(receiving)
  268.         if r_player and isinvehicle(r_player) then
  269.             local m_vehicleId = getplayervehicleid(r_player)
  270.             if m_vehicleId then
  271.                 local m_vehicle = getobject(m_vehicleId)
  272.                 local driver = getdriverplayer(m_vehicle)
  273.                 local gunner = getgunnerplayer(m_vehicle)
  274.                 local passenger = getpassengerplayer(m_vehicle)
  275.                 if driver == r_player and protected[r_player] then
  276.                     return false   
  277.                 end
  278.                 if passenger == r_player and protected[r_player] then
  279.                     return false   
  280.                 end
  281.                 if gunner == r_player and protected[r_player] then
  282.                     return false   
  283.                 end            
  284.             end
  285.         end
  286.     end
  287. end
  288.  
  289. function round(input, precision) -- rounds the number to the specified decimal place
  290.     return math.floor((input * 10^(tonumber(precision) or 0) + 0.5)) / (10^(tonumber(precision) or 0))
  291. end
  292.  
  293. -- Created by H® Shaft thank you to Oxide, AelitePrime, Nugget & Wizard.
  294. -- Visit http://halorace.org/forum/index.php?topic=514.0 or
  295. -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement