Page 1 of 1
Targetting subents
Posted: Tue Oct 11, 2011 7:37 pm
by CommonSenseOTB
Is there a way through script or AI to have NPC's target a subent of the player ship or of other NPC's instead of the main entity so they would effectively ignore the main entity to attack the subent(s) only?
Re: Targetting subents
Posted: Tue Oct 11, 2011 8:33 pm
by Thargoid
Not to my knowledge, no.
Re: Targetting subents
Posted: Tue Nov 29, 2011 1:00 pm
by Kaks
Sorry, I hadn't noticed this one at the time!
I take it you've already tried this snippet inside your NPC js script:
Code: Select all
this.shipTargetAcquired = function(targetShip){
if(targetShip.subEntities.length > 0) this.ship.target = targetShip.subEntities[0];
}
I haven't actually looked into this at all, but I'd have thought there's nothing in trunk (and in 1.75.3) to stop it from working...
Re: Targetting subents
Posted: Tue Nov 29, 2011 3:40 pm
by Eric Walch
Kaks wrote:I haven't actually looked into this at all, but I'd have thought there's nothing in trunk (and in 1.75.3) to stop it from working...
I remember looking in the code and noticed that the code always makes sure it is not targeting subEnts. It selects the mother when tried.
Re: Targetting subents
Posted: Tue Nov 29, 2011 4:11 pm
by Kaks
Ok, then all you can do is to specifically override the targetted ship's takingDamage, to transfer all the damage to one of its subentities. Technically it's not the same, but hey, as long as you don't tell anybody...
Something along these lines:
Code: Select all
this.ship.target.script.oldDamageEvent = this.ship.target.script.shipTakingDamage
player.thatSpecificShip = this.ship;
this.ship.target.script.shipTakingDamage = function(amount, whom, type)
{
if(whom.isValid && whom == player.thatSpecificShip && this.ship.subEntities.length > 0){
// they're targetting subents!!!
this.ship.energy += amount;
this.ship.subEntities[0].energy -= amount;
}
else if (this.oldDamageEvent) this.oldDamageEvent();
}
Shouldn't be too far from working ok: as long as it's got at least a subent, any hit from 'thatSpecificShip' is going to damage the first subent. Once all subents are gone it'll behave exactly as before!
The extra stuff in the script is to take into account NPC shields & the like. If you don't care about that, then things should get simpler.
NB: the keyword
this should refer to different things depending on the context, that's why I used player to transfer the original
this.ship value inside the function. To be 'proper' I should have used closures instead, but that could have meant a bit of a longer explanation...
Anyway, hope this goes some way towards helping you make your ideas reality!
Re: Targetting subents
Posted: Tue Nov 29, 2011 5:31 pm
by CommonSenseOTB
Thanx Kaks. That should help tremendously down the road.