Advertisement
nepphhh

lib.ks

Dec 31st, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. // Activation functions
  2. function ignite {
  3. parameter dub, callback is {}, fail is true.
  4. local pts is ship:partsdubbed(dub).
  5. for p in pts
  6. p:activate.
  7. if pts:length callback(). else if fail tprint( dub + " missing!").
  8. }
  9. function activate {
  10. parameter dub, cmd, callback is {}, fail is true.
  11. local pts is ship:partsdubbed(dub).
  12. for p in pts
  13. for m in p:modules // Finds the right module to run the event you see in the rmb dialogue
  14. if p:getmodule(m):hasevent(cmd) {
  15. p:getmodule(m):doevent(cmd).
  16. break.
  17. }
  18. if pts:length callback(). else if fail tprint( dub + " missing!").
  19. }
  20. function activateRCS {
  21. parameter dub, callback is {}, fail is true.
  22. local pts is ship:partsdubbed(dub).
  23. for p in pts
  24. for m in p:modules // Finds the right module to run the event you see in the rmb dialogue
  25. if p:getmodule(m):hasfield("rcs") {
  26. p:getmodule(m):setfield("rcs", true).
  27. break.
  28. }
  29. if pts:length callback(). else if fail tprint( dub + " missing!").
  30. rcs on.
  31. }
  32. function extinguish {
  33. parameter dub, callback is {}, fail is true.
  34. local pts is ship:partsdubbed(dub).
  35. for p in pts
  36. p:shutdown.
  37. if pts:length callback(). else if fail tprint( dub + " missing!").
  38. }
  39.  
  40. // Vessel check functions
  41. function flameoutCheck {
  42. parameter dub, num is 1.
  43. local out is 0.
  44. for e in ship:partsdubbed(dub) {
  45. // For engines with limited ignitions
  46. if e:getmodule(e:modules[0]):hasfield("ignitions remaining") {
  47. if (e:flameout or (e:ignition = false and e:getmodule(e:modules[0]):getfield("ignitions remaining")=0))
  48. set out to out + 1.
  49. } else if e:flameout set out to out + 1. // All others
  50. }
  51. return (out >= num).
  52. }
  53. function ullageCheck {
  54. parameter dub, num is 1.
  55. local out is 0.
  56. for e in ship:partsdubbed(dub) {
  57. // For engines with limited ignitions
  58. if e:getmodule(e:modules[0]):hasfield("propellant") {
  59. if (not e:flameout and not e:ignition and e:getmodule(e:modules[0]):getfield("propellant")="Very Stable (100.00 %)")
  60. set out to out + 1.
  61. } else if (not e:flameout and not e:ignition) set out to out + 1. // All others
  62. }
  63. return (out >= num).
  64. }
  65. function resourceCheck {
  66. parameter dub, lim.
  67. local resource is 0.
  68. for p in ship:partsdubbed(dub) {
  69. set resource to resource + p:resources[0]:amount.
  70. }
  71. if resource <= lim return resource.
  72. return false.
  73. }
  74. // Meta functions
  75. function loadvessel {
  76. parameter message.
  77. print("Loading...").
  78. wait until ship:loaded.
  79. wait 2.
  80. // Indicate script activated
  81. getvoice(0):PLAY(LIST(
  82. NOTE("A#4", 0.2, 0.25), NOTE("A4", 0.2, 0.25), NOTE("R", 0.2, 0.25),
  83. SLIDENOTE("C5", "F5", 0.45, 0.5), NOTE("R", 0.2, 0.25))).
  84. print(message).
  85. setLaunchTime(false).
  86. when (ship:altitude > 10000 and eta:apoapsis > eta:periapsis) then tprint("Apogee: " + round(ship:altitude/1000, 1) + " km.").
  87. }
  88. function setLaunchTime {
  89. parameter logstarttime is time:seconds.
  90. global tprint is {
  91. parameter text.
  92. if logstarttime {
  93. local t is round(time:seconds-logstarttime, 1).
  94. if t >= 0 print("T+" + t + ": " + text).
  95. else print("T" + t + ": " + text).
  96. }
  97. else print("Pre-launch: " + text).
  98. }.
  99. global getLogStartTime is {
  100. return logstarttime.
  101. }.
  102. }
  103. function finish {
  104. print "Staging complete.". wait 5. print "Shutting down.". shutdown.
  105. }
  106.  
  107. function ignitionfailure {
  108. print "Ignition failure!". wait 5. print "Shutting down.". shutdown.
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement