Ok, most stuff is working now. I had a bit of trouble running SEXPs but the forum search helped me. I never would have guesses it is the "!". The exclamation mark is hardcoded in my brain as a negation already because it is the same in almost every programming language. And of course it isn't the negation in LUA as I had to learn....
Anyway, here's my next question: Admiral MS, you were talking about a LUA delay function or something.
I searched for "delay", "sleep", and "wait" (those are the most common names for such a function in script languages) in the LUA documentation but couldn't find it yet. Can anyone point me to an example?
For those interested in my cloaking script here it is how it looks now:
in the mission there are four events that trigger the "p_CloakOrder" function and keep track of the cloaking status. The player can't cloak or decloak more often than every 5 seconds (because the cloaking and decloaking animations take three seconds), that is done by the events at the moment. The whole other stuff is done by the script below.
I'm using a ghost named cloak_ghost in the mission to store the player's damage. Is there a more elegant way?
-- ------------------------ Cloaking -----------------------------
p_CloakOrder = function(par_order)
playerShip = hv.Player
if (par_order == 1) then
p_Cloaking(0)
end
if (par_order == 2) then
p_Cloaked(0)
end
if (par_order == 3) then
p_Decloaking(0)
end
if (par_order == 0) then
p_Decloaked(0)
end
return 0
end
p_Cloaking = function(x)
mn.runSEXP("play-sound-from-table !0 !0 !0 !144")
orgWeapClass = playerShip.SecondaryBanks[1].WeaponClass.Name
orgAmmo = playerShip.SecondaryBanks[1].AmmoLeft
orgEnergy = playerShip.WeaponEnergyLeft
mn.runSEXP("ship-copy-damage !" .. tostring(playerShip.Name) .. "! !cloak_ghost!")
mn.runSEXP("change-ship-class !Strakha#Cloak! !".. tostring(playerShip.Name) .. "!")
mn.runSEXP("ship-copy-damage !cloak_ghost! !" .. tostring(playerShip.Name) .. "!")
playerShip.SecondaryBanks[1].WeaponClass = tb.WeaponClasses[orgWeapClass]
playerShip.SecondaryBanks[1].AmmoLeft = orgAmmo
playerShip.WeaponEnergyLeft = orgEnergy
mn.runSEXP("lock-primary-weapon !" .. tostring(playerShip.Name) .. "!")
mn.runSEXP("lock-secondary-weapon !" .. tostring(playerShip.Name) .. "!")
mn.runSEXP("hud-set-text !Cinfo! ! Cloaking!")
return 0
end
p_Cloaked = function(x)
orgWeapClass = playerShip.SecondaryBanks[1].WeaponClass.Name
orgAmmo = playerShip.SecondaryBanks[1].AmmoLeft
orgEnergy = playerShip.WeaponEnergyLeft
mn.runSEXP("ship-copy-damage !" .. tostring(playerShip.Name) .. "! !cloak_ghost!")
mn.runSEXP("change-ship-class !Strakha#Inv! !".. tostring(playerShip.Name) .. "!")
mn.runSEXP("ship-copy-damage !cloak_ghost! !" .. tostring(playerShip.Name) .. "!")
playerShip.SecondaryBanks[1].WeaponClass = tb.WeaponClasses[orgWeapClass]
playerShip.SecondaryBanks[1].AmmoLeft = orgAmmo
playerShip.WeaponEnergyLeft = orgEnergy
mn.runSEXP("protect-ship !" .. tostring(playerShip.Name) .. "!")
mn.runSEXP("hud-set-text !Cinfo! ! Cloaked!")
return 0
end
p_Decloaking = function(x)
mn.runSEXP("play-sound-from-table !0 !0 !0 !145")
orgWeapClass = playerShip.SecondaryBanks[1].WeaponClass.Name
orgAmmo = playerShip.SecondaryBanks[1].AmmoLeft
orgEnergy = playerShip.WeaponEnergyLeft
mn.runSEXP("ship-copy-damage !" .. tostring(playerShip.Name) .. "! !cloak_ghost!")
mn.runSEXP("change-ship-class !Strakha#Decloak! !".. tostring(playerShip.Name) .. "!")
mn.runSEXP("ship-copy-damage !cloak_ghost! !" .. tostring(playerShip.Name) .. "!")
playerShip.SecondaryBanks[1].WeaponClass = tb.WeaponClasses[orgWeapClass]
playerShip.SecondaryBanks[1].AmmoLeft = orgAmmo
playerShip.WeaponEnergyLeft = orgEnergy
mn.runSEXP("hud-set-text !Cinfo! ! Decloaking!")
return 0
end
p_Decloaked = function(x)
orgWeapClass = playerShip.SecondaryBanks[1].WeaponClass.Name
orgAmmo = playerShip.SecondaryBanks[1].AmmoLeft
orgEnergy = playerShip.WeaponEnergyLeft
mn.runSEXP("ship-copy-damage !" .. tostring(playerShip.Name) .. "! !cloak_ghost!")
mn.runSEXP("change-ship-class !Strakha! !".. tostring(playerShip.Name) .. "!")
mn.runSEXP("ship-copy-damage !cloak_ghost! !" .. tostring(playerShip.Name) .. "!")
playerShip.SecondaryBanks[1].WeaponClass = tb.WeaponClasses[orgWeapClass]
playerShip.SecondaryBanks[1].AmmoLeft = orgAmmo
playerShip.WeaponEnergyLeft = orgEnergy
mn.runSEXP("unlock-primary-weapon !" .. tostring(playerShip.Name) .. "!")
mn.runSEXP("unlock-secondary-weapon !" .. tostring(playerShip.Name) .. "!")
mn.runSEXP("unprotect-ship !" .. tostring(playerShip.Name) .. "!")
mn.runSEXP("hud-set-text !Cinfo! ! Visible!")
return 0
end
-- ---------------------------------------------------------------