Author Topic: Making a specific weapon fire ONLY when you set full power to weapons?  (Read 506 times)

Offline Flowrellik

  • Posts: 154
  • Cookies: 7
I had an idea in mind ship HPwise where certain ships can fire a secret weapon by means of setting full power to weapons, but I wonder, has this ever been done before and how?

Offline KrrKs

  • Posts: 461
  • Cookies: 25
Re: Making a specific weapon fire ONLY when you set full power to weapons?
« Reply #1 on: October 30, 2017, 09:17:37 AM »
I don't remember encountering such a mechanic.
But I also don't quite remember how the power mechanics work; Does it only alter the recharge/reload rate of weapons or also the max charge?

If it is the latter, it would be enough to set the normal maxcharge for e.g., a pulse weapon 25% (or 20% or whatever) below the discharge rate (or what it is called).

If it is the former, a little script would need to check the power distribution and set e.g., the maxcharge depending on that.

Offline KrrKs

  • Posts: 461
  • Cookies: 25
Re: Making a specific weapon fire ONLY when you set full power to weapons?
« Reply #2 on: October 30, 2017, 05:31:14 PM »
double post, yay  :smack

Of course it was not the easy way, what was i thinking...
It took me way too long to get back into the BC and python way to do things, but I came up with a little working example. It is still missing stuff to check whether the player is actually in a ship equipped with the subsystem in question, or if the script should run depending on playership.


Code: [Select]
import App
import MissionLib

#Global Variables
pSubsystemName = "Fwd Torpedo" #Name of the Subsystem
percentageThreshhold = 1.20 #At which point should the system become active, 1.2 means 120%

isDisabled = 1 #Tracker to dis/re -enable the subsystem

def init():
#init function - I'm probably missing stuff to check whether the player was reset or changed ships and similar
pPlayer = MissionLib.GetPlayer()
pSubsystemProperty = MissionLib.GetSubsystemByName(pPlayer, pSubsystemName).GetProperty()

# Set the subsystem disabled for now
pSubsystemProperty.SetDisabledPercentage(100.0)
isDisabled = 1

pPlayer.AddPythonFuncHandlerForInstance(App.ET_SUBSYSTEM_POWER_CHANGED, __name__ + ".PowerChanged")

def PowerChanged(pObject, pEvent):
global isDisabled
#Some power level changed

pSubsystem = MissionLib.GetSubsystemByName(MissionLib.GetPlayer(), pSubsystemName)
fPercentage = -1

try:
# We need to find the Parent i.e., the Pulse or Torpedo system of the actual launcher to get the power levels...
# There *should* be an easier way, but I don't know it
pParentSubsystem = pSubsystem.GetParentSubsystem()
try:
PoweredSubsystem = App.PoweredSubsystem_Cast(pParentSubsystem)
if PoweredSubsystem is None:
print "Parent to ", pSubsystemName, " is None!"
return
else:
fPercentage = PoweredSubsystem.GetPowerPercentageWanted()

except:
print "Something went awfully wrong"
except:
print "No ParentSystem to ", pSubsystemName


# if the powerlevel is higher than our threshold and the subsystem in question was disabled, enable the subsystem again
if fPercentage >= percentageThreshhold and isDisabled:
pSubsystem.GetProperty().SetDisabledPercentage(0.0)
isDisabled = 0
print "Enabling System"

# if the powerlevel in question is lower than our threshold and the system was enabled, disable it again
elif fPercentage < percentageThreshhold and not isDisabled:
pSubsystem.GetProperty().SetDisabledPercentage(100.0)
isDisabled = 1
print "Disabling System"

Offline Morgan

  • Moderator
  • Posts: 1340
  • Cookies: 65535
Re: Making a specific weapon fire ONLY when you set full power to weapons?
« Reply #3 on: November 01, 2017, 11:48:54 AM »
Considering the way BC's weapon system is coded I'm not sure it's possible in the way that you're looking for.  However, in Advanced Power Control you can simply kill power to the individual weapons you don't want to fire, and leave only the ones you want.  I imagine you could just save a configuration where certain weapons are off and others are on, and you could just switch between the two that way.  :idk: