Author Topic: Any script to disable all engines on all ships?  (Read 2064 times)

Offline ChronowerX_GT

  • ChronowerX Productions - Founder
  • Posts: 809
  • Cookies: 36
    • ChronowerX Productions
Any script to disable all engines on all ships?
« on: June 19, 2008, 12:33:18 PM »
I've been trying various fleet shots using the "Edit ()" command but when I exit it and go back to normal QB all the ships fly off into different positions. To stop this i've been transporting to every ship and manually disableing the engines but with 20 ships in the map it takes quite a while. Is there any script avaliable that allows me to destroy every engine in the map, without visable damage, by just clicking on a button? Or how would I go about creating one? Thanks.


Having a smoking section in a restaurant is kinda like having a peeing section in a pool...

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: Any script to disable all engines on all ships?
« Reply #1 on: June 19, 2008, 12:40:03 PM »
Stick this in a file you can easily remember (in scripts/):

Code: [Select]
import App

def disableAllEngines():
  pPlayer = App.Game_GetCurrentPlayer()
  pSet = pPlayer.GetContainingSet()
  ObjTuple = pSet.GetClassObjectList(App.CT_SHIP)
  if ObjTuple:
    for pShip in ObjTuple:
      if pShip:
        pShip.ClearAI()

What this actually does, is making the ships not think (including the player), so they also won't fire weapons.
If you need that, then that's also possible through scripts.


Then, in the console:
Code: [Select]
from <<YourChosenNameHere>> import *And then you can do:
Code: [Select]
disableAllEngines()
Also, this script assumes the player ship is in the set which contains all the ships you want to disable engines for.
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: Any script to disable all engines on all ships?
« Reply #2 on: June 19, 2008, 01:18:22 PM »
As for the button:
Code: [Select]
import App
# if you have scripts\Lib\LibEngineering.py(c)
import Lib.LibEngineering
def init():
Lib.LibEngineering.CreateMenuButton("The name of your button", "Tactical", __name__ + ".disableAllEngines")

# else (i dont' know if it is part of stock bc):
def init():
pTacticalControlWindow = App.TacticalControlWindow_GetTacticalControlWindow()
if not pTacticalControlWindow:
print "Error: No Tactical Control Window"
return None
pDatabase = App.g_kLocalizationManager.Load("data/TGL/Bridge Menus.tgl")
pMenu = pTacticalControlWindow.FindMenu(pDatabase.GetString("Tactical"))
App.g_kLocalizationManager.Unload(pDatabase)
ET_EVENT = App.Mission_GetNextEventType()

pMenu.AddPythonFuncHandlerForInstance(ET_EVENT, __name__ + ".disableAllEngines")

pEvent = App.TGIntEvent_Create()
pEvent.SetEventType(ET_EVENT)
pEvent.SetDestination(pMenu)
pEvent.SetInt(EventInt)
pButton = App.STButton_CreateW(App.TGString("The name of your button"), pEvent)

pMenu.PrependChild(pButton)
# in both cases:
def disableAllEngines(pObject, pEvent):
pPlayer = App.Game_GetCurrentPlayer()
pSet = pPlayer.GetContainingSet()
ObjTuple = pSet.GetClassObjectList(App.CT_SHIP)
if ObjTuple:
for pShip in ObjTuple:
if pShip:
pShip.ClearAI()
pObject.CallNextHandler(pEvent)

you do the same as MLeo said only that you type into the console
Code: [Select]
init()instead of
Code: [Select]
from <<YourChosenNameHere>> import *
If you have QBautostart installed place the script into scripts/Custom/QBautostart and the button wil be loaded automatically when you start QB.

NOTE: the code in the second init method is a copy of some code in LibEngineering so I'm not the autor, i only changed some variables!

Offline ChronowerX_GT

  • ChronowerX Productions - Founder
  • Posts: 809
  • Cookies: 36
    • ChronowerX Productions
Re: Any script to disable all engines on all ships?
« Reply #3 on: June 19, 2008, 01:29:49 PM »
Great, thanks a lot. I'll try them out as soon as I get on my desktop.


Having a smoking section in a restaurant is kinda like having a peeing section in a pool...

Offline ChronowerX_GT

  • ChronowerX Productions - Founder
  • Posts: 809
  • Cookies: 36
    • ChronowerX Productions
Re: Any script to disable all engines on all ships?
« Reply #4 on: June 19, 2008, 03:14:02 PM »
Thanks guys, the script worked great. Just what I wanted. Since the thread's served it purpouse i'll lock it.


Having a smoking section in a restaurant is kinda like having a peeing section in a pool...