Page 1 of 1

Accessing an entity's parent [SOLVED]

Posted: Tue Aug 16, 2011 2:34 pm
by UK_Eliter
[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.

Code: Select all

function isHostile(entity) 
{	 
	return (entity.isShip && entity.target && entity.target == player.ship && entity.hasHostileTarget);
}
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.

Re: Accessing an entity's parent

Posted: Tue Aug 16, 2011 3:22 pm
by Eric Walch
UK_Eliter wrote:
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.
it is this.ship.owner as described here. When subminution is launched, it takes the target from the mother missile.

Re: Accessing an entity's parent [SOLVED]

Posted: Tue Aug 16, 2011 3:41 pm
by UK_Eliter
Eric: great. Thank you.