[WIP] NPC Equipment Damage
Moderators: winston, another_commander
-
- Competent
- Posts: 58
- Joined: Mon Mar 02, 2015 2:08 pm
- Location: drifting in remLock mask near Vezadi Station
[WIP] NPC Equipment Damage
Allows NPC equipment to be damaged in combat.
Download from Elite Wiki. (version 0.2.1, with more bug fixes (see below))
Compatible with N-Shields and Ship Configuration. Probably won't work with CustomShields or NPC Shields. OXP equipment can add its own handlers to a list if it needs to de-activate scripts etc when damaged.
Download from Elite Wiki. (version 0.2.1, with more bug fixes (see below))
Compatible with N-Shields and Ship Configuration. Probably won't work with CustomShields or NPC Shields. OXP equipment can add its own handlers to a list if it needs to de-activate scripts etc when damaged.
Last edited by Ngalo on Tue Jun 14, 2016 1:15 pm, edited 3 times in total.
Equal Rights for NPCs!
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: [WIP] NPC Equipment Damage
I like this very much!
After having a bit of a look at the code, I think for better compatibility in future releases I need to make the $awaitEquipmentDamaged routine in ShipConfig accept a ship as a parameter, and thereby making it available to be used for NPC's. That should streamline your job of applying equipment breakage for ShipConfig equipment items to NPC's. I think I'll be able to squeeze that into the next release.
Edit: Actually, I'm going to attach $awaitEquipmentDamaged to the "script" property of the player ship, meaning that all the ship references in the routine will become "this.ship" and it can therefore be applied to any other ship.
After having a bit of a look at the code, I think for better compatibility in future releases I need to make the $awaitEquipmentDamaged routine in ShipConfig accept a ship as a parameter, and thereby making it available to be used for NPC's. That should streamline your job of applying equipment breakage for ShipConfig equipment items to NPC's. I think I'll be able to squeeze that into the next release.
Edit: Actually, I'm going to attach $awaitEquipmentDamaged to the "script" property of the player ship, meaning that all the ship references in the routine will become "this.ship" and it can therefore be applied to any other ship.
Last edited by phkb on Wed May 11, 2016 3:32 am, edited 1 time in total.
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: [WIP] NPC Equipment Damage
A couple of bugs:The way you have "quantity" specified JS is turning it into a variable, rather than using it as a property. Just remove the "[" and "]" from around the name and it should be good to go. Same goes for "commodity" 2 lines later.
Next one:With this one, I think you need to change this:To this:Because "h" is already the item in the array.
One more:In this case I think your should just change "append" for "push".
Code: Select all
12:41:10.286 [script.javaScript.exception.notDefined]: ***** JavaScript exception (upsScavenger 1.0): ReferenceError: quantity is not defined
12:41:10.286 [script.javaScript.exception.notDefined]: ../AddOns/Testing.oxp/NPC_Equipment_Damage.oxz/Scripts/NPC_Equipment_Damage.js, line 62.
Next one:
Code: Select all
12:42:30.629 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (griff_spawn_wreckage 1.1): TypeError: handlers[h] is undefined
12:42:30.630 [script.javaScript.exception.unexpectedType]: ../AddOns/Testing.oxp/NPC_Equipment_Damage.oxz/Scripts/NPC_Equipment_Damage.js, line 108.
Code: Select all
for (h in handlers)
{
handlers[h].apply(ship.script, [eq.equipmentKey]);
}
Code: Select all
for (h in handlers)
{
if (typeof h == "function") h.apply(ship.script, [eq.equipmentKey]);
}
One more:
Code: Select all
13:10:33.559 [script.javaScript.exception.notFunction]: ***** JavaScript exception (oolite-default-ship-script 1.82): TypeError: cargopods.append is not a function
13:10:33.559 [script.javaScript.exception.notFunction]: ../AddOns/Testing.oxp/NPC_Equipment_Damage.oxp/Scripts/NPC_Equipment_Damage.js, line 64.
- Norby
- ---- E L I T E ----
- Posts: 2577
- Joined: Mon May 20, 2013 9:53 pm
- Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
- Contact:
Re: [WIP] NPC Equipment Damage
Hi Ngalo!
First of all I like your new addons, the codes inside looks like skillfull works. I hope you will be persistent enough to make a few more versions to reach enough stable stages.
I got many lines into my log, too much to quote, please check it here. Most of the 7000 lines in a 10 min session is "calling internal dmg", the game was frozen without any new frame displayed for more seconds while several hundreds of these are generated. I never seen similar long stops so far, so you produced something unique.
Ship script is terminated due to timeLimit during these times. Don't worry, I think you can solve it, or feel free to ask.
First of all I like your new addons, the codes inside looks like skillfull works. I hope you will be persistent enough to make a few more versions to reach enough stable stages.
I got many lines into my log, too much to quote, please check it here. Most of the 7000 lines in a 10 min session is "calling internal dmg", the game was frozen without any new frame displayed for more seconds while several hundreds of these are generated. I never seen similar long stops so far, so you produced something unique.
Ship script is terminated due to timeLimit during these times. Don't worry, I think you can solve it, or feel free to ask.
-
- Competent
- Posts: 58
- Joined: Mon Mar 02, 2015 2:08 pm
- Location: drifting in remLock mask near Vezadi Station
Re: [WIP] NPC Equipment Damage
Thanks for all your bug-finding help with this and N-Shields. I think I have now (0.1.1) fixed everything except the 'handlers[h] undefined' bug. I've left that one because debug-console experimentation shows that, although what you suggested would be right in Python, it apparently isn't in JS:
Therefore I don't know what's actually wrong and am not going to break it further by attempting a fix while thus ignorant.
Code: Select all
> for (i in ["spam", "eggs", "ni", "foo", "bar"]){log("item: ", i)}
0
1
2
3
4
Equal Rights for NPCs!
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: [WIP] NPC Equipment Damage
I'm not sure if this is correct or not, but anyway...
I'm noticing that the script is damaging the same items over and over again on the same ship, as evidenced by this log extract:
I'm noticing that the script is damaging the same items over and over again on the same ship, as evidenced by this log extract:
The poor energy bank got damaged 4 times within the space of a second! Is the damaging routine checking if the equipment is already damaged, or is it competing with ShipConfig's process of restoring equipment if the ship has armour?13:43:03.684 [NPC_Equipment_Damage]: damaging EQ_HEAT_SINK on Gnat: Fletcher's Skull
13:43:03.789 [NPC_Equipment_Damage]: damaging EQ_ENERGYBANK_TYPE5 on Gnat: Fletcher's Skull
13:43:03.953 [NPC_Equipment_Damage]: damaging EQ_FUEL_SCOOPS on Gnat: Fletcher's Skull
13:43:04.246 [NPC_Equipment_Damage]: damaging EQ_ENERGYBANK_TYPE5 on Gnat: Fletcher's Skull
13:43:04.368 [NPC_Equipment_Damage]: damaging EQ_THRUSTERS_TYPE2A on Gnat: Fletcher's Skull
13:43:04.476 [NPC_Equipment_Damage]: damaging EQ_AFT_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:04.834 [NPC_Equipment_Damage]: damaging EQ_AFT_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:05.060 [NPC_Equipment_Damage]: damaging EQ_HEAT_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:08.032 [NPC_Equipment_Damage]: damaging EQ_FORWARD_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:08.175 [NPC_Equipment_Damage]: damaging EQ_HYPERDRIVE_TYPE2 on Gnat: Fletcher's Skull
13:43:08.364 [NPC_Equipment_Damage]: damaging EQ_ENERGYBANK_TYPE5 on Gnat: Fletcher's Skull
13:43:08.476 [NPC_Equipment_Damage]: damaging EQ_HEAT_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:08.571 [NPC_Equipment_Damage]: damaging EQ_HEAT_SHIELD_TYPE2 on Fer-de-Lance: Rachael
13:43:08.699 [NPC_Equipment_Damage]: damaging EQ_AFT_SHIELD_TYPE2 on Fer-de-Lance: Rachael
13:43:08.743 [NPC_Equipment_Damage]: damaging EQ_THRUSTERS_TYPE2A on Gnat: Fletcher's Skull
13:43:08.799 [NPC_Equipment_Damage]: damaging EQ_FUEL_SCOOPS on Gnat: Fletcher's Skull
13:43:08.930 [NPC_Equipment_Damage]: damaging EQ_AFT_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:09.022 [NPC_Equipment_Damage]: damaging EQ_THRUSTERS_TYPE2A on Gnat: Fletcher's Skull
13:43:09.126 [NPC_Equipment_Damage]: damaging EQ_THRUSTERS_TYPE2A on Gnat: Fletcher's Skull
13:43:09.984 [NPC_Equipment_Damage]: damaging EQ_ENERGYBANK_TYPE5 on Gnat: Fletcher's Skull
13:43:10.103 [NPC_Equipment_Damage]: damaging EQ_HYPERDRIVE_TYPE2 on Gnat: Fletcher's Skull
13:43:10.230 [NPC_Equipment_Damage]: damaging EQ_FORWARD_SHIELD_TYPE2 on Gnat: Fletcher's Skull
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: [WIP] NPC Equipment Damage
I'm also seeing this in my log file:
Code: Select all
<<snip 30 other lines of "damaging [equipment_item] on GalCop Viper Interceptor >>
14:21:36.146 [NPC_Equipment_Damage]: damaging EQ_FUEL_INJECTION_TYPE2 on GalCop Viper Interceptor: KPL581-DI6
14:21:36.169 [script.javaScript.timeLimit]: ***** ERROR: Script "griff_spawn_wreckage" ran for 1.12141 seconds and has been terminated.
14:21:36.169 [script.javaScript.stackTrace]: 0 (NPC_Equipment_Damage.js:77) <anonymous function>
14:21:36.169 [script.javaScript.stackTrace]: this: [Script "NPC_Equipment_Damage" version 0.1.1]
14:21:36.169 [script.javaScript.stackTrace]: ship: [Ship "GalCop Viper Interceptor" position: (56387.9, 60499.5, 744699) scanClass: CLASS_POLICE status: STATUS_IN_FLIGHT]
14:21:36.169 [script.javaScript.stackTrace]: handlers: undefined
14:21:36.169 [script.javaScript.stackTrace]: accumulator: undefined
14:21:36.169 [script.javaScript.stackTrace]: target: undefined
14:21:36.169 [script.javaScript.stackTrace]: eq: [EquipmentInfo EQ_THRUSTERS_TYPE2C "Manoeuvring Thrusters Class 2C"]
14:21:36.169 [script.javaScript.stackTrace]: damageableOdds: 1
14:21:36.169 [script.javaScript.stackTrace]: damageableCounter: 1
14:21:36.169 [script.javaScript.stackTrace]: i: "5"
14:21:36.169 [script.javaScript.stackTrace]: cargopods: []
14:21:36.169 [script.javaScript.stackTrace]: damage_to: 2.52182734375
14:21:36.169 [script.javaScript.stackTrace]: n_considered: 3.52182734375
14:21:36.169 [script.javaScript.stackTrace]: n_mass: 3.52182734375
14:21:36.169 [script.javaScript.stackTrace]: n_cargo: 0
14:21:36.169 [script.javaScript.stackTrace]: 1 (NPC_Equipment_Damage.js:44) <anonymous function>
14:21:36.169 [script.javaScript.stackTrace]: this: [Script "griff_spawn_wreckage" version 1.1]
14:21:36.169 [script.javaScript.stackTrace]: type: "scrape damage"
14:21:36.169 [script.javaScript.stackTrace]: whom: [Ship "Navigation Buoy" position: (56363.1, 60473.3, 744739) scanClass: CLASS_BUOY status: STATUS_IN_FLIGHT]
14:21:36.169 [script.javaScript.stackTrace]: amount: 18694.5703125
14:21:36.169 [script.javaScript.stackTrace]: internal_damage: true
14:21:36.169 [script.javaScript.stackTrace]: 2 (N-Shields.js:777) <anonymous function>
14:21:36.169 [script.javaScript.stackTrace]: this: [Script "NShields" version 0.6.2]
14:21:36.170 [script.javaScript.stackTrace]: type: "scrape damage"
14:21:36.170 [script.javaScript.stackTrace]: whom: [Ship "Navigation Buoy" position: (56363.1, 60473.3, 744739) scanClass: CLASS_BUOY status: STATUS_IN_FLIGHT]
14:21:36.170 [script.javaScript.stackTrace]: amount: 19686.5703125
14:21:36.170 [script.javaScript.stackTrace]: ship: [Ship "GalCop Viper Interceptor" position: (56387.9, 60499.5, 744699) scanClass: CLASS_POLICE status: STATUS_IN_FLIGHT]
14:21:36.170 [script.javaScript.stackTrace]: 3 (N-Shields.js:472) <anonymous function>
14:21:36.170 [script.javaScript.stackTrace]: this: [Script "griff_spawn_wreckage" version 1.1]
14:21:36.170 [script.javaScript.stackTrace]: caller: undefined
14:21:36.170 [script.javaScript.stackTrace]: type: "scrape damage"
14:21:36.170 [script.javaScript.stackTrace]: whom: [Ship "Navigation Buoy" position: (56363.1, 60473.3, 744739) scanClass: CLASS_BUOY status: STATUS_IN_FLIGHT]
14:21:36.170 [script.javaScript.stackTrace]: amount: 19814.5703125
14:21:36.170 [script.javaScript.stackTrace]: hitLocationRelative: (-26.0033, -16.9483, 24.8363)
14:21:36.170 [script.javaScript.stackTrace]: hitLocation: (56361.9, 60482.6, 744724)
-
- Competent
- Posts: 58
- Joined: Mon Mar 02, 2015 2:08 pm
- Location: drifting in remLock mask near Vezadi Station
Re: [WIP] NPC Equipment Damage
Version 0.2 is now out with improved Ship Configuration compatibility and an attempt to fix the issue with the same equipment getting damaged multiple times (due to not checking whether it was already damaged, although I'm not sure I've corrected it in an entirely fair manner).
Equal Rights for NPCs!
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: [WIP] NPC Equipment Damage
Still seeing this in my log file occasionally:Other issues appear to be fixed, though.
Code: Select all
12:48:33.015 [script.javaScript.timeLimit]: ***** ERROR: Script "griff_cobra_III_(alt)_externalMissiles.js" ran for 1.14818 seconds and has been terminated.
12:48:33.015 [script.javaScript.stackTrace]: 0 (NPC_Equipment_Damage.js:84) <anonymous function>
12:48:33.015 [script.javaScript.stackTrace]: this: [Script "NPC_Equipment_Damage" version 0.2]
12:48:33.015 [script.javaScript.stackTrace]: ship: [Ship "Cobra Mark III" position: (-41597.4, 15340.7, 349765) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
12:48:33.015 [script.javaScript.stackTrace]: handlers: undefined
12:48:33.015 [script.javaScript.stackTrace]: accumulator: undefined
12:48:33.015 [script.javaScript.stackTrace]: target: undefined
12:48:33.016 [script.javaScript.stackTrace]: eq: [EquipmentInfo EQ_ENGINE_COUPLING_TYPE2 "Engine Power Coupling Class 2"]
12:48:33.016 [script.javaScript.stackTrace]: damageableEquip: [[EquipmentInfo EQ_THRUSTERS_TYPE2A "Manoeuvring Thrusters Class 2A"]]
12:48:33.016 [script.javaScript.stackTrace]: damageableOdds: 1
12:48:33.016 [script.javaScript.stackTrace]: damageableCounter: 1
12:48:33.016 [script.javaScript.stackTrace]: i: "6"
12:48:33.016 [script.javaScript.stackTrace]: cargopods: ["minerals", "minerals"]
12:48:33.016 [script.javaScript.stackTrace]: damage_to: 645.0336249999996
12:48:33.016 [script.javaScript.stackTrace]: n_considered: 2501.0336249999996
12:48:33.016 [script.javaScript.stackTrace]: n_mass: 21.68389375
12:48:33.016 [script.javaScript.stackTrace]: n_cargo: 20
12:48:33.016 [script.javaScript.stackTrace]: 1 (NPC_Equipment_Damage.js:50) <anonymous function>
12:48:33.016 [script.javaScript.stackTrace]: this: [Script "griff_cobra_III_(alt)_externalMissiles.js" version 1.01]
12:48:33.016 [script.javaScript.stackTrace]: type: "scrape damage"
12:48:33.016 [script.javaScript.stackTrace]: whom: [Ship "Asteroid" position: (-41624.9, 15266.9, 349762) scanClass: CLASS_ROCK status: STATUS_IN_FLIGHT]
12:48:33.016 [script.javaScript.stackTrace]: amount: 5425.53564453125
12:48:33.016 [script.javaScript.stackTrace]: internal_damage: true
12:48:33.016 [script.javaScript.stackTrace]: 2 (N-Shields.js:794) <anonymous function>
12:48:33.016 [script.javaScript.stackTrace]: this: [Script "NShields" version 0.6.3]
12:48:33.016 [script.javaScript.stackTrace]: type: "scrape damage"
12:48:33.016 [script.javaScript.stackTrace]: whom: [Ship "Asteroid" position: (-41624.9, 15266.9, 349762) scanClass: CLASS_ROCK status: STATUS_IN_FLIGHT]
12:48:33.016 [script.javaScript.stackTrace]: amount: 7985.53564453125
12:48:33.016 [script.javaScript.stackTrace]: ship: [Ship "Cobra Mark III" position: (-41597.4, 15340.7, 349765) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
12:48:33.016 [script.javaScript.stackTrace]: 3 (N-Shields.js:489) <anonymous function>
12:48:33.016 [script.javaScript.stackTrace]: this: [Script "griff_cobra_III_(alt)_externalMissiles.js" version 1.01]
12:48:33.016 [script.javaScript.stackTrace]: caller: undefined
12:48:33.017 [script.javaScript.stackTrace]: type: "scrape damage"
12:48:33.017 [script.javaScript.stackTrace]: whom: [Ship "Asteroid" position: (-41624.9, 15266.9, 349762) scanClass: CLASS_ROCK status: STATUS_IN_FLIGHT]
12:48:33.017 [script.javaScript.stackTrace]: amount: 8113.53564453125
12:48:33.017 [script.javaScript.stackTrace]: hitLocationRelative: (-31.0124, -70.7728, -1.39412)
12:48:33.017 [script.javaScript.stackTrace]: hitLocation: (-41628.4, 15269.9, 349763)
-
- Competent
- Posts: 58
- Joined: Mon Mar 02, 2015 2:08 pm
- Location: drifting in remLock mask near Vezadi Station
Re: [WIP] NPC Equipment Damage
I think what's happening with the scripts running out of time is that my code doesn't check whether the damage amount is sufficient to destroy the ship, so occasionally something like a collision or a Q-bomb does a truly ridiculous amount of damage and the equipment damage code still gets called once for every 32 points of it.
The download link will shortly be updated to version 0.2.1 with a fix.
The download link will shortly be updated to version 0.2.1 with a fix.
Equal Rights for NPCs!
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: [WIP] NPC Equipment Damage
Small bug in the manifest.plist file on version 0.2.1. You're missing a comma "," between the two "optional_oxp" entries.
- Cholmondely
- Archivist
- Posts: 5365
- Joined: Tue Jul 07, 2020 11:00 am
- Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
- Contact:
Re: [WIP] NPC Equipment Damage
The most recent version seems to be 10th May 2016 - so this bug was presumably not fixed.
There is a bug preventing loading on the AppleMac.
See here: https://bb.oolite.space/viewtopic.ph ... 34#p273134 for the relevant sections in opening.log and putative fixes!
Comments wanted:
•Missing OXPs? What do you think is missing?
•Lore: The economics of ship building How many built for Aronar?
•Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
•Missing OXPs? What do you think is missing?
•Lore: The economics of ship building How many built for Aronar?
•Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
Re: [WIP] NPC Equipment Damage
This OXP is in my TODO list for updating and making sure it smoothly integrates with N-Shields. I plan to do as I did with NPC Energy Units for the same reason (the original's license): re-write as a new OXP (different ID, incompatible with the original so there is no collision) and put the new version in the Expansion Manager.
- Cholmondely
- Archivist
- Posts: 5365
- Joined: Tue Jul 07, 2020 11:00 am
- Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
- Contact:
Re: [WIP] NPC Equipment Damage
I'll see if I can bung up a wiki page for it then.
Comments wanted:
•Missing OXPs? What do you think is missing?
•Lore: The economics of ship building How many built for Aronar?
•Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
•Missing OXPs? What do you think is missing?
•Lore: The economics of ship building How many built for Aronar?
•Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
- Cholmondely
- Archivist
- Posts: 5365
- Joined: Tue Jul 07, 2020 11:00 am
- Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
- Contact:
Re: [WIP] NPC Equipment Damage
I've already sorted out the links on http://wiki.alioth.net/index.php/User:Ngalo
Comments wanted:
•Missing OXPs? What do you think is missing?
•Lore: The economics of ship building How many built for Aronar?
•Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
•Missing OXPs? What do you think is missing?
•Lore: The economics of ship building How many built for Aronar?
•Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?