I can't recall - or perhaps I never knew - how to do the following. I've got some ships in a group. Only one of them has an ECM. I want the one with an ECM to fire it when it, or one of its fellows, is attacked with a missile. How do do this? None of the ships has a script but only instead a (PLIST) AI. Thanks.
EDIT: I haven't set any of the ships as a group leader.
Getting a ship to fire ECM on behalf of another ship
Moderators: winston, another_commander
- Norby
- ---- E L I T E ----
- Posts: 2577
- Joined: Mon May 20, 2013 9:53 pm
- Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
- Contact:
Re: Getting a ship to fire ECM on behalf of another ship
Imho attach a ship script to all ships (either in shipata.plist or calling ship.setScript()) then within shipAttackedWithMissile handler you can call ship.fireECM() on the ECM-equipped ship.
-
- ---- E L I T E ----
- Posts: 1248
- Joined: Sat Sep 12, 2009 11:58 pm
- Location: Essex (mainly industrial and occasionally anarchic)
Re: Getting a ship to fire ECM on behalf of another ship
Thanks very much Norby. However, that approach seems a fair amount of work, both computationally (i.e. it will be a bit expensive CPU-wise) and for me, especially since I'm doing it only really for a gimic (with, er, interstellar versions of Witchspace-Worshipping Lobsters, and in an already rather over-extended OXP, namely my Interstellar Tweaks). Is there no easier way, involving an AI?
- Norby
- ---- E L I T E ----
- Posts: 2577
- Joined: Mon May 20, 2013 9:53 pm
- Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
- Contact:
Re: Getting a ship to fire ECM on behalf of another ship
This is not not CPU expensive because called only at the event of missile launch and the ECM-equipped ship should be stored into a variable when created.
The AI way is similar. For example:
Then you must make a
When you create the ships you should set $shipWithECM in each ship script. If you create them using system.addShips then do this:
The AI way is similar. For example:
Code: Select all
"INCOMING_MISSILE" = (fireECM, fightOrFleeMissile, setTargetToPrimaryAggressor, "sendScriptMessage: _requestECM");
_requestECM
function in a ship_script_ecm.js:
Code: Select all
this._requestECM = function _requestECM() {
var ship = this.$shipWithECM;
if( ship && ship.isValid) ship.fireECM();
}
Code: Select all
var ships = system.addShips("unique-rule-or-datakey-of-ships", 6, player.ship.position, 20000);
for(var i=0; i<ships.length; i++) {
if(i == 0) { //give ECM to the first ship
ships[i].awardEquipment("EQ_ECM");
}
ships[i].setScript("ship_script_ecm.js"); //will call for friendly ECM when attacked by missile
ships[i].script.$shipWithECM = ships[0]; //save the first ship which hold ECM
}
}
-
- ---- E L I T E ----
- Posts: 1248
- Joined: Sat Sep 12, 2009 11:58 pm
- Location: Essex (mainly industrial and occasionally anarchic)
Re: Getting a ship to fire ECM on behalf of another ship
OK, I've implemented that and it works. Thank you very much, Norby. (You were in the acknowledgements of my OXP already.)
-
- ---- E L I T E ----
- Posts: 1248
- Joined: Sat Sep 12, 2009 11:58 pm
- Location: Essex (mainly industrial and occasionally anarchic)
Re: Getting a ship to fire ECM on behalf of another ship
There's something else I'd like to do, but I fear it would be complicated. It's this: I have ships that attack the player if he is not a fugitive; but I'd like them to attack him, also, if he is a fugitive but has previously fired on one of them. (If he does fire on them, they will respond; but they can get distracted by picking up loot or fighting other ships; it's when they return to seeking victims that I'd like them to recall that he - the player - fired on them (if he did).
Any ideas? EDIT: OK, I've got it all working!
Perhaps I should do this: get the ships to store whether the player has fired on them, via the event handler (or is there a better, more specific handler), and then check the stored variable when seeking targets. I'd use, in the targetting bit, something like this:
(though sadly I have to strip out the readable formatting for such a thing to work).
EDIT: OK, I've got it all working!
Any ideas? EDIT: OK, I've got it all working!
Perhaps I should do this: get the ships to store whether the player has fired on them, via the
Code: Select all
shipTakingDamage
Code: Select all
this.$isPotentialTarget = function(e) {
return
e.isShip && !e.isCloaked && e.isPiloted
&&
(
(
( e.isPirateVictim || e.hasRole("hiredGuns_escort") || e.isPlayer ) && ( e.bounty < 50 )
)
||
(
e.isPlayer && this.ship.script.$playerHasAttackedPirates
)
)
}
EDIT: OK, I've got it all working!
- Norby
- ---- E L I T E ----
- Posts: 2577
- Joined: Mon May 20, 2013 9:53 pm
- Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
- Contact:
Re: Getting a ship to fire ECM on behalf of another ship
I think this way is good, just set the HasAttacked variable in all ship scripts within the pirate group.