Pos or vector help please

Freeform discussion about anything related to modding Transcendence.
Post Reply
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

I'm trying to place another stargate in Eridani exactly opposite Dante II which is the barren planet near the Eridani Stargate.

Code: Select all

<Station type="&stRockyPlanetoidSizeF;" 
		objName="OldStart"
		name="Dante II" 
		showOrbit="true"
		/>
I can get the stargate to appear and function but I can't work out how to get it to refer to Dante II's position.

This puts it 100ls straight up from the star:

Code: Select all

<OnGlobalSystemCreated>
	(if (eq (sysGetNode) "SE")
		(block Nil
			(sysCreateStargate &stStargate; (sysVectorPolarOffset Nil 90 100) "GateToNirvana" "NI" "NirvanaStargate")
		)
	)
</OnGlobalSystemCreated>
But I can't get it to go straight up from Dante II. I can work out how to subtract the vectors to put the stargate at 180 degrees relative but can't work out how to use Dante II's position.

I've tried "Dante II", "OldStart", objGetPos and everything else I can think of inside the sysVectorPolarOffset brackets. In theory if I change the "Nil" value to Dante II's position it should work. But the game won't play ball. Does anyone know how to do this or if this can even be done? TIA.
Stupid code. Do what I want, not what I typed in!
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

Apparently, the names assigned to worlds in system definitions don't override the names in their type definitions. So Dante II's name is "(rocky planetoid)". This is probably a bug, but it generally doesn't matter since you can't target them manually.

Anyway, this code should find it and return its ID, assuming Eridani is the active system:

Code: Select all

(block (DanteII)
	(enumWhile (sysFindObject nil "t S:d") (not DanteII) object
		(if (eq (objGetType object) &stRockyPlanetoidSizeF;)
			(setq DanteII object)
		)
	)
	DanteII
)
Last edited by NMS on Sun Nov 06, 2016 3:36 am, edited 1 time in total.
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

also (objgetname thePlanet) should return the name of the planet if the planet has a name.
If it doesn't, then it returns "(planet)" (including the parenthesis)
you can use this to filter the list of the objects in the system and return only the planet you want

this, in theory, should return the pos of Dante II:

(objGetPos (@ (filter (sysFindObject gPlayerShip "t") tempPlanet (eq (objGetName tempPlanet) "DanteII")) 0)

I didn't test it, so I'm not sure if it works.
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

Huh, you're right, assuming you put a space in "Dante II". I didn't realize there was a difference between (objGetName object) and (objGetProperty object 'name). I guess the latter gets the type's default name.

You probably don't need to call (objGetPos), though. I think every function that takes a position also takes the ID of an object.
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

I think every function that takes a position also takes the ID of an object.
ah ! nice :D

this will simplify (and maybe speed-up?) some of my code for Weapons Extended.
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Thank you. I'll put that in and see how I go.

The only other way I could think of was to use objGetID to get the ID of anything near the Eridani stargate that wasn't a stargate, nav sign, asteroid, ship or wreck. But that seemed a bit longwinded and I've never used objGetID so didn't know if it would work.

Thanks again!
Stupid code. Do what I want, not what I typed in!
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Success. Both lots of code work, and as NMS said, digdug's code works without the objGetPos.

I used digdugs because I'd never seen enumWhile before (and it's gonna take me a while to work it out).

Final code:

Code: Select all

<OnGlobalSystemCreated>
	(block Nil
		(if (eq (sysGetNode) "SE")
			(sysCreateStargate
				&stStargate; 
					(sysVectorPolarOffset 
						Nil
						(add 
							(sysVectorAngle (@ (filter (sysFindObject gPlayerShip "t") tempPlanet (eq (objGetName tempPlanet) "Dante II")) 0))
							180
						)
						80
					)
				"GateToNirvana"
				"NI"
				"NirvanaStargate"
			)
		)
	)
</OnGlobalSystemCreated>
This places the stargate 80ls away from the star (which is also the system centre) at a bearing of 180 degrees (or opposite in other words) from Dante II.

Thanks. And you'll both get a special thanks in the code.
Stupid code. Do what I want, not what I typed in!
Post Reply