*RESOLVED* Capture the damage received from the player?

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
Kominate
Posts: 19
Joined: Fri Apr 12, 2019 6:24 pm
Contact:

*RESOLVED* Capture the damage received from the player?

Post by Kominate »

I'm currently making a human monster pack and I have an actor called "FI_DefaultArmor" that I use to apply armor to the enemies' torsos.

Armor code

Code: Select all

class FI_DefaultArmor : Actor
{
	Default
	{
	alpha 0.9;
	health 1000;
	height 45;
	mass 5;
	painChance 256;
	radius 16;
	renderStyle "add";
	scale 0.5;
        +isMonster;
        +shootable;
	+noBlood;
        +noGravity;
	+thruActors
        -countKill;
	}
	States
	{
	spawn:
        TNT1 A 1 A_warp(AAPTR_MASTER);
	loop;
	see:
	TNT1 A 1 A_warp(AAPTR_MASTER);
	loop;
	pain:
	TNT1 A 1 
	{
	A_pain;
	A_warp(AAPTR_MASTER);
	A_startSound("E/NP/AAJ/ARMORHITA",6,CHANF_DEFAULT,1.0,ATTN_NORM,0,0);
	A_damageMaster(10);
	}
	goto see;
	death:
	TNT1 A 1 A_noBlocking();
	TN11 A -1;
	stop;
	}
}
Place where I apply it

Code: Select all

	spawn:
	TNT1 A 0 NoDelay
	{
	NPC_bulletCount = 7;
	NPC_grenadeCount = 20;
	NPC_retreatCount = 3;
	A_spawnItemEx("FI_DefaultArmor",0,0,0,0,0,0,0,SXF_SETMASTER);
	[active,alert,death,pain,burning,scream,reload] = random_voicePicker();
	activeSound = active;
	seeSound = alert;
	deathSound = death;
	painSound = pain;
	}
It works fine as the enemy receives the damage I gave it on A_damageMaster() but i'm not sure how to get the damage that he receives from the player. Looking through the sources, I saw that I could get it from DamageMobJ but I wasn't sure how to call it inside A_damageMaster().

Video of it in action:
https://imgur.com/a/cK4Y1Sp
Last edited by Kominate on Mon Mar 31, 2025 7:44 am, edited 1 time in total.
Kominate
Posts: 19
Joined: Fri Apr 12, 2019 6:24 pm
Contact:

Re: Capture the damage received from the player?

Post by Kominate »

All good, just did it like this and it worked as the enemy takes reduced damage from everything the player throws at him.

Code: Select all

class FI_DefaultArmor : Actor
{
	//Stores the damage received from the player
	int damageTaken;
	
	/*Overrides the DamageMobJ function to obtain the damage from player*/
	override int damageMobJ(Actor attacker, Actor victim, int damage,Name mod,int flags, double angle)
	{
		damageTaken = damage/3;
		return super.DamageMobj(attacker, victim, damage, mod, flags, angle);
	}
	
	
	Default
	{
		alpha 0.9;
		health 1000000;
		height 56;
		mass 5;
		painChance 256;
		radius 16;
		renderStyle "add";
		scale 0.5;
        +isMonster;
        +shootable;
		+noBlood;
        +noGravity;
		+thruActors
        -countKill;
	}
	States
	{
	/*========================================================Spawn========================================================*/
	spawn:
        TNT1 A 1 A_warp(AAPTR_MASTER);
		loop;
	/*========================================================See========================================================*/
	see:
		TNT1 A 1 A_warp(AAPTR_MASTER);
		loop;
	/*========================================================Pain========================================================*/
	pain:
		TNT1 A 1 
		{
		A_pain;
		A_warp(AAPTR_MASTER);
		A_startSound("E/NP/AAJ/ARMORHITA",6,CHANF_DEFAULT,1.0,ATTN_NORM,0,0);
		A_damageMaster(damageTaken);
		}
		goto see;
	/*========================================================Death========================================================*/
	death:
		TNT1 A 1 A_noBlocking();
		TN11 A -1;
		stop;
	}
}
Post Reply

Return to “Scripting”