I'm trying to write a little OXP that fortifies the ECM system. For that I need to be able to detect by script whether the player's ECM is on (although, ideally, I'd allow some NPCs to have the equipment in question, too).
It doesn't appear to be documented in the wiki but in the source code I've seen a reference to a ship script event handler.. this.shipHitByECM(pulsesRemaining) .. which I think may be a starting point. It's noted in the release notes for 1.71 aswell.
Edit to add - and also used by Svengali in one of his Vector Scripts...vector_richman.js
Good spotted. Since today it is in the wiki as: shipHitByECM.
It was probably missed because it is in a whole different part of the code and not in ship- or player-entity.
Edit to add - and also used by Svengali in one of his Vector Scripts...vector_richman.js
Yep. The Vector is using this handler.
But to decide if the ECM pulse comes from the player you'll have to combine it with other checks - e.g. checking players energy level, etc. If I remember right the calculated value of the energy drain is not a constant value and other stuff (like the cloak or hit by lasers) will change that level as well.
If your plan is just a communication you could also use Cabal_Common_Comms to have more control.
Is there any way an NPC could 'notice' player, using just JS (ship script?) ?
By 'notice' I mean to make it react (for example send comms message "hello") to player presence (player inside scanner range) or player action (player targetting said NPC for ID or missile).
Yes, just use a periodic scan (driven by a timer for example) with a filter that the entity isPlayer and a range of 25600 (or whatever you want). The result of the scan will be an array of either zero length (if the player isn't in range) or 1 entity long (if they are).
You can adjust things by changing the filtering on the scan (e.g. entity.isPlayer && entity.target && entity.target === this.ship) for the player being in range and having the scanning ship under target lock.
If you want an example of such scanning, look in the probe missile script in Armoury, plus several other OXPs as well as it's quite a common technique.
Last edited by Thargoid on Tue Oct 11, 2011 8:38 pm, edited 1 time in total.
Is there any way an NPC could 'notice' player, using just JS (ship script?) ?
For that you need a timer that regularly does the check. Easiest is doing is with a script call from an AI because AI.plist already has a timer through UPDATE.
When you want to do it exclusively from JS you must create your own timer:
I am a bit confused about shipGroup. If I add a leader and more ships to the group, does the others use the escortAI for the leader, or can they have seperate AI's like a special escortAI?