Modding weapons

Freeform discussion about anything related to modding Transcendence.
Post Reply
Novak 67
Miner
Miner
Posts: 40
Joined: Wed Mar 11, 2015 1:46 pm
Location: Training himself to create better mods

As mention on top, this forum mentions about modding weapons, currently I only need help for a small detail, I need a function that when the there omnidirectional turret exceeds a certain range, it stops shooting or when it stops swivelling to a target, also one detail, the weapon does not shot when there is no target.

Also I want to get help from this as well, I want a weapon that simply has 4 omnidirectional turrets into one gun, so all turrets can simply focus to one target.

The code for the gun is mentioned below:

Code: Select all

	<ItemType UNID="&itexclusion;"
		name=		"weapon(s) named "exclusion""
		attributes=	"commonwealth, energyWeapon, majorItem, kabuto"
		level=		"1"
		frequency=	"common"
		value=		"1"
		mass=		"1"
		description=	"This weapon fires 4 independently directed ion beams that fire in a expanding formation."
		>

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

		<Weapon
			type=		"beam"
			omnidirectional="true"
			damage=		"ion:2d2+1"
			fireRate=	"5"
			lifetime=	"20"
			powerUse=	"10"
			effect=		"&efIonBeamDefault;"
			hitEffect=	"&efDriHitDefault;"
			sound=		"&snLaserCannon;"
			>

			; Fires 4 times!
			<Configuration aimTolerance="5">
				<Shot/> <Shot/> <Shot/> <Shot/>
			</Configuration>
		</Weapon>

	</ItemType>
PM
Fleet Admiral
Fleet Admiral
Posts: 2570
Joined: Wed Sep 01, 2010 12:54 am

Is this the same weapon you are trying to make in your other "...Firing 4 projectiles, into one target " topic, including turret placement?

You want one of us to post custom <OnFireWeapon> code to do what you ask?

The weapon does not fire when no targets are within "certain range"? What is the "certain range"? Range 30 is the maximum targeting range for standard omnidirectional weapons.

What are eligible targets? Enemies only (red only)? Anyone who is shooting at you (red and angry green)? Ships only? Ships and stations? Missiles too?

Do you want to check for friendly fire, and not target an enemy if a friendly is in the line of fire?

It should not take much for me to adapt Phaser/DDT code to do what you want.
Download and Play in 1.9 beta 1...
Drake Technologies (Alpha): More hardware for combat in parts 1 and 2!
Star Castle Arcade: Play a classic arcade game adventure, with or without more features (like powerups)!
Playership Drones: Buy or restore exotic ships to command!

Other playable mods from 1.8 and 1.7, waiting to be updated...
Godmode v3 (WIP): Dev/cheat tool compatible with D&O parts 1 or 2.
Novak 67
Miner
Miner
Posts: 40
Joined: Wed Mar 11, 2015 1:46 pm
Location: Training himself to create better mods

PM wrote:Is this the same weapon you are trying to make in your other "...Firing 4 projectiles, into one target " topic, including turret placement?

You want one of us to post custom <OnFireWeapon> code to do what you ask?
Yep.
PM wrote: The weapon does not fire when no targets are within "certain range"? What is the "certain range"? Range 30 is the maximum targeting range for standard omnidirectional weapons.
The certain range is the omnidirectional range, of 30. for the swivelling option below, but if it is omnidirectional, then 20 because I do not want an over powered weapon.
PM wrote: What are eligible targets? Enemies only (red only)? Anyone who is shooting at you (red and angry green)? Ships only? Ships and stations? Missiles too?

Do you want to check for friendly fire, and not target an enemy if a friendly is in the line of fire?
The certain targets are enemies and angry greens. and it will always target those.
PM wrote:It should not take much for me to adapt Phaser/DDT code to do what you want.
Well, I will try not to copy your DDT stuff since I do not like to be similar. But for this weapon, I want the weapon to simply have four swivelling turrets that every turret can turn only 135º limit with 45º degrees of it overlapping 2 of the 4 turrets. The purpose of this weapon is to simply make every ship a battleship.

