FreeSpace Releases > Scripting Releases

Simple script to automatically shut off engine glows

(1/3) > >>

xenocartographer:
Have you ever looked at a docked ship and wonder why the crew always forgets to turn off the engine? disabled an Orion or manually SEXP'd off thruster bank 'cause man, that can't be good for the Ganymede it's parked in? marveled at Alpha wing standing still in space even though there's clearly reaction mass pouring out of the back in complete violation of Newtonian mechanics, as if these vessels are flown not by mere mortals but something perhaps divine, perhaps profane, and inhuman thing deserving of awe and trembling?

Well, no more! The days of idling ships rendering completely redundant thruster glows are OVER!




--- Code: ---#Conditional Hooks

$Application: FS2_Open

$On Game Init: [
   ThrusterCache = {}
   THRUSTER_ACTIVE_THRESHOLD = .01
]

$On Mission Start: [
   ThrusterCache = {}
]

$State: GS_STATE_GAME_PLAY
$On Frame: [
   local numShips = #mn.Ships
   for i=1, numShips do
      local ship = mn.Ships[i]
      if ship:isValid() then
         local signature = ship:getSignature()
         local thrust = ship.Physics.ForwardThrust
         local engines = (thrust > THRUSTER_ACTIVE_THRESHOLD)
         if engines ~= ThrusterCache[signature] then
            mn.runSEXP("(set-thrusters-status !" .. tostring(engines) .. "! !" .. ship.Name .. "!)")
            ThrusterCache[signature] = engines
         end
      end
   end
]

#End

--- End code ---

AdmiralRalwood:
Hmm. This looks like it executes mn.runSEXP() per ship per frame, which strikes me as... sub-optimal. I'm not sure what the performance savings would be, but I'd try implementing an engine status cache and only executing mn.runSEXP() when the engine status changes.

xenocartographer:
It does and I'd considered that. A'ight, sec.

Aaaaaaand updated. Turns out Physics handles actually have an entry for forward thrust, so that's cool (...but makes the script look a whole lot less clever :P ).

Nightstorm:
Hi there.  This is pretty cool, I was wondering if you could modify it to also turn off the glow points too.  In Diaspora it kills the engine glow but your engines stay lit up when they really shouldn't be if the throttle is at zero.

Thanks!

m!m:
I noticed a small bug in how you use the cache index. You use the iteration index as an index for the cache but the iteration index is not guaranteed to always refer to the same ship. Instead you should use the signature of the object (it can be retrieved using getSignature) for the cache which will make sure that you always use the correct value for every ship.

Navigation

[0] Message Index

[#] Next page

Go to full version