tracer/projectile damage?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
powerup1
Posts: 6
Joined: Fri Dec 23, 2022 2:19 pm
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

tracer/projectile damage?

Post by powerup1 »

I've been racking my head with zscript for a few days trying to figure out how...

Code: Select all

extend class _ZTracer
{
	Default 
   {
		DamageFunction 0;
		Height 1;
		Radius 1;
		Speed 60;
		DamageType "GeneralDamage";
		+BLOODSPLATTER;
		+MISSILE;
		+PUFFONACTORS;
		+FORCERADIUSDMG;
		+RANDOMIZE;
		+HITMASTER;

	}
	States {
		Spawn:
			
			TNT1 A 1;
			loop;
		Death:
			
			TNT1 A 0 ;
			PUFF A 0 Bright;
			PUFF BBBBBBBBBBBBB 0 A_SpawnItemEx("CoolBulletPuff",0,0,0,random(-5,5),random(-5,5),random(-5,5));
			PUFF AABBCCDD 1 Bright;
			Stop;
		XDeath:                            \/
			QEX1 A 0 A_Explode(5 * random(1, 3), 3, 0, false, 30000);
			Stop;                      /\
To get the damage value of this bullet tracer...

Code: Select all

ACTOR SMG : Weapon replaces Pistol
{
	AttackSound "weapons/smg"
	Inventory.PickupSound "misc/w_pkup"
	Inventory.PickupMessage "$GOTSMG"
	//Inventory.RestrictedTo "PowerPlayer"
	Obituary "$OB_SMG"
	Weapon.AmmoType "Clip"
	Weapon.AmmoGive 0
	Weapon.AmmoUse 1
	Weapon.SlotNumber 2
	Weapon.Kickback 75
	Weapon.SisterWeapon "SuperSMG"
	Weapon.SelectionOrder 1900
	+WEAPON.WIMPY_WEAPON
	Tag "$TAG_SMG"
	
States
	{
		Select:
			SMGG A 1 A_Raise
			Loop
			
		Deselect:
			SMGG A 1 A_Lower
			Loop
			
		Ready:
			SMGG A 1 A_WeaponReady
			Loop
			
		Fire:
			SMGG A 1
			SMGG A 0 A_GunFlash               \/
			SMGG B 3 A_FireBullets(5.6, 0, 1, 8)
			SMGG CC 1 A_Refire                /\
			Goto Ready
To inherit the damage value of this SMG
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: tracer/projectile damage?

Post by Jarewill »

It's hard to tell what can be done with this code.
Nothing shows how the _ZTracer projectile even spawns, as the weapon's attack function doesn't do anything like that.

You need to show all relevant code here with whatever functions you use to spawn the projectile.
powerup1
Posts: 6
Joined: Fri Dec 23, 2022 2:19 pm
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Re: tracer/projectile damage?

Post by powerup1 »

Code: Select all

class BulletZPuff : BulletPuff replaces BulletPuff
{
	Default
	{
		+NODECAL;
		+PUFFONACTORS;
		+ALLOWTHRUFLAGS;
		+THRUACTORS;
		+ALWAYSPUFF;
		+PUFFGETSOWNER;
		+NOBLOOD;
		+BLOODLESSIMPACT;
		+SKYEXPLODE;
		+BOUNCEONWALLS;
		+USEBOUNCESTATE;
		-BLOODSPLATTER;
		-ALLOWPARTICLES;
		
		BounceType "Doom";
		VSpeed 0;
		DamageType "DummyDamage";
	}
	States
	{
	Spawn:
	Melee:
	Death:
	XDeath:	
	Death.Sky:
	Bounce.Wall:
		PUFF A 0 Bright NoDelay
		{
			//Console.printf("Spawned!");
			Vector2 ownerVec = Vec2To(target);
			double distance = ownerVec.Length();
			Actor oldtarget = target.target;
			target.target = master;
			//Console.printf("Distance %d",distance);
			let bullet = BulletPuff(target.A_spawnprojectile("_ZTracer"));
			target.target = oldtarget;
			
		}
		Stop;
	}
}

/*
	
	TRACER SYSTEM FOR ZSCRIPT 2.4 | APRIL 7TH 2017
	AUTHOR: (DENIS) BELMONDO
	
	USAGE: make a new class, inherit from _ZTracer and change the properties as
		   you wish.
	
	you may use this in your project. just leave this comment at the top of 
	this script and give credit please! thank you :^)
	
*/

class _ZTracer : FastProjectile
{

	const TRACERDURATION	= 1; // tics
	const TRACERFANCY		= 0; // fake bool
	const TRACERLENGTH		= 180.0; // float
	const TRACERSCALE		= 4.0; // float
	const TRACERSTEP		= 0.01; // float
	const TRACERFANCYSTEP	= 0.01; // float
	const TRACERACTOR		= "_ZTracerTrail"; // actor name

	float x1, y1, z1;
	float x2, y2, z2;
	
	// intentional briticism to avoid conflicts with "color" keyword.
	static const color colours[] = {
		"9b 5b 13",
		"af 7b 1f",
		"c3 9b 2f",
		"d7 bb 43",
		"ff ff 73",
		"ff ff 73"  /* appears twice so a segment of this color is longer
					than the others. */
	};
	
	// literally just stole this from wikipedia
	float lerp(float v0, float v1, float t) {
		return (1 - t) * v0 + t * v1;
	}
	
	override void BeginPlay()
	{
		// we don't want to lerp into weird coordinates
		x1 = pos.x;
		y1 = pos.y;
		z1 = pos.z;
		
		x2 = pos.x;
		y2 = pos.y;
		z2 = pos.z;
        Super.BeginPlay(); //Thanks to Player701!
        Speed = Cvar.FindCvar('cl_tracerbasespeed').GetInt();
	}
	
	override void Tick()
	{
		if (level.frozen || globalfreeze) return;
		
		x1 = pos.x;
		y1 = pos.y;
		z1 = pos.z;
		
		x2 = pos.x + vel.x / GetDefaultSpeed("_ZTracer") * TRACERLENGTH;
		y2 = pos.y + vel.y / GetDefaultSpeed("_ZTracer") * TRACERLENGTH;
		z2 = pos.z + vel.z / GetDefaultSpeed("_ZTracer") * TRACERLENGTH;
		
		if (TRACERFANCY == 0)
		{
			for(float i = 0; i < 1; i += TRACERSTEP) {
				A_SpawnParticle (
					colours[clamp(i * colours.Size(), 0, colours.Size() - 1)],
					SPF_FULLBRIGHT,
					TRACERDURATION,
					TRACERSCALE * i,
					0,
					(-pos.x) + lerp(x1, x2, i),
					(-pos.y) + lerp(y1, y2, i),
					(-pos.z) + lerp(z1, z2, i),
					0, 0, 0,
					0, 0, 0,
					1.0
				);
			} 
		}
		else
		{
			for(float i = 0; i < 1; i += TRACERFANCYSTEP) {
				A_SpawnItemEx (
					TRACERACTOR,
					(-pos.x) + lerp(x1, x2, i),
					(-pos.y) + lerp(y1, y2, i),
					(-pos.z) + lerp(z1, z2, i),
					0, 0, 0, 0,
					SXF_ABSOLUTEPOSITION
				);
			}
		}

		Super.Tick();
	}
	
}

extend class _ZTracer
{
	Default 
   {
		DamageFunction 0;
		Height 1;
		Radius 1;
		Speed 60;
		DamageType "GeneralDamage";
		+BLOODSPLATTER;
		+MISSILE;
		+PUFFONACTORS;
		+FORCERADIUSDMG;
		+RANDOMIZE;
		+HITMASTER;

	}
	States {
		Spawn:
			
			TNT1 A 1;
			loop;
		Death:
			
			TNT1 A 0 ;
			PUFF A 0 Bright;
			PUFF BBBBBBBBBBBBB 0 A_SpawnItemEx("CoolBulletPuff",0,0,0,random(-5,5),random(-5,5),random(-5,5));
			TNT1 A 0 A_PlaySound("bullet/ricochet", CHAN_WEAPON, 0.5, 0, 1.8);
			FRTB A 0 A_SpawnItemEx ("Wallsmoke", 0,0,0, 0,0,0, 0, 160, 64);
			NULL A 0 A_SpawnItemEx ("PUFFEffectSpawner", 0,0,0, 0,0,0, 0, 160);
			TNT1 A 0 A_SpawnProjectile("Ricochet2",0,0,Random(-180,180), 2, Random(-50,50));
			PUFF AABBCCDD 1 Bright;
			Stop;
		XDeath:
			QEX1 A 0 A_Explode(5 * random(1, 3), 3, 0, false, 30000);
			Stop;
		Crash:
			QEX1 A 0 A_Explode(5 * random(1, 3), 3, 0, false, 30000);
			Stop;
	}
}
Here's the most important parts of the tracer script
Post Reply

Return to “Scripting”