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
Militia Lieutenant
Militia Lieutenant
Posts: 124
Joined: Thu May 19, 2016 12:58 am
Location: Was destroyed by a Phobos-class dreadnought in the Eridani system

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>
User avatar
TheLoneWolf
Militia Captain
Militia Captain
Posts: 802
Joined: Thu Nov 28, 2013 5:03 pm
Location: Aboard the CSS Radiant

Where did you learn what-does-what?
User avatar
0xABCDEF
Militia Lieutenant
Militia Lieutenant
Posts: 124
Joined: Thu May 19, 2016 12:58 am
Location: Was destroyed by a Phobos-class dreadnought in the Eridani system

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
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 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