Ok, sorry for asking again, but I'm stuck somehow. Here's my code:
at mission start a event calls the following function:
p_InitCloakTimers = function(x)
-- set everything to null
naCloakableShips = {} -- table that contains cloakable ships. Index is the Signature, value is the name
naCloakingTimers = {} -- cloaking timer table. Index is the Signature, value the time when the ship cloaked
naDecloakingTimers = {} -- decloaking timer table. Index is the Signature, value the time when the ship decloaked
naCloakStatus = {} -- Status. 0=visible, 1=cloaking, 2=cloaked, 3=decloaking
--loop through ships, get their names and signatures
for i=1, #mn.Ships do
i_ship = mn.Ships[i]
ishipName = tostring(i_ship.Name)
nshipSig = i_ship:getSignature()
-- if they are cloakable (only Strakha for now) set their status and add them to the CloakableShips list
if (i_ship.Class.Name == "Strakha") then
naCloakableShips[nshipSig] = ishipName
naCloakingTimers[nshipSig] = 0
naDecloakingTimers[nshipSig] = 0
naCloakStatus[nshipSig] = 0
end
end
PlayerCloakable = 1 -- I should rename this variable, it has nothing to do with the player
-- HUD color for player cloaking
orgHUDR, orgHUDG, orgHUDB = hu.getHUDGaugeColor(9) -- get HUD colors on mission start
end
The CloakOrder function triggers the cloaking functions based on the first parameter,
the ship name is the second one. Orders 1 and 3 are called by key-pressed events, and they work.
The other two are triggered OnFrame (see code further below)
p_CloakOrder = function(par_order, nship)
destr = mn.evaluateSEXP("(is-destroyed-delay !0! !".. nship .. "!)")
nshipSig = mn.Ships[nship]:getSignature()
if (not destr) then
if (par_order == 1) then
p_Cloaking(nship)
naCloakingTimers[nshipSig] = mn.getMissionTime()
naCloakStatus[nshipSig] = 1
end
if (par_order == 2) then
p_Cloaked(nship)
naCloakStatus[nshipSig] = 2
end
if (par_order == 3) then
p_Decloaking(nship)
naDecloakingTimers[nshipSig] = mn.getMissionTime()
naCloakStatus[nshipSig] = 3
end
if (par_order == 0) then
p_Decloaked(nship)
naCloakStatus[nshipSig] = 0
end
end
return 0
end
The following function should check whether a ship is cloaking or decloaking for 3 seconds,
change the status to cloaked and trigger the cloak functions 2 and 0. The cloak functions themselves work
$On Frame:
[
if PlayerCloakable == 1 then
-- here I loop through my table of cloakable ships to see whether the cloaking or decloaking timers have reached 3 already
for i_shipSig,i_shipName in pairs(naCloakableShips) do
o_ship = mn.getObjectFromSignature(i_shipSig)
if ((i_shipname ~= nil) and (o_ship:isValid()) and (o_ship:hasShipExploded() == 0)) then
if ((mn.getMissionTime() - naCloakingTimers[i_shipSig]) == 3 and naCloakStatus[i_shipSig] == 1) then
p_CloakOrder(2, i_shipName)
elseif ((mn.getMissionTime() - naDecloakingTimers[i_shipSig]) == 3 and naCloakStatus[i_shipSig] == 3) then
p_CloakOrder(0, i_shipName)
else
end
end
end
end
]
I can't find the error. The ships start cloaking when I press the key, and go to decloaking when I press it again,
but they are never cloaked or decloaked. So they newer reach CloakStatus 0 or 2 again.
So I think the first or last block I posted is the problem.
Take your time, I'll work on my campaign missions in the meantime.