Advertisement
HR_Shaft

Vehicle Cloaking for Phasor v2+

Dec 8th, 2014
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.08 KB | None | 0 0
  1. --[[ ###  Vehicle Cloaking  ###]]--
  2. --[[ ###     by H® Shaft    ###]]--
  3. --[[ ###    for Phasor v2   ###]]--
  4.  
  5. -- PC and CE Version 12/8/2014  
  6.  
  7. -- Enables DRIVERS (only) of hog/ghost/tank to to activate a 10 second (editable default) 'cloaking device' by pressing their CROUCH key.
  8. -- Players in cloaked vehicles are also cloaked and can still take damage.
  9. -- Gunners and Passengers are notified when driver activates the cloaking device.
  10.  
  11. -- You can edit these values below differently for PER MAP name (map file name):
  12. -- cloak_limit:         | Number of times a player can activate cloaking device during one game. (default: 3)
  13. -- regeneration time:   | Specify the amount of time (in seconds) between cloak activations. (default: 60 seconds)
  14. -- cloak_duration:      | Specify the amount of time (in seconds) the cloak will last. (default: 10 seconds)
  15. -- enable_cloak:        | Enable (true) or Disable (false) the cloaking device for the specified map. (default: enabled all on outdoor maps)
  16.  
  17. -- Want Shields too?? (activated by flashlight key), see my other script: "Shields Up!" Link: http://pastebin.com/U7t5x55f
  18.  
  19. ---- don't edit this section below ----
  20. calls, delay, regeneration_time, cloak_duration, enable_cloak, cloaked, hails, crouch, crouch_time, game_started = {}, {}, {}, {}, {}, {}, {}, {}, 2, false
  21. ---- don't edit this section above ----
  22.  
  23. --================ EDIT VALUES BELOW THIS LINE ========================
  24.  
  25. cloak_limit = 3     -- | Number of times a player can activate cloaking device during one game.
  26.  
  27. -- Specify the amount of time between cloak activations
  28. --                      Map:                        Edit Time(In Seconds):
  29.  
  30. regeneration_time.      beavercreek         =       60      -- battle creek
  31. regeneration_time.      bloodgulch          =       60
  32. regeneration_time.      boardingaction      =       60             
  33. regeneration_time.      carousel            =       60      -- derelict
  34. regeneration_time.      chillout            =       60             
  35. regeneration_time.      damnation           =       60             
  36. regeneration_time.      dangercanyon        =       60             
  37. regeneration_time.      deathisland         =       60         
  38. regeneration_time.      gephyrophobia       =       60             
  39. regeneration_time.      hangemhigh          =       60             
  40. regeneration_time.      icefields           =       60             
  41. regeneration_time.      infinity            =       60             
  42. regeneration_time.      longest             =       60             
  43. regeneration_time.      prisoner            =       60             
  44. regeneration_time.      putput              =       60      -- chiron tl34
  45. regeneration_time.      ratrace             =       60             
  46. regeneration_time.      sidewinder          =       60             
  47. regeneration_time.      timberland          =       60             
  48. regeneration_time.      wizard              =       60
  49.  
  50. -- Specify the amount of time the cloak will last
  51. --                      Map:                        Edit Time(In Seconds):
  52.  
  53. cloak_duration.     beavercreek         =       0       -- battle creek
  54. cloak_duration.     bloodgulch          =       10
  55. cloak_duration.     boardingaction      =       0              
  56. cloak_duration.     carousel            =       0       -- derelict
  57. cloak_duration.     chillout            =       0              
  58. cloak_duration.     damnation           =       0              
  59. cloak_duration.     dangercanyon        =       10             
  60. cloak_duration.     deathisland         =       10         
  61. cloak_duration.     gephyrophobia       =       10             
  62. cloak_duration.     hangemhigh          =       0              
  63. cloak_duration.     icefields           =       10             
  64. cloak_duration.     infinity            =       10             
  65. cloak_duration.     longest             =       0              
  66. cloak_duration.     prisoner            =       0              
  67. cloak_duration.     putput              =       0       -- chiron tl310
  68. cloak_duration.     ratrace             =       0              
  69. cloak_duration.     sidewinder          =       10             
  70. cloak_duration.     timberland          =       10             
  71. cloak_duration.     wizard              =       0
  72.  
  73. -- If the boolean is true for the map then cloak up will be enabled
  74. --                      Map:                        edit boolean
  75.  
  76. enable_cloak.           beavercreek         =       false       -- battle creek
  77. enable_cloak.           bloodgulch          =       true
  78. enable_cloak.           boardingaction      =       false              
  79. enable_cloak.           carousel            =       false       -- derelict
  80. enable_cloak.           chillout            =       false              
  81. enable_cloak.           damnation           =       false              
  82. enable_cloak.           dangercanyon        =       true               
  83. enable_cloak.           deathisland         =       true           
  84. enable_cloak.           gephyrophobia       =       true               
  85. enable_cloak.           hangemhigh          =       false              
  86. enable_cloak.           icefields           =       true               
  87. enable_cloak.           infinity            =       true               
  88. enable_cloak.           longest             =       false              
  89. enable_cloak.           prisoner            =       false              
  90. enable_cloak.           putput              =       false       -- chiron tl3true
  91. enable_cloak.           ratrace             =       false              
  92. enable_cloak.           sidewinder          =       true               
  93. enable_cloak.           timberland          =       true               
  94. enable_cloak.           wizard              =       false
  95.  
  96. --================ EDIT VALUES ABOVE THIS LINE ========================
  97.  
  98. function GetRequiredVersion()
  99.     return 200
  100. end
  101.  
  102. function OnScriptLoad(process, game, persistent)
  103.     if game == "PC" then
  104.         Map = readstring(0x698F21)
  105.     else
  106.         Map = readstring(0x61D151)
  107.     end
  108.     GAME = game
  109.     for i=0,15 do
  110.         calls[i], delay[i], hails[i], cloaked[i] = 0, 0, 0, false
  111.     end
  112.     game_started = true
  113.     cloak = registertimer(20, "Cloak") 
  114. end
  115.  
  116. function OnNewGame(map)
  117.     if GAME == "PC" then
  118.         Map = readstring(0x698F21)
  119.     else
  120.         Map = readstring(0x61D151)
  121.     end
  122.     for i=0,15 do
  123.         calls[i], delay[i], hails[i], cloaked[i] = 0, 0, 0, false
  124.     end
  125.     game_started = true
  126. end
  127.  
  128. function OnPlayerJoin(player)
  129.     if getplayer(player) then
  130.         calls[player], delay[player], hails[player], cloaked[player] = 0, 0, 0, false
  131.         announce = registertimer(20000, "timedannounce", player)
  132.     end
  133. end
  134.  
  135. function OnGameEnd(stage)
  136.     if stage == 1 then
  137.         game_started = false
  138.         if announce then
  139.             announce = nil
  140.         end
  141.         if passenger then
  142.             passenger = nil
  143.         end
  144.         if removeshields then
  145.             removeshields = nil
  146.         end                
  147.     end
  148. end
  149.  
  150. function OnClientUpdate(player)
  151.     if enable_cloak[Map] then
  152.         if delay[player] > 0 then delay[player] = delay[player] - 1 end
  153.         if hails[player] > 0 then hails[player] = hails[player] - 1 end
  154.         local m_playerObjId = getplayerobjectid(player)
  155.         if m_playerObjId and isinvehicle(player) then
  156.             local m_vehicle = getobject(getvehicleobjectid(player))
  157.             local obj_crouch = readbit(getobject(m_playerObjId) + 0x208, 0)
  158.             local id = resolveplayer(player)
  159.             if obj_crouch and crouch[id] == nil then
  160.                 crouch[id] = ActivateCloak(player, m_vehicle)
  161.             elseif obj_crouch ~= 0 and crouch[id] ~= nil then
  162.                 crouch[id] = nil
  163.             end        
  164.         end    
  165.     end    
  166. end
  167.  
  168. function ActivateCloak(player, m_vehicle)
  169.     if getplayer(player) and game_started then
  170.         if hails[player] == 0 then
  171.             local m_player = getplayer(player)
  172.             if validvehicle(m_vehicle) then
  173.                 if not cloak_limit or calls[player] < cloak_limit then
  174.                     if (delay[player] or 0) == 0 then
  175.                         local m_objectId = getplayerobjectid(player)
  176.                         if m_objectId then
  177.                             local m_object = getobject(m_objectId)
  178.                             if m_object then
  179.                                 if cloak_duration[Map] and cloak_duration[Map] > 0 then
  180.                                     cloaked[player] = true
  181.                                     removecloak = registertimer(cloak_duration[Map] * 1000, "RemoveCloak", {m_object, player})
  182.                                     hails[player] = (crouch_time*30)
  183.                                 end
  184.                             end
  185.                         end
  186.                         delay[player] = math.floor(regeneration_time[Map]*30)
  187.                         calls[player] = calls[player] + 1
  188.                         for i=0,15 do
  189.                             if getplayer(i) then
  190.                                 privatesay(i, getname(player) .. " activated a temporary cloaking device!")
  191.                             end
  192.                         end    
  193.                         sendconsoletext(player, "**Cloak Activated!** You have " .. cloak_limit - calls[player] .. " cloak activations remaining.", 6, 0)
  194.                         sendconsoletext(getgunnerplayer(m_vehicle), "Your driver has activated the cloaking device!, Hang on!", 4, 0)
  195.                         sendconsoletext(getpassengerplayer(m_vehicle), "Your driver has activated the cloaking device!, Hang on!", 4, 0)                       
  196.                     elseif (delay[player] or 0) > 0 then
  197.                         sendconsoletext(player, "**Cloak Regenerating!** Not available yet!")
  198.                         if delay[player] > 1 then
  199.                             sendconsoletext(player, "Wait another " .. round((delay[player]/30 or 0)) .. " seconds.")  
  200.                         else
  201.                             sendconsoletext(player, "Wait 1 more second.")  
  202.                         end                
  203.                     end
  204.                 else
  205.                     sendconsoletext(player, "**Cloaking Device** You've reached the max cloak activations for this game.")
  206.                 end
  207.             else
  208.                 sendconsoletext(player, "**Cloaking Device** Cloaking device not valid for this vehicle!")
  209.                 if delay[player] ~= 0 then    
  210.                     delay[player] = 0
  211.                 end    
  212.             end
  213.         end
  214.     end
  215. end
  216.  
  217. function Cloak(id, count)
  218.     for i = 0,15 do            
  219.         if getplayer(i) and cloaked[i] and game_started then
  220.             if isinvehicle(i) then
  221.                 local m_player = getplayer(i)
  222.                 local z = readfloat(m_player + 0x100)
  223.                 writefloat(m_player + 0x100, z - 1000) 
  224.             end    
  225.         end
  226.     end
  227.     return true
  228. end
  229.  
  230. function RemoveCloak(id, count, arg)
  231.     cloaked[arg[2]] = false
  232.     sendconsoletext(arg[2], "Cloaking Device depleted!", 8, 0)
  233.     return false
  234. end
  235.  
  236. function validvehicle(m_vehicle)
  237.     local name = gettaginfo(readdword(m_vehicle))
  238.     if string.find(name, "warthog") or string.find(name, "ghost") or string.find(name, "scorpion") then
  239.         return true
  240.     end
  241.     return false
  242. end
  243.  
  244. function OnPlayerLeave(player)
  245.     if getplayer(player) then
  246.         cloaked[player] = false
  247.     end
  248. end
  249.  
  250. function OnPlayerKill(killer, victim, mode)
  251.     if getplayer(victim) then
  252.         cloaked[victim] = false
  253.     end
  254. end
  255.  
  256. function getplayervehicleid(player)
  257.     local m_objectId = getplayerobjectid(player)
  258.     if m_objectId then return readdword(getobject(m_objectId) + 0x11C) end
  259. end
  260.  
  261. function getvehicleobjectid(player)
  262.     local m_objectId = getplayerobjectid(player)
  263.     if m_objectId then return readdword(getobject(m_objectId) + 0x11C) end
  264. end
  265.  
  266. function getdriverplayer(m_vehicle)
  267.     local m_objectId = readdword(m_vehicle + 0x324)
  268.     if m_objectId and m_objectId ~= 0xFFFFFFFF then
  269.         return objectidtoplayer(m_objectId)
  270.     end
  271. end
  272.  
  273. function getgunnerplayer(m_vehicle)
  274.     local m_objectId = readdword(m_vehicle + 0x328)
  275.     if m_objectId and m_objectId ~= 0xFFFFFFFF then
  276.         return objectidtoplayer(m_objectId)
  277.     end
  278. end
  279.  
  280. function getpassengerplayer(m_vehicle)
  281.     local m_objectId = readdword(m_vehicle + 0x32c)
  282.     if m_objectId and m_objectId ~= 0xFFFFFFFF then
  283.         return objectidtoplayer(m_objectId)
  284.     end
  285. end
  286.  
  287. function OnVehicleEntry(player, m_vehicleId, seat, mapid, relevant)
  288.     if getplayer(player) then
  289.         if seat == 1 and validvehicle(getobject(m_vehicleId)) then
  290.             local player_obj_id = getplayerobjectid(player)
  291.             passenger = registertimer(0, "assignpassenger", {player_obj_id, getobject(m_vehicleId)})
  292.         elseif seat == 0 and validvehicle(getobject(m_vehicleId)) then
  293.             sendconsoletext(player, "Driver: Crouch Button activates a temporary Cloaking Device.", 8, 0)
  294.         end
  295.     end
  296.     return nil
  297. end
  298.  
  299. function assignpassenger(id, count, arg)
  300.     writedword(arg[2] + 0x32C, arg[1])
  301.     return false
  302. end
  303.  
  304. function OnVehicleEject(player, relevant)
  305.     if cloaked[player] then
  306.         cloaked[player] = false
  307.     end
  308.     return nil
  309. end
  310.  
  311. function timedannounce(id, count, player)
  312.     if getplayer(player) then
  313.         if enable_cloak[Map] then
  314.             sendconsoletext(player, "Drivers Only! Crouch Button activates a temporary Cloaking Device!", 8, 0)
  315.             sendconsoletext(player, "by H\174  Shaft", 8, 0)
  316.         end
  317.     end
  318.     return false   
  319. end
  320.  
  321. function round(input, precision) -- rounds the number to the specified decimal place
  322.     return math.floor((input * 10^(tonumber(precision) or 0) + 0.5)) / (10^(tonumber(precision) or 0))
  323. end
  324.  
  325. -- Start sendconsoletext overloaded by Nugget
  326. console = {}
  327. console.__index = console
  328. consoletimer = registertimer(100, "ConsoleTimer")
  329. phasor_sendconsoletext = sendconsoletext
  330.  
  331. function sendconsoletext(player, message, time, order, align, height, func)
  332.     if player then
  333.         console[player] = console[player] or {}
  334.         local temp = {}
  335.         temp.player = player
  336.         temp.id = nextid(player, order)
  337.         temp.message = message or ""
  338.         temp.time = time or 0.7
  339.         temp.remain = temp.time
  340.         temp.align = align or "left"
  341.         temp.height = height or 0
  342.         if type(func) == "function" then
  343.             temp.func = func
  344.         elseif type(func) == "string" then
  345.             temp.func = _G[func]
  346.         end
  347.         console[player][temp.id] = temp
  348.         setmetatable(console[player][temp.id], console)
  349.         return console[player][temp.id]
  350.     end
  351. end
  352.  
  353. function nextid(player, order)
  354.     if not order then
  355.         local x = 0
  356.         for k,v in pairs(console[player]) do
  357.             if k > x + 1 then
  358.                 return x + 1
  359.             end
  360.             x = x + 1
  361.         end
  362.         return x + 1
  363.     else
  364.         local original = order
  365.         while console[player][order] do
  366.             order = order + 0.001
  367.             if order == original + 0.999 then break end
  368.         end
  369.         return order
  370.     end
  371. end
  372.  
  373. function getmessage(player, order)
  374.     if console[player] then
  375.         if order then
  376.             return console[player][order]
  377.         end
  378.     end
  379. end
  380.  
  381. function getmessages(player)
  382.     return console[player]
  383. end
  384.  
  385. function getmessageblock(player, order)
  386.     local temp = {}
  387.     for k,v in opairs(console[player]) do
  388.         if k >= order and k < order + 1 then
  389.             table.insert(temp, console[player][k])
  390.         end
  391.     end
  392.     return temp
  393. end
  394.  
  395. function console:getmessage()
  396.     return self.message
  397. end
  398.  
  399. function console:append(message, reset)
  400.     if console[self.player] then
  401.         if console[self.player][self.id] then
  402.             if getplayer(self.player) then
  403.                 if reset then
  404.                     if reset == true then
  405.                         console[self.player][self.id].remain = console[self.player][self.id].time
  406.                     elseif tonumber(reset) then
  407.                         console[self.player][self.id].time = tonumber(reset)
  408.                         console[self.player][self.id].remain = tonumber(reset)
  409.                     end
  410.                 end
  411.                 console[self.player][self.id].message = message or ""
  412.                 return true
  413.             end
  414.         end
  415.     end
  416. end
  417.  
  418. function console:shift(order)
  419.     local temp = console[self.player][self.id]
  420.     console[self.player][self.id] = console[self.player][order]
  421.     console[self.player][order] = temp
  422. end
  423.  
  424. function console:pause(time)
  425.     console[self.player][self.id].pausetime = time or 5
  426. end
  427.  
  428. function console:delete()
  429.     console[self.player][self.id] = nil
  430. end
  431.  
  432. function ConsoleTimer(id, count)
  433.     for i,_ in opairs(console) do
  434.         if tonumber(i) then
  435.             if getplayer(i) then
  436.                 for k,v in opairs(console[i]) do
  437.                     if console[i][k].pausetime then
  438.                         console[i][k].pausetime = console[i][k].pausetime - 0.1
  439.                         if console[i][k].pausetime <= 0 then
  440.                             console[i][k].pausetime = nil
  441.                         end
  442.                     else
  443.                         if console[i][k].func then
  444.                             if not console[i][k].func(i) then
  445.                                 console[i][k] = nil
  446.                             end
  447.                         end
  448.                         if console[i][k] then
  449.                             console[i][k].remain = console[i][k].remain - 0.1
  450.                             if console[i][k].remain <= 0 then
  451.                                 console[i][k] = nil
  452.                             end
  453.                         end
  454.                     end
  455.                 end
  456.                 if table.len(console[i]) > 0 then
  457.                     local paused = 0
  458.                     for k,v in pairs(console[i]) do
  459.                         if console[i][k].pausetime then
  460.                             paused = paused + 1
  461.                         end
  462.                     end
  463.                     if paused < table.len(console[i]) then
  464.                         local str = ""
  465.                         for i = 0,30 do
  466.                             str = str .. " \n"
  467.                         end
  468.                         phasor_sendconsoletext(i, str)
  469.                         for k,v in opairs(console[i]) do
  470.                             if not console[i][k].pausetime then
  471.                                 if console[i][k].align == "right" or console[i][k].align == "center" then
  472.                                     phasor_sendconsoletext(i, consolecenter(string.sub(console[i][k].message, 1, 78)))
  473.                                 else
  474.                                     phasor_sendconsoletext(i, string.sub(console[i][k].message, 1, 78))
  475.                                 end
  476.                             end
  477.                         end
  478.                     end
  479.                 end
  480.             else
  481.                 console[i] = nil
  482.             end
  483.         end
  484.     end
  485.    
  486.     return true
  487. end
  488.  
  489. function consolecenter(text)
  490.     if text then
  491.         local len = string.len(text)
  492.         for i = len + 1, 78 do
  493.             text = " " .. text
  494.         end
  495.         return text
  496.     end
  497. end
  498.  
  499. function opairs(t)
  500.     local keys = {}
  501.     for k,v in pairs(t) do
  502.         table.insert(keys, k)
  503.     end    
  504.     table.sort(keys,
  505.     function(a,b)
  506.         if type(a) == "number" and type(b) == "number" then
  507.             return a < b
  508.         end
  509.         an = string.lower(tostring(a))
  510.         bn = string.lower(tostring(b))
  511.         if an ~= bn then
  512.             return an < bn
  513.         else
  514.             return tostring(a) < tostring(b)
  515.         end
  516.     end)
  517.     local count = 1
  518.     return function()
  519.         if table.unpack(keys) then
  520.             local key = keys[count]
  521.             local value = t[key]
  522.             count = count + 1
  523.             return key,value
  524.         end
  525.     end
  526. end
  527.  
  528. function table.len(t)
  529.     local count = 0
  530.     for k,v in pairs(t) do
  531.         count = count + 1
  532.     end
  533.     return count
  534. end
  535. -- Stop sendconsoletext overloaded
  536.  
  537. -- Created by H® Shaft.
  538. -- Thanks to Oxide, AelitePrime, Nugget & Wizard - and 002!
  539. -- Visit http://halorace.org/forum/index.php?topic=514.0 or
  540. -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement