secondary weapon UNID query

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

Does anyone know if there is an easy way to get the UNID of the secondary weapon of a ship class? typGetProperty - secondaryWeaponUNID doesn't work unfortunately :(. Possibly 'secondaryWeapon="true"' can be used in a search somehow.
I'm mucking about with the Korolov Enemy Intelligence screens which only show the one (primary) weapon but would like the first secondary weapon to show as well.

Or is it a case of converting to a shipobject then getting the first installed weapon-not primary and reconverting to a UNID? TIA.
Stupid code. Do what I want, not what I typed in!
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

you get get/set a secondary weapon property using:

(objGetItemProperty obj item 'secondary) -> True or Nil

(objSetItemProperty obj item 'secondary) -> True if successful.
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Thank you. I'm a bit busy ATM but that will help; it's a lot easier than what I was going to try!
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

That checks a specific item on a specific ship. So to get the secondary weapons on a ship you could use this:

Code: Select all

(filter (objGetItems obj 'wI) theWeapon (objGetItemProperty obj theWeapon 'secondary))
That will return a list of items. You can use (itmGetType item) to get the UNIDs.

I think if you want to get this for a ship type, you'll have to create a ship of that type, run that code on it, then destroy it.
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Thanks for that. I had a quick try over Xmas but couldn't quite work out the filtering code. This definitely helps. :)
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

Got it. I was trying to get a weapon list off of a UNID and that didn't work. Thank you both.

Final code that gives us 'secondaryWeaponUNID'. The screen needs this to display the weapon's name.
This is inserted into a copy of the Korolov ship information screen code to add the secondary weapon to the display.

Code: Select all

		;Here we insert code to allow the dockscreen to display the name of the secondary weapon if there is one.
	(setq createdShip (sysCreateShip (@ gSelect 0) Nil (typGetProperty (@ gSelect 0) 'defaultSovereign)))
	(setq secondaryWeaponList (filter (objGetItems createdShip 'wI) theWeapon (objGetItemProperty createdShip theWeapon 'secondary)))
	(objDestroy createdShip)
	(setq secondaryWeapon (@ secondaryWeaponList 0))
	(setq secondaryWeaponUNID (int (itmGetType secondaryWeapon)))

	(if (eq weaponUNID secondaryWeaponUNID)
		(setq secondaryWeaponUNID 0)
	)
	(if (eq classUNID &scHeliotropeGunship;)
		(setq secondaryWeaponUNID (int &itTurbolaserCannon;))
	)
	(if (eq classUNID 0x001B3004)
		(setq secondaryWeaponUNID (int &itMicronukeCannon;))
	)
(@ gSelect 0) is a ship UNID taken from a StaticData table.
The three 'if's at the end are
1: to stop the screen displaying the secondary weapon twice in ships if the primary weapon is a launcher.
2 and 3: the Heliotrope Gunship and Tundra don't have the property 'secondary' on either of their weapons so their second weapon doesn't get filtered into the secondary weapon list. This cheats and adds it manually.
I might do different code to count installed weapons and add them to the list if there isn't a secondary weapon one day.
Stupid code. Do what I want, not what I typed in!
Post Reply