shipTakingDamage event handler question

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

Moderators: another_commander, winston

Post Reply
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

shipTakingDamage event handler question

Post by Smivs »

I'm trying to trigger an event when the player ship has no shields and is taking damage, so the 'shipTakingDamage' handler looked ideal.
Wiki wrote:The shipTakingDamage handler is called when a ship sustains damage. (For player ships this only happens after the shields are down)
However this is not working as expected. The event is being triggered as soon as the player ship takes a hit. Just one hit from a pulse laser is triggering the event, even when the shields show no loss whatsoever. This is what I'd expect from the 'shipBeingAttacked' handler, but not the 'shipTakingDamage' handler.
I have tested this with a base Cobra3 (no shield boosters etc) up to my iron-ass Boa Clipper and the effect is the same.
Is this right?
Commander Smivs, the friendliest Gourd this side of Riedquat.

User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: shipTakingDamage event handler question

Post by Kaks »

Sounds like a bug! Will look into it & report asap! :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)

User avatar
Commander McLane
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: shipTakingDamage event handler question

Post by Commander McLane »

It does not sound right, especially as the description explicitly says otherwise. (I also notice that the event isn't listed at all on the world script event handler page, only for ship scripts.)

You could of course (sort of) work around it by using an additional check:

Code: Select all

    if(player.ship.forwardShield > 0 && player.ship.aftShield > 0) return;
That's however no real workaround, because of the two different shields. After all, your ship can take damage if only one of the shields is depleted. For a proper check you'd have to keep track of both shield values, and return if one of them decreased (meaning that the shield took the damage).

Thinking about it, there is also the issue of subentities. It may be that it was one of your subentities that took the damage instead of your shields. I have no idea how the event handler deals with subentities.

another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 5803
Joined: Wed Feb 28, 2007 7:54 am

Re: shipTakingDamage event handler question

Post by another_commander »

I think it works as expected. The shipTakingDamage handler takes the damage amount as its first argument and when this is 0, then it means that a shield rather than hull was hit. See the log entries below from the player ship taking damage on shield, followed by damage on the hull.

11:39:59.322 [jstest.shipTakingDamage]: Player ship taking 0 damage by [Ship "GalCop Viper" position: (-47667.8, 57979.1, 428768) scanClass: CLASS_POLICE status: STATUS_IN_FLIGHT] by means of energy damage
11:39:59.572 [jstest.shipTakingDamage]: Player ship taking 6.374378204345703 damage by [Ship "GalCop Viper" position: (-47672.4, 57957.9, 428774) scanClass: CLASS_POLICE status: STATUS_IN_FLIGHT] by means of energy damage

I can't put my hand on the fire for this, but if I recall correctly when the handler was first committed, it was like this by design.

User avatar
Commander McLane
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: shipTakingDamage event handler question

Post by Commander McLane »

another_commander wrote:I think it works as expected. The shipTakingDamage handler takes the damage amount as its first argument and when this is 0, then it means that a shield rather than hull was hit. See the log entries below from the player ship taking damage on shield, followed by damage on the hull.
That makes it even easier to deal with the case (I should've read the documentation properly before posting :oops: ):

Code: Select all

this.shipTakingDamage = function(amount, whom, type)
{
     if(amount === 0) return;
}

User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: shipTakingDamage event handler question

Post by Eric Walch »

Smivs wrote:I'm trying to trigger an event when the player ship has no shields and is taking damage, so the 'shipTakingDamage' handler looked ideal.
Wiki wrote:The shipTakingDamage handler is called when a ship sustains damage. (For player ships this only happens after the shields are down)
However this is not working as expected. The event is being triggered as soon as the player ship takes a hit.
I think another_commander is right. The handler is working as planned, only the description in the wiki is wrong. The handler fires when hit and than shows the amount of damage. That way a script is able to transfer energy from the banks to the shields on a hit or do other interesting shield alterations. :wink:

User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: shipTakingDamage event handler question

Post by Smivs »

Thanks all. Yes, it seems the wording in the Wiki is misleading/confusing. By 'down' I assumed it meant 'down to zero', whereas it actually means 'down below maximum'. Perhaps it should read
For player ships this happens if the shields are below maximum
or similar.
No worries. By following McLanes suggestion of doing a shield check as well, I've pretty much got things working as I wanted.
Commander Smivs, the friendliest Gourd this side of Riedquat.

User avatar
Commander McLane
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: shipTakingDamage event handler question

Post by Commander McLane »

Smivs wrote:By following McLanes suggestion of doing a shield check as well, I've pretty much got things working as I wanted.
The second suggestion of checking for '0' as amount is much better.

User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: shipTakingDamage event handler question

Post by Smivs »

Commander McLane wrote:
Smivs wrote:By following McLanes suggestion of doing a shield check as well, I've pretty much got things working as I wanted.
The second suggestion of checking for '0' as amount is much better.
Yes, both methods seem to work identically, but the check for amount is certainly more elegant. Thank you.
Commander Smivs, the friendliest Gourd this side of Riedquat.

User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: shipTakingDamage event handler question

Post by Kaks »

OK, it would be simple to change, but it looks like the 1.76 behaviour allows for more flexibility. Updating the wiki it is! :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)

User avatar
Commander McLane
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: shipTakingDamage event handler question

Post by Commander McLane »

Smivs wrote:
Commander McLane wrote:
Smivs wrote:By following McLanes suggestion of doing a shield check as well, I've pretty much got things working as I wanted.
The second suggestion of checking for '0' as amount is much better.
Yes, both methods seem to work identically, but the check for amount is certainly more elegant. Thank you.
It's not only more elegant, but also the only variant which gives correct results. The two approaches will stop working identically as soon as either your front or your rear shield is depleted. From then on the first approach is bound to give false results.

User avatar
Thargoid
Thargoid
Thargoid
Posts: 5510
Joined: Thu Jun 12, 2008 6:55 pm

Re: shipTakingDamage event handler question

Post by Thargoid »

Yes, A_C's recollection is correct. I recall the discussion I had with Ahruman on the subject when it was set up, as the event was my request so I could write IronHide properly.

Post Reply