Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ ### Vehicle Cloaking ###]]--
- --[[ ### by H® Shaft ###]]--
- --[[ ### for Phasor v2 ###]]--
- -- PC and CE Version 12/8/2014
- -- Enables DRIVERS (only) of hog/ghost/tank to to activate a 10 second (editable default) 'cloaking device' by pressing their CROUCH key.
- -- Players in cloaked vehicles are also cloaked and can still take damage.
- -- Gunners and Passengers are notified when driver activates the cloaking device.
- -- You can edit these values below differently for PER MAP name (map file name):
- -- cloak_limit: | Number of times a player can activate cloaking device during one game. (default: 3)
- -- regeneration time: | Specify the amount of time (in seconds) between cloak activations. (default: 60 seconds)
- -- cloak_duration: | Specify the amount of time (in seconds) the cloak will last. (default: 10 seconds)
- -- enable_cloak: | Enable (true) or Disable (false) the cloaking device for the specified map. (default: enabled all on outdoor maps)
- -- Want Shields too?? (activated by flashlight key), see my other script: "Shields Up!" Link: http://pastebin.com/U7t5x55f
- ---- don't edit this section below ----
- calls, delay, regeneration_time, cloak_duration, enable_cloak, cloaked, hails, crouch, crouch_time, game_started = {}, {}, {}, {}, {}, {}, {}, {}, 2, false
- ---- don't edit this section above ----
- --================ EDIT VALUES BELOW THIS LINE ========================
- cloak_limit = 3 -- | Number of times a player can activate cloaking device during one game.
- -- Specify the amount of time between cloak activations
- -- Map: Edit Time(In Seconds):
- regeneration_time. beavercreek = 60 -- battle creek
- regeneration_time. bloodgulch = 60
- regeneration_time. boardingaction = 60
- regeneration_time. carousel = 60 -- derelict
- regeneration_time. chillout = 60
- regeneration_time. damnation = 60
- regeneration_time. dangercanyon = 60
- regeneration_time. deathisland = 60
- regeneration_time. gephyrophobia = 60
- regeneration_time. hangemhigh = 60
- regeneration_time. icefields = 60
- regeneration_time. infinity = 60
- regeneration_time. longest = 60
- regeneration_time. prisoner = 60
- regeneration_time. putput = 60 -- chiron tl34
- regeneration_time. ratrace = 60
- regeneration_time. sidewinder = 60
- regeneration_time. timberland = 60
- regeneration_time. wizard = 60
- -- Specify the amount of time the cloak will last
- -- Map: Edit Time(In Seconds):
- cloak_duration. beavercreek = 0 -- battle creek
- cloak_duration. bloodgulch = 10
- cloak_duration. boardingaction = 0
- cloak_duration. carousel = 0 -- derelict
- cloak_duration. chillout = 0
- cloak_duration. damnation = 0
- cloak_duration. dangercanyon = 10
- cloak_duration. deathisland = 10
- cloak_duration. gephyrophobia = 10
- cloak_duration. hangemhigh = 0
- cloak_duration. icefields = 10
- cloak_duration. infinity = 10
- cloak_duration. longest = 0
- cloak_duration. prisoner = 0
- cloak_duration. putput = 0 -- chiron tl310
- cloak_duration. ratrace = 0
- cloak_duration. sidewinder = 10
- cloak_duration. timberland = 10
- cloak_duration. wizard = 0
- -- If the boolean is true for the map then cloak up will be enabled
- -- Map: edit boolean
- enable_cloak. beavercreek = false -- battle creek
- enable_cloak. bloodgulch = true
- enable_cloak. boardingaction = false
- enable_cloak. carousel = false -- derelict
- enable_cloak. chillout = false
- enable_cloak. damnation = false
- enable_cloak. dangercanyon = true
- enable_cloak. deathisland = true
- enable_cloak. gephyrophobia = true
- enable_cloak. hangemhigh = false
- enable_cloak. icefields = true
- enable_cloak. infinity = true
- enable_cloak. longest = false
- enable_cloak. prisoner = false
- enable_cloak. putput = false -- chiron tl3true
- enable_cloak. ratrace = false
- enable_cloak. sidewinder = true
- enable_cloak. timberland = true
- enable_cloak. wizard = false
- --================ EDIT VALUES ABOVE THIS LINE ========================
- function GetRequiredVersion()
- return 200
- end
- function OnScriptLoad(process, game, persistent)
- if game == "PC" then
- Map = readstring(0x698F21)
- else
- Map = readstring(0x61D151)
- end
- GAME = game
- for i=0,15 do
- calls[i], delay[i], hails[i], cloaked[i] = 0, 0, 0, false
- end
- game_started = true
- cloak = registertimer(20, "Cloak")
- end
- function OnNewGame(map)
- if GAME == "PC" then
- Map = readstring(0x698F21)
- else
- Map = readstring(0x61D151)
- end
- for i=0,15 do
- calls[i], delay[i], hails[i], cloaked[i] = 0, 0, 0, false
- end
- game_started = true
- end
- function OnPlayerJoin(player)
- if getplayer(player) then
- calls[player], delay[player], hails[player], cloaked[player] = 0, 0, 0, false
- announce = registertimer(20000, "timedannounce", player)
- end
- end
- function OnGameEnd(stage)
- if stage == 1 then
- game_started = false
- if announce then
- announce = nil
- end
- if passenger then
- passenger = nil
- end
- if removeshields then
- removeshields = nil
- end
- end
- end
- function OnClientUpdate(player)
- if enable_cloak[Map] then
- if delay[player] > 0 then delay[player] = delay[player] - 1 end
- if hails[player] > 0 then hails[player] = hails[player] - 1 end
- local m_playerObjId = getplayerobjectid(player)
- if m_playerObjId and isinvehicle(player) then
- local m_vehicle = getobject(getvehicleobjectid(player))
- local obj_crouch = readbit(getobject(m_playerObjId) + 0x208, 0)
- local id = resolveplayer(player)
- if obj_crouch and crouch[id] == nil then
- crouch[id] = ActivateCloak(player, m_vehicle)
- elseif obj_crouch ~= 0 and crouch[id] ~= nil then
- crouch[id] = nil
- end
- end
- end
- end
- function ActivateCloak(player, m_vehicle)
- if getplayer(player) and game_started then
- if hails[player] == 0 then
- local m_player = getplayer(player)
- if validvehicle(m_vehicle) then
- if not cloak_limit or calls[player] < cloak_limit then
- if (delay[player] or 0) == 0 then
- local m_objectId = getplayerobjectid(player)
- if m_objectId then
- local m_object = getobject(m_objectId)
- if m_object then
- if cloak_duration[Map] and cloak_duration[Map] > 0 then
- cloaked[player] = true
- removecloak = registertimer(cloak_duration[Map] * 1000, "RemoveCloak", {m_object, player})
- hails[player] = (crouch_time*30)
- end
- end
- end
- delay[player] = math.floor(regeneration_time[Map]*30)
- calls[player] = calls[player] + 1
- for i=0,15 do
- if getplayer(i) then
- privatesay(i, getname(player) .. " activated a temporary cloaking device!")
- end
- end
- sendconsoletext(player, "**Cloak Activated!** You have " .. cloak_limit - calls[player] .. " cloak activations remaining.", 6, 0)
- sendconsoletext(getgunnerplayer(m_vehicle), "Your driver has activated the cloaking device!, Hang on!", 4, 0)
- sendconsoletext(getpassengerplayer(m_vehicle), "Your driver has activated the cloaking device!, Hang on!", 4, 0)
- elseif (delay[player] or 0) > 0 then
- sendconsoletext(player, "**Cloak Regenerating!** Not available yet!")
- if delay[player] > 1 then
- sendconsoletext(player, "Wait another " .. round((delay[player]/30 or 0)) .. " seconds.")
- else
- sendconsoletext(player, "Wait 1 more second.")
- end
- end
- else
- sendconsoletext(player, "**Cloaking Device** You've reached the max cloak activations for this game.")
- end
- else
- sendconsoletext(player, "**Cloaking Device** Cloaking device not valid for this vehicle!")
- if delay[player] ~= 0 then
- delay[player] = 0
- end
- end
- end
- end
- end
- function Cloak(id, count)
- for i = 0,15 do
- if getplayer(i) and cloaked[i] and game_started then
- if isinvehicle(i) then
- local m_player = getplayer(i)
- local z = readfloat(m_player + 0x100)
- writefloat(m_player + 0x100, z - 1000)
- end
- end
- end
- return true
- end
- function RemoveCloak(id, count, arg)
- cloaked[arg[2]] = false
- sendconsoletext(arg[2], "Cloaking Device depleted!", 8, 0)
- return false
- end
- function validvehicle(m_vehicle)
- local name = gettaginfo(readdword(m_vehicle))
- if string.find(name, "warthog") or string.find(name, "ghost") or string.find(name, "scorpion") then
- return true
- end
- return false
- end
- function OnPlayerLeave(player)
- if getplayer(player) then
- cloaked[player] = false
- end
- end
- function OnPlayerKill(killer, victim, mode)
- if getplayer(victim) then
- cloaked[victim] = false
- end
- end
- function getplayervehicleid(player)
- local m_objectId = getplayerobjectid(player)
- if m_objectId then return readdword(getobject(m_objectId) + 0x11C) end
- end
- function getvehicleobjectid(player)
- local m_objectId = getplayerobjectid(player)
- if m_objectId then return readdword(getobject(m_objectId) + 0x11C) end
- end
- function getdriverplayer(m_vehicle)
- local m_objectId = readdword(m_vehicle + 0x324)
- if m_objectId and m_objectId ~= 0xFFFFFFFF then
- return objectidtoplayer(m_objectId)
- end
- end
- function getgunnerplayer(m_vehicle)
- local m_objectId = readdword(m_vehicle + 0x328)
- if m_objectId and m_objectId ~= 0xFFFFFFFF then
- return objectidtoplayer(m_objectId)
- end
- end
- function getpassengerplayer(m_vehicle)
- local m_objectId = readdword(m_vehicle + 0x32c)
- if m_objectId and m_objectId ~= 0xFFFFFFFF then
- return objectidtoplayer(m_objectId)
- end
- end
- function OnVehicleEntry(player, m_vehicleId, seat, mapid, relevant)
- if getplayer(player) then
- if seat == 1 and validvehicle(getobject(m_vehicleId)) then
- local player_obj_id = getplayerobjectid(player)
- passenger = registertimer(0, "assignpassenger", {player_obj_id, getobject(m_vehicleId)})
- elseif seat == 0 and validvehicle(getobject(m_vehicleId)) then
- sendconsoletext(player, "Driver: Crouch Button activates a temporary Cloaking Device.", 8, 0)
- end
- end
- return nil
- end
- function assignpassenger(id, count, arg)
- writedword(arg[2] + 0x32C, arg[1])
- return false
- end
- function OnVehicleEject(player, relevant)
- if cloaked[player] then
- cloaked[player] = false
- end
- return nil
- end
- function timedannounce(id, count, player)
- if getplayer(player) then
- if enable_cloak[Map] then
- sendconsoletext(player, "Drivers Only! Crouch Button activates a temporary Cloaking Device!", 8, 0)
- sendconsoletext(player, "by H\174 Shaft", 8, 0)
- end
- end
- return false
- end
- function round(input, precision) -- rounds the number to the specified decimal place
- return math.floor((input * 10^(tonumber(precision) or 0) + 0.5)) / (10^(tonumber(precision) or 0))
- end
- -- Start sendconsoletext overloaded by Nugget
- console = {}
- console.__index = console
- consoletimer = registertimer(100, "ConsoleTimer")
- phasor_sendconsoletext = sendconsoletext
- function sendconsoletext(player, message, time, order, align, height, func)
- if player then
- console[player] = console[player] or {}
- local temp = {}
- temp.player = player
- temp.id = nextid(player, order)
- temp.message = message or ""
- temp.time = time or 0.7
- temp.remain = temp.time
- temp.align = align or "left"
- temp.height = height or 0
- if type(func) == "function" then
- temp.func = func
- elseif type(func) == "string" then
- temp.func = _G[func]
- end
- console[player][temp.id] = temp
- setmetatable(console[player][temp.id], console)
- return console[player][temp.id]
- end
- end
- function nextid(player, order)
- if not order then
- local x = 0
- for k,v in pairs(console[player]) do
- if k > x + 1 then
- return x + 1
- end
- x = x + 1
- end
- return x + 1
- else
- local original = order
- while console[player][order] do
- order = order + 0.001
- if order == original + 0.999 then break end
- end
- return order
- end
- end
- function getmessage(player, order)
- if console[player] then
- if order then
- return console[player][order]
- end
- end
- end
- function getmessages(player)
- return console[player]
- end
- function getmessageblock(player, order)
- local temp = {}
- for k,v in opairs(console[player]) do
- if k >= order and k < order + 1 then
- table.insert(temp, console[player][k])
- end
- end
- return temp
- end
- function console:getmessage()
- return self.message
- end
- function console:append(message, reset)
- if console[self.player] then
- if console[self.player][self.id] then
- if getplayer(self.player) then
- if reset then
- if reset == true then
- console[self.player][self.id].remain = console[self.player][self.id].time
- elseif tonumber(reset) then
- console[self.player][self.id].time = tonumber(reset)
- console[self.player][self.id].remain = tonumber(reset)
- end
- end
- console[self.player][self.id].message = message or ""
- return true
- end
- end
- end
- end
- function console:shift(order)
- local temp = console[self.player][self.id]
- console[self.player][self.id] = console[self.player][order]
- console[self.player][order] = temp
- end
- function console:pause(time)
- console[self.player][self.id].pausetime = time or 5
- end
- function console:delete()
- console[self.player][self.id] = nil
- end
- function ConsoleTimer(id, count)
- for i,_ in opairs(console) do
- if tonumber(i) then
- if getplayer(i) then
- for k,v in opairs(console[i]) do
- if console[i][k].pausetime then
- console[i][k].pausetime = console[i][k].pausetime - 0.1
- if console[i][k].pausetime <= 0 then
- console[i][k].pausetime = nil
- end
- else
- if console[i][k].func then
- if not console[i][k].func(i) then
- console[i][k] = nil
- end
- end
- if console[i][k] then
- console[i][k].remain = console[i][k].remain - 0.1
- if console[i][k].remain <= 0 then
- console[i][k] = nil
- end
- end
- end
- end
- if table.len(console[i]) > 0 then
- local paused = 0
- for k,v in pairs(console[i]) do
- if console[i][k].pausetime then
- paused = paused + 1
- end
- end
- if paused < table.len(console[i]) then
- local str = ""
- for i = 0,30 do
- str = str .. " \n"
- end
- phasor_sendconsoletext(i, str)
- for k,v in opairs(console[i]) do
- if not console[i][k].pausetime then
- if console[i][k].align == "right" or console[i][k].align == "center" then
- phasor_sendconsoletext(i, consolecenter(string.sub(console[i][k].message, 1, 78)))
- else
- phasor_sendconsoletext(i, string.sub(console[i][k].message, 1, 78))
- end
- end
- end
- end
- end
- else
- console[i] = nil
- end
- end
- end
- return true
- end
- function consolecenter(text)
- if text then
- local len = string.len(text)
- for i = len + 1, 78 do
- text = " " .. text
- end
- return text
- end
- end
- function opairs(t)
- local keys = {}
- for k,v in pairs(t) do
- table.insert(keys, k)
- end
- table.sort(keys,
- function(a,b)
- if type(a) == "number" and type(b) == "number" then
- return a < b
- end
- an = string.lower(tostring(a))
- bn = string.lower(tostring(b))
- if an ~= bn then
- return an < bn
- else
- return tostring(a) < tostring(b)
- end
- end)
- local count = 1
- return function()
- if table.unpack(keys) then
- local key = keys[count]
- local value = t[key]
- count = count + 1
- return key,value
- end
- end
- end
- function table.len(t)
- local count = 0
- for k,v in pairs(t) do
- count = count + 1
- end
- return count
- end
- -- Stop sendconsoletext overloaded
- -- Created by H® Shaft.
- -- Thanks to Oxide, AelitePrime, Nugget & Wizard - and 002!
- -- Visit http://halorace.org/forum/index.php?topic=514.0 or
- -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement