Accessing an entity's parent [SOLVED]
Posted: Tue Aug 16, 2011 2:34 pm
[EDIT: I meant to put this in the 'Scripters' Cove' thread - but it seems I failed to. Sorry.]
Dear all
I am trying to make a script detect whether (1) an entity's parent has been targeted in a hostile way by some other ship (that's to enable a missile to target ships attacking the ship that launched the missile), (2) the as-it-were grandparent of an entity has been targeted in a hostile way by some other ship (that's to enable subminitions that launch from the aforementioned missile to target ships attacking the ship that launched the missile).
Now, I've managed to do this (both 1 and 2) when the ship that launches the missile is the player. For then I can just use the following function.
But I'm having trouble with the situation when that is not the case, i.e. when a NPC launched the missile. There doesn't appear to be a this.ship.parent key (even for entities that are declared as both missiles and submunitions). Can anyone help?
Apologies if this has been discussed before. I couldn't find such a discussion.
Dear all
I am trying to make a script detect whether (1) an entity's parent has been targeted in a hostile way by some other ship (that's to enable a missile to target ships attacking the ship that launched the missile), (2) the as-it-were grandparent of an entity has been targeted in a hostile way by some other ship (that's to enable subminitions that launch from the aforementioned missile to target ships attacking the ship that launched the missile).
Now, I've managed to do this (both 1 and 2) when the ship that launches the missile is the player. For then I can just use the following function.
Code: Select all
function isHostile(entity)
{
return (entity.isShip && entity.target && entity.target == player.ship && entity.hasHostileTarget);
}
Apologies if this has been discussed before. I couldn't find such a discussion.