Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Activation functions
- function ignite {
- parameter dub, callback is {}, fail is true.
- local pts is ship:partsdubbed(dub).
- for p in pts
- p:activate.
- if pts:length callback(). else if fail tprint( dub + " missing!").
- }
- function activate {
- parameter dub, cmd, callback is {}, fail is true.
- local pts is ship:partsdubbed(dub).
- for p in pts
- for m in p:modules // Finds the right module to run the event you see in the rmb dialogue
- if p:getmodule(m):hasevent(cmd) {
- p:getmodule(m):doevent(cmd).
- break.
- }
- if pts:length callback(). else if fail tprint( dub + " missing!").
- }
- function activateRCS {
- parameter dub, callback is {}, fail is true.
- local pts is ship:partsdubbed(dub).
- for p in pts
- for m in p:modules // Finds the right module to run the event you see in the rmb dialogue
- if p:getmodule(m):hasfield("rcs") {
- p:getmodule(m):setfield("rcs", true).
- break.
- }
- if pts:length callback(). else if fail tprint( dub + " missing!").
- rcs on.
- }
- function extinguish {
- parameter dub, callback is {}, fail is true.
- local pts is ship:partsdubbed(dub).
- for p in pts
- p:shutdown.
- if pts:length callback(). else if fail tprint( dub + " missing!").
- }
- // Vessel check functions
- function flameoutCheck {
- parameter dub, num is 1.
- local out is 0.
- for e in ship:partsdubbed(dub) {
- // For engines with limited ignitions
- if e:getmodule(e:modules[0]):hasfield("ignitions remaining") {
- if (e:flameout or (e:ignition = false and e:getmodule(e:modules[0]):getfield("ignitions remaining")=0))
- set out to out + 1.
- } else if e:flameout set out to out + 1. // All others
- }
- return (out >= num).
- }
- function ullageCheck {
- parameter dub, num is 1.
- local out is 0.
- for e in ship:partsdubbed(dub) {
- // For engines with limited ignitions
- if e:getmodule(e:modules[0]):hasfield("propellant") {
- if (not e:flameout and not e:ignition and e:getmodule(e:modules[0]):getfield("propellant")="Very Stable (100.00 %)")
- set out to out + 1.
- } else if (not e:flameout and not e:ignition) set out to out + 1. // All others
- }
- return (out >= num).
- }
- function resourceCheck {
- parameter dub, lim.
- local resource is 0.
- for p in ship:partsdubbed(dub) {
- set resource to resource + p:resources[0]:amount.
- }
- if resource <= lim return resource.
- return false.
- }
- // Meta functions
- function loadvessel {
- parameter message.
- print("Loading...").
- wait until ship:loaded.
- wait 2.
- // Indicate script activated
- getvoice(0):PLAY(LIST(
- NOTE("A#4", 0.2, 0.25), NOTE("A4", 0.2, 0.25), NOTE("R", 0.2, 0.25),
- SLIDENOTE("C5", "F5", 0.45, 0.5), NOTE("R", 0.2, 0.25))).
- print(message).
- setLaunchTime(false).
- when (ship:altitude > 10000 and eta:apoapsis > eta:periapsis) then tprint("Apogee: " + round(ship:altitude/1000, 1) + " km.").
- }
- function setLaunchTime {
- parameter logstarttime is time:seconds.
- global tprint is {
- parameter text.
- if logstarttime {
- local t is round(time:seconds-logstarttime, 1).
- if t >= 0 print("T+" + t + ": " + text).
- else print("T" + t + ": " + text).
- }
- else print("Pre-launch: " + text).
- }.
- global getLogStartTime is {
- return logstarttime.
- }.
- }
- function finish {
- print "Staging complete.". wait 5. print "Shutting down.". shutdown.
- }
- function ignitionfailure {
- print "Ignition failure!". wait 5. print "Shutting down.". shutdown.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement