Page 1 of 1

Getting ship or escapepod co-ordinates when player ejects

Posted: Mon Oct 14, 2013 4:16 am
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 . .).

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

Posted: Mon Oct 14, 2013 6:47 am
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.

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

Posted: Mon Oct 14, 2013 1:59 pm
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?

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

Posted: Mon Oct 14, 2013 3:29 pm
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")
}

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

Posted: Mon Oct 14, 2013 3:46 pm
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") ) }

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

Posted: Mon Oct 14, 2013 5:05 pm
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.

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

Posted: Tue Oct 15, 2013 2:07 am
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.