The XML Scrambler Part I: Limited Ammunition Mode

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

This is my attempt at creating a mod that takes all non-ammo matter weapons from the XML and makes them use charges to limit their ammunition. It does load as an item, but does not seem to do anything for some reason...

Code: Select all

	<ItemType UNID="&vtWeaponizer;"
		name=		"(weaponizer)"
		level=		"1"
		virtual=	"true"
		>
		<MiscellaneousDevice/>
		<Events>
			<OnGlobalTypesInit>
				(block Nil
					;Sets theWeapon to the itemStruct
					(itmEnumTypes "p -energyWeapon" theWeapon
						(block (theType theXML)
							;Converts the itemStruct to the UNID and then to the XML
							(setq
							 theXML
							 (typGetXML
							  (setq
							   theType
							   (itmGetType
								theWeapon
								)
							   )
							  )
							 )
							
							(if
							(or ;For testing
							 (not
							  (or
							   (xmlGetSubElement (xmlGetSubElement theXML 'weapon) 'missiles)
							   (xmlGetAttrib theXML 'charges)
							   )
							  )
							 True) ;For testing
								;The weapon must have infinite ammo
								(block (halfValue halfMass)
									;Halve the value of the item
									(xmlSetAttrib theXML 'value (setq halfValue (cat (divide (int (xmlGetAttribute theXML 'value)) 2))))
									
									;Halve the mass of the item
									(xmlSetAttrib theXML 'mass (setq halfMass (cat (divide (int (xmlGetAttribute theXML 'mass)) 2))))
									
									;Add charges to the item
									(xmlSetAttrib theXML 'charges "500")
									
									;Add value bonus to item
									(xmlSetAttrib theXML 'valueBonusPerCharge (cat (divide halfValue 500)))
									
									;Add mass bonus to item
									(xmlSetAttrib theXML 'massBonusPerCharge (cat (divide halfMass 500)))
									
									;Make the weapon use charges
									(xmlSetAttrib (xmlGetSubElement theXML 'weapon) 'charges "true")
									
									(typCreate (unvDynamicUNID (xmlSetAttrib theXML 'name (cat "limited " (xmlGetAttribute theXML 'name)))) theXML) ;theType
									)
								)
							)
						)
					)
			</OnGlobalTypesInit>
		</Events>
	</ItemType>
Also I would like to register 0xABCD as my UNID
RPC
Fleet Admiral
Fleet Admiral
Posts: 2876
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

Couple problems (posting this here for posterity and for when one of us inevitably forgets):
1. unvDynamicUNID should be typDynamicUNID
2. OnGlobalTypesInit is too early in the game to call for item unids.
One test you can try is (PrintTo 'log (itmGetTypes "*")) in <OnGlobalTypesInit>. It will return nil when it should return a list of all items in the game.
Try OnGlobalUniverseCreated instead
3. xmlGetAttribute should be xmlGetAttrib
4. You can check the XMLs of all the items in the game in debuglog to check if the code works or install the right item. The problem right now is you typcreate a new item that is a duplicate, not replace the preexisting item (which I heard was doable?).

PROTIP: don't have comments in the xml you modify because that will mess up typget* functions

Code: Select all

<OnGlobalUniverseCreated>
                (block Nil
					
					;set index here:
					(TypSetData &vtWeaponizer; "i" 0)
					
                   ;Sets theWeapon to the itemStruct
                   (itmEnumTypes "p -energyWeapon" theWeapon (block (theType theXML)
                         ;Converts the itemStruct to the UNID and then to the XML
                         (setq theXML (typGetXML (setq theType (itmGetType theWeapon ))))
                         
                        (if
							(or
								(not(or
									(xmlGetSubElement (xmlGetSubElement theXML 'weapon) 'missiles)
									(xmlGetAttrib theXML 'charges)
									))
								True
							)
                            ;The weapon must have infinite ammo
                            (block (halfValue halfMass)
								;Add charges to the item
									;it's not added to the right spot
                               (xmlSetAttrib theXML 'charges "500")
							
                               ;Make the weapon use charges
                               (xmlSetAttrib (xmlGetSubElement theXML 'weapon) 'charges "true")
							   
							   ;Halve the value of the item
                               (xmlSetAttrib theXML 'value (setq halfValue (cat (divide (int (xmlGetAttrib theXML 'value)) 2))))
                               
                               ;Halve the mass of the item
                               (xmlSetAttrib theXML 'mass (setq halfMass (cat (divide (int (xmlGetAttrib theXML 'mass)) 2))))
                               
                               ;Add value bonus to item
                               (xmlSetAttrib theXML 'valueBonusPerCharge (cat (divide halfValue 500)))
                               
                               ;Add mass bonus to item
                               (xmlSetAttrib theXML 'massBonusPerCharge (cat (divide halfMass 500)))
                               
							   (typCreate (typDynamicUNID (cat "uniquestring" (add (TypGetData &vtWeaponizer; "i") 1))) theXML) ;theType
							   (TypSetData &vtWeaponizer; "i" (add (TypGetData &vtWeaponizer; "i") 1))
							   
							   ;;check out the XML:
							   (PrintTo 'log "checking weapon XML generation")
							   (PrintTo 'log theXML)
							   
                               )
                            )
                         ))
                   )
             </OnGlobalUniverseCreated>
Tutorial List on the Wiki and Installing Mods
Get on Discord for mod help and general chat
Image
Image
Der Tod ist der zeitlose Frieden und das leben ist der Krieg
Wir müssen wissen — wir werden wissen!
I don't want any sort of copyright on my Transcendence mods. Feel free to take/modify whatever you want.
RPC
Fleet Admiral
Fleet Admiral
Posts: 2876
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

Update:
1. My bad on the OnGlobalUniverseCreated vs OnGlobalTypesInit. You really do need OnGlobalTypesInit to override everything in the game. The problem is that apparently only Typfind works in OnGlobalTypesInit but once you get the right checks you can just do the same thing as earlier and it works, overriding everything not a launcher or energy weapon to have 500 charges.

Code: Select all

(block Nil
					;(PrintTo 'log "check typfind")
					;(PrintTo 'log (Typfind "i"))
					;set index here:
					  (TypSetData &vtWeaponizer; "i" 0)
					(enum (Typfind "i") theUNID (block Nil
						;check if it's a primary weapon (not a launcher)
						;check if it's not an energy weapon
						;(PrintTo 'log "check name")
							;(PrintTo 'log (typGetDataField theUNID 'name))
						;(PrintTo 'log "check weapon")
							;(PrintTo 'log (eq (itmGetProperty (itmcreate theUNID 1) 'category) "weapon"))
						;(PrintTo 'log "check not launcher")
							;(PrintTo 'log (not(typGetProperty theUNID 'launcher)))
						;(PrintTo 'log "check not energyweapon")
							;(PrintTo 'log (not(itmHasAttribute (itmCreate theUNID 1) "energyWeapon")))
						(if
							(and
								(eq (itmGetProperty (itmcreate theUNID 1) 'category) "weapon")
								(not (typGetProperty theUNID 'launcher))
								(not (itmHasAttribute (itmCreate theUNID 1) "energyWeapon"))
								)
								(block (theType theXML)
									 ;Converts the itemStruct to the UNID and then to the XML
									 (setq theXML (typGetXML theUNID))
									 (PrintTo 'log "checking OG weapon XML generation")
									(PrintTo 'log theXML)
									 
									(if
										 (or
											(not(or
											   (xmlGetSubElement (xmlGetSubElement theXML 'weapon) 'missiles)
											   (xmlGetAttrib theXML 'charges)
											   ))
											True
										 )
										;The weapon must have infinite ammo
										(block (halfValue halfMass)
									;Add charges to the item
									   ;it's not added to the right spot
										   (xmlSetAttrib theXML 'charges "500")
								 
										   ;Make the weapon use charges
										   (xmlSetAttrib (xmlGetSubElement theXML 'weapon) 'charges "true")
									
									;Halve the value of the item
										   (xmlSetAttrib theXML 'value (setq halfValue (cat (divide (int (xmlGetAttrib theXML 'value)) 2))))
										   
										   ;Halve the mass of the item
										   (xmlSetAttrib theXML 'mass (setq halfMass (cat (divide (int (xmlGetAttrib theXML 'mass)) 2))))
										   
										   ;Add value bonus to item
										   (xmlSetAttrib theXML 'valueBonusPerCharge (cat (divide halfValue 500)))
										   
										   ;Add mass bonus to item
										   (xmlSetAttrib theXML 'massBonusPerCharge (cat (divide halfMass 500)))
										   
									;(typCreate (typDynamicUNID (cat "uniquestring" (add (TypGetData &vtWeaponizer; "i") 1))) theXML) ;theType
									(typCreate theUNID theXML) ;theType
									(TypSetData &vtWeaponizer; "i" (add (TypGetData &vtWeaponizer; "i") 1))
									
									;;check out the XML:
									;(PrintTo 'log "checking weapon XML generation")
									;(PrintTo 'log theXML)
									
									;(PrintTo 'log "checking OG weapon XML")
									;(PrintTo 'log (typGetXML (setq theType (itmGetType theWeapon ))))
										   )
										)
									 )
							)
						))
				   )
Tutorial List on the Wiki and Installing Mods
Get on Discord for mod help and general chat
Image
Image
Der Tod ist der zeitlose Frieden und das leben ist der Krieg
Wir müssen wissen — wir werden wissen!
I don't want any sort of copyright on my Transcendence mods. Feel free to take/modify whatever you want.
Post Reply