Getting ship or escapepod co-ordinates when player ejects

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

Moderators: winston, another_commander

Post Reply
UK_Eliter
---- E L I T E ----
---- E L I T E ----
Posts: 1246
Joined: Sat Sep 12, 2009 11:58 pm
Location: Essex (mainly industrial and occasionally anarchic)

Getting ship or escapepod co-ordinates when player ejects

Post by UK_Eliter »

Hi all

I'm asking for a bit of help. I need to be able to determine which ships are near the player's escape capsule, but:

(1) seemingly I can't use player.ship.position for this, because, by the time the this.escapePodSequenceOverhandler fires, or even the handler this.shipLaunchedEscapePod, that variable is invalid;

(2) this.shipLaunchedEscapePod does give me the escapepod entity to use, but its reported position seems fixed at (!) 0,0,0.

Help! Sorry if I am missing something (it is rather late . .).
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Getting ship or escapepod co-ordinates when player eject

Post by cim »

UK_Eliter wrote:
(1) seemingly I can't use player.ship.position for this, because, by the time the this.escapePodSequenceOverhandler fires, or even the handler this.shipLaunchedEscapePod, that variable is invalid;

(2) this.shipLaunchedEscapePod does give me the escapepod entity to use, but its reported position seems fixed at (!) 0,0,0.
You can do

Code: Select all

system.filteredEntities(this, function () { return true; }, player.ship, 25600);
The first entry this returns will be the clone of the player ship added for showing the escape sequence, and the rest will be what you're after.
UK_Eliter
---- E L I T E ----
---- E L I T E ----
Posts: 1246
Joined: Sat Sep 12, 2009 11:58 pm
Location: Essex (mainly industrial and occasionally anarchic)

Re: Getting ship or escapepod co-ordinates when player eject

Post by UK_Eliter »

Thanks a lot for that cim. It does indeed work. The problem must have been elsewhere in my script ('cos I was trying that before). The problem might have been multi-line filter functions, along the lines of:

Code: Select all

function $otherShipsToRemove(e)
	{
		return
		(
			!e.isPlayer && !e.isPolice && !e.scanClass == "CLASS_MILITARY"
			&& !e.hasRole("IST_mil") && !e.hasRole("spectre")
			&& !e.hasRole("IST_alloy") && !e.hasRole("IST_alien_cargopod") && !e.hasRole("asteroid")
			&& !e.hasRole("hiredGuns_escort") && !e.hasRole("ecl_escape_pod_beacon") && !e.hasRole("escape-capsule")
		);
	}
Is that sort of use of split lines OK?
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Getting ship or escapepod co-ordinates when player eject

Post by Commander McLane »

Yes, it should be. As long as all the brackets etc. are correct, of course.

Speaking of which, I'm not sure whether the ()-parenthesis is correct in this specific example. I have usually not used it for a return condition. Thus I'd write

Code: Select all

function $otherShipsToRemove(e)
{
    return !e.isPlayer && !e.isPolice && !e.scanClass == "CLASS_MILITARY" && !e.hasRole("IST_mil") && !e.hasRole("spectre") && !e.hasRole("IST_alloy") && !e.hasRole("IST_alien_cargopod") && !e.hasRole("asteroid") && !e.hasRole("hiredGuns_escort") && !e.hasRole("ecl_escape_pod_beacon") && !e.hasRole("escape-capsule")
}
UK_Eliter
---- E L I T E ----
---- E L I T E ----
Posts: 1246
Joined: Sat Sep 12, 2009 11:58 pm
Location: Essex (mainly industrial and occasionally anarchic)

Re: Getting ship or escapepod co-ordinates when player eject

Post by UK_Eliter »

Commander McLane wrote:
Yes, it should be. As long as all the brackets etc. are correct, of course.

Speaking of which, I'm not sure whether the ()-parenthesis is correct in this specific example. I have usually not used it for a return condition. Thus I'd write

Code: Select all

function $otherShipsToRemove(e)
{
    return !e.isPlayer && !e.isPolice && !e.scanClass == "CLASS_MILITARY" && !e.hasRole("IST_mil") && !e.hasRole("spectre") && !e.hasRole("IST_alloy") && !e.hasRole("IST_alien_cargopod") && !e.hasRole("asteroid") && !e.hasRole("hiredGuns_escort") && !e.hasRole("ecl_escape_pod_beacon") && !e.hasRole("escape-capsule")
}
Thanks! Anyone else, though, have a view on the matter of the bracket type? I suppose it can't hurt to replace the parentheses with curly brackets - after all, that's what McLane does, and various tutorials on the web do things that way too. EDIT: ah, actually, McLane has not replaced those parentheses - the ( and ) - but just removed them . . I suppose one needs them when the boolean could evaluate different ways depending on how one interpreted it, i.e. one needs the brackets when one would need them in algebra, and not otherwise. EDIT again: so you'd need brackets for the following (which does indeed contain brackets - and it's from code of mine):

Code: Select all

function $isNavalCarrier(e) { return e.isShip && ( e.hasRole("behemoth") || e.hasRole("leviathan") ) }
Last edited by UK_Eliter on Mon Oct 14, 2013 5:20 pm, edited 1 time in total.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Getting ship or escapepod co-ordinates when player eject

Post by Commander McLane »

UK_Eliter wrote:
I suppose one needs them when the boolean could evaluate different ways depending on how one interpreted it, i.e. one needs the brackets when one would need them in algebra, and not otherwise. EDIT again: so you'd need brackets for the following (which does indeed contain brackets - and it's from code of mine):

Code: Select all

function $isNavalCarrier(e) { return e.isShip && ( e.hasRole("behemoth") || e.hasRole("leviathan") ) }
Yep. But this also means that they can't hurt if put around the whole condition. So that was probably a false alarm.
User avatar
Tricky
---- E L I T E ----
---- E L I T E ----
Posts: 821
Joined: Sun May 13, 2012 11:12 pm
Location: Bradford, UK. (Anarchic)

Re: Getting ship or escapepod co-ordinates when player eject

Post by Tricky »

Javascript automatically inserts a semi-colon on a new line, Whitespace and semicolons, so it probably is best to have brackets for a return statement.
Post Reply