[WIP] NPC Equipment Damage

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: another_commander, winston

Ngalo
Competent
Competent
Posts: 58
Joined: Mon Mar 02, 2015 2:08 pm
Location: drifting in remLock mask near Vezadi Station

[WIP] NPC Equipment Damage

Post by Ngalo »

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.
Last edited by Ngalo on Tue Jun 14, 2016 1:15 pm, edited 3 times in total.
Equal Rights for NPCs!
User avatar
phkb
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3137
Joined: Tue Jan 21, 2014 10:37 pm
Location: Between SDL and a hard place…

Re: [WIP] NPC Equipment Damage

Post by phkb »

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.
Last edited by phkb on Wed May 11, 2016 3:32 am, edited 1 time in total.
User avatar
phkb
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3137
Joined: Tue Jan 21, 2014 10:37 pm
Location: Between SDL and a hard place…

Re: [WIP] NPC Equipment Damage

Post by phkb »

A couple of bugs:

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.
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:

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.
With this one, I think you need to change this:

Code: Select all

					for (h in handlers)
					{
						handlers[h].apply(ship.script, [eq.equipmentKey]);
					}
To this:

Code: Select all

					for (h in handlers)
					{
						if (typeof h == "function") h.apply(ship.script, [eq.equipmentKey]);
					}
Because "h" is already the item in the array.
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.
In this case I think your should just change "append" for "push".
User avatar
Norby
---- E L I T E ----
---- 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

Post by Norby »

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. :)
Ngalo
Competent
Competent
Posts: 58
Joined: Mon Mar 02, 2015 2:08 pm
Location: drifting in remLock mask near Vezadi Station

Re: [WIP] NPC Equipment Damage

Post by Ngalo »

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:

Code: Select all

> for (i in ["spam", "eggs", "ni", "foo", "bar"]){log("item: ", i)}
0

1

2

3

4 
Therefore I don't know what's actually wrong and am not going to break it further by attempting a fix while thus ignorant.
Equal Rights for NPCs!
User avatar
phkb
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3137
Joined: Tue Jan 21, 2014 10:37 pm
Location: Between SDL and a hard place…

Re: [WIP] NPC Equipment Damage

Post by phkb »

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:
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
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?
User avatar
phkb
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3137
Joined: Tue Jan 21, 2014 10:37 pm
Location: Between SDL and a hard place…

Re: [WIP] NPC Equipment Damage

Post by phkb »

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)
Ngalo
Competent
Competent
Posts: 58
Joined: Mon Mar 02, 2015 2:08 pm
Location: drifting in remLock mask near Vezadi Station

Re: [WIP] NPC Equipment Damage

Post by Ngalo »

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!
User avatar
phkb
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3137
Joined: Tue Jan 21, 2014 10:37 pm
Location: Between SDL and a hard place…

Re: [WIP] NPC Equipment Damage

Post by phkb »

Still seeing this in my log file occasionally:

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)
Other issues appear to be fixed, though.
Ngalo
Competent
Competent
Posts: 58
Joined: Mon Mar 02, 2015 2:08 pm
Location: drifting in remLock mask near Vezadi Station

Re: [WIP] NPC Equipment Damage

Post by Ngalo »

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.
Equal Rights for NPCs!
User avatar
phkb
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3137
Joined: Tue Jan 21, 2014 10:37 pm
Location: Between SDL and a hard place…

Re: [WIP] NPC Equipment Damage

Post by phkb »

Small bug in the manifest.plist file on version 0.2.1. You're missing a comma "," between the two "optional_oxp" entries.
User avatar
Cholmondely
Wiki Wizard
Wiki Wizard
Posts: 1881
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of Her Most Britannic Majesty (currently plague-ridden)
Contact:

Re: [WIP] NPC Equipment Damage

Post by Cholmondely »

phkb wrote: Wed Jun 15, 2016 1:04 am Small bug in the manifest.plist file on version 0.2.1. You're missing a comma "," between the two "optional_oxp" entries.
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: http://www.aegidian.org/bb/viewtopic.ph ... 34#p273134 for the relevant sections in opening.log and putative fixes!
Denizen of the Dark and Dismal Deserts of Digebiti.

Milo wrote Dancing the Gavotte
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 466
Joined: Mon Feb 10, 2020 12:47 pm

Re: [WIP] NPC Equipment Damage

Post by dybal »

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.
User avatar
Cholmondely
Wiki Wizard
Wiki Wizard
Posts: 1881
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of Her Most Britannic Majesty (currently plague-ridden)
Contact:

Re: [WIP] NPC Equipment Damage

Post by Cholmondely »

I'll see if I can bung up a wiki page for it then.
Denizen of the Dark and Dismal Deserts of Digebiti.

Milo wrote Dancing the Gavotte
User avatar
Cholmondely
Wiki Wizard
Wiki Wizard
Posts: 1881
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of Her Most Britannic Majesty (currently plague-ridden)
Contact:

Re: [WIP] NPC Equipment Damage

Post by Cholmondely »

I've already sorted out the links on http://wiki.alioth.net/index.php/User:Ngalo
Denizen of the Dark and Dismal Deserts of Digebiti.

Milo wrote Dancing the Gavotte
Post Reply