XML Scrambler 3 & 4: Piracy & Punishment/Anger Mismanagement

A place to discuss mods in development and concepts for new mods.
Post Reply
User avatar
0xABCDEF
Commonwealth Pilot
Commonwealth Pilot
Posts: 90
Joined: Thu May 19, 2016 12:58 am
Location: Was destroyed by a Phobos-class dreadnought in the Eridani system

Sat May 21, 2016 12:55 am

I need a way to inject some code into the OnDestroy event on every ship class. If there is no events subelement, it must create one. If there is, it needs to replace the original. Do the same for the OnDestroy subelement. The task is (not) simple: For the code below, get the piracy check block to successfully enter the ship class.

Code: Select all

	<ItemType UNID="&vtPiracy;"
		name=		"(piracy)"
		level=		"1"
		virtual=	"true"
		>
		<MiscellaneousDevice/>
		<Events>
			<OnGlobalTypesInit>
				(enum (typFind "s") theShip
					(block (theXML theEvents theOnDestroy)
						(if (not (setq theEvents (xmlGetSubElement (setq theXML (typGetXML theShip)) 'events)))
							(xmlAppendSubElement theXML (setq theEvents (xmlCreate 'Events)))
							)
						(if (not (setq theOnDestroy (xmlGetSubElement theEvents 'OnDestroy)))
							(xmlAppendSubElement theEvents (setq theOnDestroy (xmlCreate 'OnDestroy)))
							)
						(xmlAppendText
							theEvents
							"
								(block Nil
									(enum (sysFindObject aOrderGiver "sTAF Z N:100; -auton; -zoanthrope;") theWitness
										(shpOrderImmediate theWitness 'attack aOrderGiver)
										)
									)
							"
							)
						(typCreate theShip theXML)
						)
					)
			</OnGlobalTypesInit>
		</Events>
	</ItemType>
EDIT: Found solution with StaticData

Code: Select all

	<ItemType UNID="&vtPiracy;"
		name=		"(piracy)"
		level=		"1"
		virtual=	"true"
		>
		<MiscellaneousDevice/>
		<StaticData>
			<Events>
			</Events>
			<OnDestroy>
				(block Nil
					(enum (sysFindObject aOrderGiver "sTAF Z N:100; -auton; -zoanthrope;") theWitness
						(shpOrderImmediate theWitness 'attack aOrderGiver)
						)
					)
			</OnDestroy>
		</StaticData>
		<Events>
			<OnGlobalTypesInit>
				(enum (typFind "s") theShip
					(block (theStaticData theXML theEvents theOnDestroy)
						(setq theStaticData (xmlGetSubElement (typGetXML &vtPiracy;) 'StaticData))
						(setq theXML (typGetXML theShip))
						(if (not (xmlGetSubElement theXML 'Events))
							(xmlAppendSubElement theXML (xmlGetSubElement theStaticData 'Events))
							) ;If there is no 'Events, create it
						(setq theEvents (xmlGetSubElement theXML 'Events))
						
						(setq theOnDestroy (xmlGetSubElement theEvents 'OnDestroy))
						(if theOnDestroy
							(xmlDeleteSubElement theEvents (find (xmlGetSubElementList theEvents) theOnDestroy))
							)
						(xmlAppendSubElement theEvents (xmlGetSubElement theStaticData 'OnDestroy))
						(typCreate theShip theXML)
						)
					)
			</OnGlobalTypesInit>
		</Events>
	</ItemType>

Code: Select all

<OnFireWeapon>
	(gamEnd Nil "encountered an unexpected error")
</OnFireWeapon>
-Command Screen Library: RTS in a dockscreen
-Extended Justice: A safer Commonwealth for all
-Playership Bones: Revisit your old ship wrecks!
-Please help out our official Documentarist (me) by editing the wiki

User avatar
TheLoneWolf
Militia Captain
Militia Captain
Posts: 799
Joined: Thu Nov 28, 2013 5:03 pm
Location: Aboard the CSS Radiant

Sat May 21, 2016 8:43 am

Where did you learn what-does-what?

User avatar
0xABCDEF
Commonwealth Pilot
Commonwealth Pilot
Posts: 90
Joined: Thu May 19, 2016 12:58 am
Location: Was destroyed by a Phobos-class dreadnought in the Eridani system

Sun May 22, 2016 5:30 pm

I went onto the IRC for help and also searched for information around xelerus, the wiki, and the forums. The wiki seriously needs to be updated with all available information

Code: Select all

<OnFireWeapon>
	(gamEnd Nil "encountered an unexpected error")
</OnFireWeapon>
-Command Screen Library: RTS in a dockscreen
-Extended Justice: A safer Commonwealth for all
-Playership Bones: Revisit your old ship wrecks!
-Please help out our official Documentarist (me) by editing the wiki

NMS
Militia Commander
Militia Commander
Posts: 400
Joined: Tue Mar 05, 2013 8:26 am

Sun Jun 05, 2016 1:30 am

I just wanted to say thanks for coming up with the <StaticData> idea. It's so much easier than trying to write valid XML inside a Lisp string.

Post Reply