Scripters cove

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Scripters cove [hope I'm not hijaking this thread . .]

Post by Smivs »

UK_Eliter wrote:
Hi everyone

Can anyone tell me, please, if/how I can detect whether a ship (specifically: the player) has initiated an ECM pulse?

Cheers.

If you pressed the right button, you probably did :wink:
Commander Smivs, the friendliest Gourd this side of Riedquat.
UK_Eliter
---- E L I T E ----
---- E L I T E ----
Posts: 1248
Joined: Sat Sep 12, 2009 11:58 pm
Location: Essex (mainly industrial and occasionally anarchic)

Re: Scripters cove

Post by UK_Eliter »

Smivs! :roll: This forum is not called 'player's cove'!

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).
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Scripters cove

Post by Capt. Murphy »

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
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Scripters cove

Post by Eric Walch »

Capt. Murphy wrote:
It doesn't appear to be documented in the wiki
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. :?
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Scripters cove

Post by Svengali »

Capt. Murphy wrote:
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.
Eric Walch wrote:
Since today it is in the wiki as: shipHitByECM.
Thanks a lot Eric.
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: Scripters cove

Post by Zieman »

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).
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

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.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Scripters cove

Post by Eric Walch »

Zieman wrote:
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:

Code: Select all

this.shipSpawned = function ()
{
	this.checkPlayerTimer = new Timer(this, this.checkPlayer, 20, 10);
}

this.checkPlayer = function ()
{
	// do your checking here. e.g.:
	if (player.ship.position && player.ship.position.distanceTo(this.ship) < this.ship.scannerRange) this.foo();
}

this.entityDestroyed = function ()
{
    if (this.checkPlayerTimer) {this.checkPlayerTimer.stop(); delete this.checkPlayerTimer};
}
The last lines is to remove the timer again after the ship is removed from the system.
Last edited by Eric Walch on Wed Oct 12, 2011 7:53 pm, edited 1 time in total.
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: Scripters cove

Post by Zieman »

Wow, thanks guys!

Saves me countless hours of trying to figure out stuff from the wiki and endless try-think-retry-rethink -cycle...
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: Scripters cove

Post by Zieman »

Another question:
I have a code snippet in a ship script that is supposed to prevent said (pirate) ship attacking player if player has bounty:

Code: Select all

this.shipTargetAcquired = function(target)
	{
		if (target.isPlayer && player.bounty > 0) this.ship.target = null;
	}
It even seems to be working, but every now and the I get log errors conserning this code (line 37 is the if -line):

Code: Select all

19:17:54.031 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (Far Arm ships Dart script 3.0): TypeError: target is null
19:17:54.031 [script.javaScript.exception.unexpectedType]:       ../AddOns/Far_Arm_ships_v3.0_beta4.oxp/Scripts/fa-dart.js, line 37.
I presume my coding is again incomplete, even if the tiniest possibility of a possible Oolite bug might exist ?
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

More likely the target is acquired and then immediately lost for some reason. Just change your code to

Code: Select all

if (target && target.isPlayer && player.bounty > 0) this.ship.target = null;
and you'll be covered in this case. It's good practice to do anyway (I should know, I keep falling over this one myself!)[/color]
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Scripters cove

Post by Eric Walch »

Zieman wrote:
Another question:
I have a code snippet in a ship script that is supposed to prevent said (pirate) ship attacking player if player has bounty:

Code: Select all

this.shipTargetAcquired = function(target)
	{
		if (target.isPlayer && player.bounty > 0) this.ship.target = null;
	}
The problem is probably that the target is already invalid when the code triggers. Better to double check the target really exist by using

Code: Select all

this.shipTargetAcquired = function(target)
	{
		if (target && target.isPlayer && player.bounty > 0) this.ship.target = null;
	}
Edit: ninjad by Thargoid.
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: Scripters cove

Post by Zieman »

Wow, that was quick!

Thank you again, both of you!
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
User avatar
Okti
---- E L I T E ----
---- E L I T E ----
Posts: 700
Joined: Sun Sep 26, 2010 1:51 pm
Location: A GH shop, near witchpoint to Oresrati in Galaxy 8

Re: Scripters cove

Post by Okti »

Hi all,

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?
My OXP's
And Latest Mission Coyote's Run
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

They can use whatever AI you want (the ship group won't make any changes to AI).

Have a look at the Thargoid armada group in TCAT for an example of it's use (it is a little convoluted).
Post Reply