montana05 wrote: ↑Sat Aug 15, 2020 11:34 pm
dybal wrote: ↑Wed Aug 05, 2020 4:48 pm
[*]make possible to enable OXP functionality for NPCs, with the user defining if it's enabled or not (has performance and game balance consequences),
A rather silly question Dybal but I admit that I didn't have a look at the code now:
Is it possible to assign the equipment to only specific NPC ships, like with this.ship.awardEquipment on spawn or a ship_script entry ? And if so would it work when the player deactivated NPC's ?
I'm not sure I understood the question, so I will describe what I did and its limitations...
I have a shipSpawned worldScript that is triggered as any ship (what the core game considers a ship) is created. If the ship is NPC and NPC-enable config is true at that time, that script starts a on-time timer of 3 seconds. After those 3 seconds, if the ship has functional Shield Equalizer or Shield Capacitors, it creates several porperties in the ship.script to handle state, hooks the relevant functions into the ship.script and starts a timer bound to the ship script (Shield Equalizer + Capacitors is timer driven).
The 3 second delay in setting things up has two reasons:
- some OXPs set a new script to the ship after it's spawned (EscortdDeck does it to its escorts, for example), so any change I did to the ship.script in shipSpawned might be discarded;
- give time for other OXPs to award the Shield Equalizer and Capacitors equipments to the ship (like ShipVersion) in their on shipSpawned worldScripts.
So:
- the only time my code looks at the NPC-enable configuration setting is at the ship's spawn time;
- if the NPC-enable configuration setting was true at spawn time, at spawn time + 3 seconds my code looks at the ship and if it has he relevant equipments, sets it up.
This OXP doesn't award the equipments to the NPCs, that must be done by other OXPs by their own reasons (and I know of two who do, ShipVersion and Ship Storage Helper on behalf of EscortdDeck), it only ensures (if the configuration is enabling it) that any Shield Equalizer or Shield Capacitor awarded to the NPC ship in its first 3 seconds of existence will be functional.
One possible improvement would be hooking a equipmentAdded event handler to the ship script at spawn time and make that event handler set things up when and if a Equalizer or Capacitors was awarded to the ship... that would remove the timing constraint to the equipment awarding. It would be better as long as no other OXP is hooking its own equipmentAdded event handler to the ship script... if many tried it, it would get messy... There Can Be Only One