Here is the weapon code that I want to become like that above:

Code: Select all

<ItemType UNID="&itexclusion;"
		name=		"weapon(s) named "exclusion""
		attributes=	"commonwealth, energyWeapon, majorItem, kabuto"
		level=		"1"
		frequency=	"common"
		value=		"1"
		mass=		"1"
		description=	"This weapon fires 4 independently omnidirectional ion beams that fire in a expanding formation."
		>

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

		<Weapon
			type=		"beam"
			omnidirectional="true"
			damage=		"ion:2d2+1"
			fireRate=	"5"
			lifetime=	"20"
			powerUse=	"10"
			effect=		"&efIonBeamDefault;"
			hitEffect=	"&efDriHitDefault;"
			sound=		"&snLaserCannon;"
			>

			; Fires 4 times!
			<Configuration aimTolerance="5">
				<Shot/> <Shot/> <Shot/> <Shot/>
			</Configuration>
		</Weapon>
PM
Fleet Admiral
Fleet Admiral
Posts: 2570
Joined: Wed Sep 01, 2010 12:54 am

I can't type much now. Try this out and tell me if it's what you want.

Code: Select all

<?xml version="1.0" ?>
<!DOCTYPE TranscendenceExtension
[
	<!ENTITY unid912Exclusion	"0xd912fff0">
	<!ENTITY it912Exclusion		"0xd912fff1">
	<!ENTITY ef912BlockedFire	"0xd912fff2">
]>

<TranscendenceExtension UNID="&unid912Exclusion;"
	name=		"Exclusion"
	apiVersion=	"25"
	credits=	"Coding by PM; done on behalf of Novak 67"
>

	<Globals>
		(block Nil
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
			; This function is a bit too big to squeeze into OnFireWeapon and still have the code readable for my tastes.
			; Thus, placed in Globals.

			(setq exclusion912Fire (lambda Nil
				(block (broken  centerAngle  theAngle theVel theWeaponType  shotSpeed  allPos posList  allTargets  shotsFired)
					(setq exclusion912VectorPolarPixelOffset (lambda (theCenter theAngle thePixels)
						; range 1 = 24 pixels.
						(sysVectorAdd theCenter (sysVectorDivide
							(sysVectorSubtract (sysVectorPolarOffset theCenter theAngle thePixels) theCenter)
							24
						))
					))

					(setq broken  (or (itmGetProperty gItem 'damaged) (itmGetProperty gItem 'disrupted)) )

					; Get direction where weapon is pointed - useful when ships don't point guns forward, like Luminous drones.
					(setq centerAngle (@ (objGetItemProperty gSource gItem 'pos) 0))
					(if (not centerAngle) (setq centerAngle 0))

					; If attacker mounted weapon to face non-forward, we need to use that.
					(setq theAngle (add (objGetProperty gSource 'rotation) centerAngle))

					; Remember our velocity because we will use that multiple times.
					(setq theVel (objGetVel gSource))

					; Get some weapon stats.
					(setq theWeaponType aWeaponType)
					(setq shotSpeed (typGetDataField theWeaponType "speed"))

					(setq allPos (list
						; #1, front and left
						(list 90 12 0  337 112)

						; #2, rear and left
						(list 135 12 0  67 202)

						; #3, rear and right
						(list 225 12 0  157 292) 

						; #4, front and right
						(list 270 12 0  247 22)
					))

					; We map positions to where they really are.
					(setq posList Nil)
					(enum allPos thisPos
						(setq posList (lnkAppend posList
							(list	(exclusion912VectorPolarPixelOffset
									aFirePos
									(modulo	'degrees (add theAngle (@ thisPos 0)) 360)
									(@ thisPos 1)
								)

								(modulo	'degrees (add theAngle (@ thisPos 3)) 360)

								(modulo	'degrees (add theAngle (@ thisPos 4)) 360)
							)
						))
					)

					; Find some targets!  Sort all visible targets within range 30 by distance.
					; We take active red enemies and angry greens.
					; Also include playership's target - we may want to shoot a friendly, such as any thief!
					(setq allTargets (filter
						(sysFindObject gSource (cat "s T N:30 P S:d;"))
						thisOne
						(or	(and	(objIsEnemy gSource thisOne)
								(not (objGetProperty thisOne 'abandoned))
							)
							(and	(objIsAngryAt thisOne gSource)
								(or	(not (objIsShip thisOne))
									; Ferian miners use the mine command - they do not shoot at the player despite feeling angry at times.
									(neq (shpGetOrder thisOne) 'mine)
								)
								(not (objGetProperty thisOne 'abandoned))
							)
							(and	(eq gSource gPlayerShip)
								(eq (objGetTarget gPlayerShip) thisOne)
								; We'll take our target, dead or alive!
							)
						)
					))

					(setq shotsFired 0)

					; Cycle through all targets, and fire beams as necessary.
					(enum posList thisGun (block (thisPos minArc maxArc  theFireAngle who)
						(setq thisPos (@ thisGun 0))
						(setq minArc (@ thisGun 1))
						(setq maxArc (@ thisGun 2))

						(setq theFireAngle Nil)
						(setq who Nil)

						(if allTargets
							; YES:  We have targets to shoot at!
							(block (thisWay)
								; Checks of 'theInput' is within firing arcs defined by 'lo' and 'hi'.
								(setq inTheArc (lambda (theInput lo hi)
									(switch
										(ls lo hi)
											(if (and (geq theInput lo) (leq theInput hi)) True Nil)
										(gr lo hi)
											(if (or (geq theInput lo) (leq theInput hi)) True Nil)
										(if (eq theInput lo) True Nil)
									)
								))

								; Cycle through all targets.
								(enum allTargets thisOne
									(if	(and	(not theFireAngle)
											(setq thisWay (sysCalcFireSolution
												(sysVectorSubtract (objGetPos thisOne) thisPos)
												(sysVectorSubtract (objGetVel thisOne) theVel)
												shotSpeed
											))
											(inTheArc thisWay minArc maxArc)
										)
										; YES:  Fire!
										(block (offSet)
											; Check for bad aim caused by damage.  Do this for each turret.
											(setq offSet
												; If the weapon is broken, distort aim half of the time.
												(if (and (eq (random 0 1) 0) broken)
													; YES:  Distortion
													(random -60 60)

													; NO:  Normal aim
													0
												)
											)
											; We have a firing angle, and we will fire.
											(setq theFireAngle (modulo 'degrees (add thisWay offSet) 360))

											; Remember who we fire at so we can move him to the end of the target list later.
											(setq who thisOne)
										)
										; NO:  No aim solution.
									)
								)

								(if (and who (gr (count allTargets) 1) )
									; YES:  Move current target to the end of the list, so followup shots target it last.
									(setq allTargets (lnkAppend
										(filter allTargets thisTarget (neq thisTarget who) )
										who
									))
									; NO:  Leave the list alone.
								)
							)

							; NO:  No one to fire at!
						)

						; Do we fire a beam?
						(if theFireAngle
							; YES:  Make this turret fire a beam.
							(block Nil
								; Count how turrets have fired.
								(setq shotsFired (add shotsFired 1))

								; Fire our beam, and make it inherit our source velocity.
								(objIncVel (sysCreateWeaponFire theWeaponType gSource thisPos theFireAngle shotSpeed aTargetObj Nil aWeaponBonus) theVel)
							)

							; NO:  Throw some sparks to show this turret did not fire.
							(sysCreateEffect &ef912BlockedFire; gSource thisPos)
						)
					))

					; Play weapon sound here once, if necessary.
					(if (geq shotsFired 1)
						; YES:  Play our weapon firing sound.  Only need to play it once -
						;  that's why we play it here after counting turrets that fired.
						(sysPlaySound &snLaserCannon; gSource)

						; NO:  No turrets fired.  Should play a subtle buzz or something.
						;  None of the standard sounds have anything appropriate - import your own!
					)

					; Fired already, return non-Nil.
					0
				)
			))
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		)
	</Globals>


	; A subtle effect for when turrets cannot fire because no target is within its fire arc.
	<Effect UNID="&ef912BlockedFire;">
		<Flare   style="fadingBlast"  radius="8"  primaryColor="#a0f0ff"  secondaryColor="#00a9ff"  lifetime="4"/>

		<ParticleCloud    style="splash"  lifetime="10"  emitDuration="5"  emitRate="5"  emitSpeed="2-5"  particleLifetime="5" >
			<ParticleEffect>  <Particle    style="plain"  minWidth="1"  maxWidth="3"  primaryColor="#a0f0ff"  secondaryColor="#00a9ff" />  </ParticleEffect>
		</ParticleCloud>
	</Effect>


	; With 40 DPS per turret, and assuming two out of four turrets firing, that means 80 DPS.
	; We will assume 80 DPS for balance decisions.  I will treat it as level 9.

	; noArticle="true" removes "a" or "an" before the name.
	<ItemType UNID="&it912Exclusion;"
		name=		"Exclusion"
		noArticle=	"true"
		attributes=	"commonwealth, energyWeapon, kabuto, majorItem, military"
		level=		"9"
		frequency=	"notrandom"
		value=		"200000"
		mass=		"12000"
		description=	"This weapons system mounts four swiveling ion cannons, each with a firing arc of 135 degrees.  Together, they provide full and sometimes overlapping coverage."
		>

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

		; NPC ships need omnidirectional="true" to fire this like other omnidirectional weapons.
		; No sound in Weapon tag because we play it during OnFireWeapon event.
		<Weapon
			type=		"beam"
			omnidirectional="true"
			damage=		"ion:2d2+1"
			fireRate=	"6"
			lifetime=	"20"
			powerUse=	"2500"
			effect=		"&efIonBeamDefault;"
			>

			; There are four shots within configuration - count them!
			<Configuration aimTolerance="5">
				; The first shot fires all of our beams.
				<Shot/>

				; The rest here are dummies to make the item picker display (x4) infront of average damage stat.
				<Shot/> <Shot/> <Shot/>
			</Configuration>
		</Weapon>

		<Events>
			<OnFireWeapon>
				; This will be called once per shot found within Configuration.
				; We have four in configuration, and this will be called four times.
				(block (theCharges)
					; Remember for later, because we will update gItem before we shoot beams.
					(setq theCharges (itmGetProperty gItem 'charges))

					; Update item for the next shot.
					; Divisor should equal the number of shots in Configuration.
					(setq gItem (objSetItemProperty gSource gItem 'charges (modulo (add theCharges 1) 4) ))

					(if (eq theCharges 0)
						; YES:  First shot in configuration - Fire!  This should return a not-Nil value.
						(exclusion912Fire)

						; NO:  Second, third, or forth shot in configuration.
						;  Don't fire, but we still need to return not-Nil to override attack.
						0
					)
				)
			</OnFireWeapon>

			<OnInstall>
				; Make sure charges are reset so that firing occurs in the proper order.
				(setq gItem (objSetItemProperty gSource gItem 'charges 0))
			</OnInstall>

			<OnUninstall>
				; Remove all charges to let items stack.  Good for smaller lists, and good to enforce buying limits.
				(setq gItem (objSetItemProperty gSource gItem 'charges 0))
			</OnUninstall>
		</Events>
	</ItemType>

</TranscendenceExtension>
Download and Play in 1.9 beta 1...
Drake Technologies (Alpha): More hardware for combat in parts 1 and 2!
Star Castle Arcade: Play a classic arcade game adventure, with or without more features (like powerups)!
Playership Drones: Buy or restore exotic ships to command!

Other playable mods from 1.8 and 1.7, waiting to be updated...
Godmode v3 (WIP): Dev/cheat tool compatible with D&O parts 1 or 2.
Post Reply