Example mod: One-Hit Per Target Passthrough

This is a moderated forum that collects tutorials, guides, and references for creating Transcendence extensions and scripts.
Post Reply
PM
Fleet Admiral
Fleet Admiral
Posts: 2161
Joined: Wed Sep 01, 2010 12:54 am

Example mod: One-Hit Per Target Passthrough

Post by PM » Sat Oct 10, 2015 11:38 pm

This example mod adds a particle weapon that fires beams with 100% passthrough, but only hits each target once instead of multiple times. The weapon is installed on the playership at the start of a new game. The mod is fully functional and should work after a simple copy-and-paste to a blank xml file.

Code: Select all

<?xml version="1.0" ?>
<!DOCTYPE TranscendenceExtension
[
	<!ENTITY unid912Passthrough	"0xd912fffc">
	<!ENTITY it912Passthrough	"0xd912fffd">
]>

; Made for Transcendence v1.6.2 or later.
<TranscendenceExtension UNID="&unid912Passthrough;"
	apiVersion="28"
	name="One-Hit Per Target Passthrough Tutorial"
	credits="PM"
>

; Since we are using resources from the standard game, we need to include this library!
; Including libraries is the first thing we need to do before anything else in this file.
	<Library unid="&unidHumanSpaceLibrary;"/>

; Here are global function(s) we will use.
	<Globals>
		(block Nil
			; Helps prevent passthrough missiles from re-hitting target and doing too much damage.
			; This function is called within three separate events.
			(setq pass912OnDamage (lambda Nil
				(if (eq (objGetObjRefData aCause "d912_LastTargetHit") gSource)
					; YES:  Hit the previous target already, so return zero damage.
					;  Unfortunately, a hit that does no damage still aggravates whoever was hit.
					0

					; NO:  New target.  Standard damage procedure.
					(block Nil
						; Remember who we hit.
						(objSetObjRefData aCause "d912_LastTargetHit" gSource)

						; Return Nil to proceed with usual damage.
						Nil
					)
				)
			))
		)
	</Globals>

; This weapon was a copy of the particle beam weapon.
; Now heavily modified for our purposes.

; The weapon will be given for free at the start of a game.
; Value will be zero so that the player cannot sell for quick cash.
; We do not want this weapon to appear anywhere else.
; Frequency is notrandom, and attribute includes CannotOrder.

	<ItemType UNID="&it912Passthrough;"
			name=				"particle beam penetrator"
			attributes=			"cannotOrder, energyWeapon, majorItem"
			level=				"3"
			frequency=			"notrandom"
			value=				"0"
			mass=				"1500"

			description=		"Beams fired by this particle weapon can passthrough and hit multiple targets.  Each target takes damage only once, usually."
			>

		<Image imageID="&rsItemsEI2;" imageX="288" imageY="0" imageWidth="96" imageHeight="96"/>

		<Weapon
				type=				"beam"

				damage=				"particle:1d8+1"
				fireRate=			"16"
				lifetime=			"40"
				powerUse=			"50"
				passthrough=			"100"

				effect=				"&efParticleBeamDefault;"
				sound=				"&snLaserCannon;"
				>
		</Weapon>

		<Events>
		; Called when beam hits a planet, wreck, or other similar object.
			<OnDamageAbandoned>
				(pass912OnDamage)
			</OnDamageAbandoned>

		; Called when beam hits armor.
			<OnDamageArmor>
				(pass912OnDamage)
			</OnDamageArmor>

		; Called when beam hits shields.
			<OnDamageShields>
				(pass912OnDamage)
			</OnDamageShields>

		; Called when we start a new game, after ship select.
			<OnGlobalUniverseCreated>
				(block (newItem)
				; Create our gift.
					(setq newItem (itmCreate &it912Passthrough; 1))
				; Add the new weapon to ship's cargo hold.
					(objAddItem gPlayerShip newItem)
				; Install the weapon.
					(shpInstallDevice gPlayerShip newItem)
				)
			</OnGlobalUniverseCreated>
		</Events>
	</ItemType>

</TranscendenceExtension>
Download and Play in 1.7 Beta...
Playership Drones v7 (Beta): Acquire and command almost any ship in Stars of the Pilgrim or Eternity Port.
Drake Technologies (Alpha): More hardware for combat! (Stuff for part 2: VotG in development...)
Star Castle Arcade: Relive classic arcade gaming in a new Transcendence adventure!
Godmode v3 (WIP): Dev/cheat tool compatible with D&O parts 1 or 2.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest