Need some help with projectile heal-on-hit

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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!)
User avatar
yahahaoi
Posts: 2
Joined: Tue Aug 25, 2026 8:10 pm
Preferred Pronouns: He/Him

Need some help with projectile heal-on-hit

Post by yahahaoi »

(sorry, I am pretty new to Zscript modding, still pretty bad with this)

so, I am trying to figure out how to make a high fire rate projectile weapon that heals the player slightly on hit.
I've tried a couple times but nothing has worked and it usually just crashes the game as soon as I launch it..
its led to some funny results, but I'm just trying to make it work at this point.
do any of y'all know what I could do to make this work? thanks!

here is the code for the projectile:

Code: Select all

class HealProj : Actor
{
	Default
	{
		Radius 4;
		Height 4;
		Speed 20;
		Damage 3;
		PROJECTILE;
	}
	States
	{
	Spawn:
		HEAL A 5;
		Loop;
	Death:
		HEAL B 3;
		HEAL C 3;
		HEAL D 3;
		TNT1 A 0;
		Stop;
	XDeath:
		HEAL B 3;
		HEAL C 3
		{
			if (target is Monster)
			{
				GiveBody(4, 65);
			}
		}
		TNT1 A 0;
		Stop;
	Crash:
		HEAL B 3;
		HEAL C 3;
		HEAL D 3;
		TNT1 A 0;
		Stop;
	}
}
Jarewill
 
 
Posts: 1871
Joined: Sun Jul 21, 2019 8:54 am

Re: Need some help with projectile heal-on-hit

Post by Jarewill »

What exactly are you trying to do?

I assume the projectile is fired by the player and checks if it hit a monster before healing.
For a projectile to get a pointer to whatever it hit, you need to give it the +HIT(pointer) flags like +HITTARGET or +HITTRACER.
However since by default the projectile stores the owner as the target, I recommend using +HITTRACER.
To check if an actor is a monster, you have to check for the ISMONSTER flag, unless all your monsters inherit from a custom Monster base class, in which case your solution would also work.

The healing code would look like this:

Code: Select all

HEAL C 3 {
	If(target && tracer && tracer.bISMONSTER){ //Sanity checks if the projectile owner and hit enemy exist
		target.GiveBody(4,65); //Call the GiveBody function from the target pointer (projectile owner)
	}
}
For this code to work, your projectile also needs the +HITTRACER flag set.
User avatar
Rabbitslayer1
Posts: 15
Joined: Sun Dec 15, 2024 12:05 pm
Preferred Pronouns: He/Him

Re: Need some help with projectile heal-on-hit

Post by Rabbitslayer1 »

You also have to change line to this

if ("target is Monster")

needed quotation marks
Jarewill
 
 
Posts: 1871
Joined: Sun Jul 21, 2019 8:54 am

Re: Need some help with projectile heal-on-hit

Post by Jarewill »

Rabbitslayer1 wrote: Thu Aug 27, 2026 10:03 am You also have to change line to this

if ("target is Monster")

needed quotation marks
You are correct that the code needed quotation marks, however not in the way you provided.
For an "is" check, you only need to quote the class you compare the pointer with, in this case only "Monster" should be in quotation marks.
If you quote the entire If check, then it will instantly fail due to not having any formula inside it.
User avatar
Rabbitslayer1
Posts: 15
Joined: Sun Dec 15, 2024 12:05 pm
Preferred Pronouns: He/Him

Re: Need some help with projectile heal-on-hit

Post by Rabbitslayer1 »

That was how I got it working though
It didnt heal anything but it did shoot
and i killed a monster with it
Jarewill
 
 
Posts: 1871
Joined: Sun Jul 21, 2019 8:54 am

Re: Need some help with projectile heal-on-hit

Post by Jarewill »

Then that's not really working if it didn't do what it was supposed to.
As I said, the check will fail because there's no valid formula inside it, so no code will execute.
User avatar
yahahaoi
Posts: 2
Joined: Tue Aug 25, 2026 8:10 pm
Preferred Pronouns: He/Him

Re: Need some help with projectile heal-on-hit

Post by yahahaoi »

Jarewill wrote: Thu Aug 27, 2026 6:57 am What exactly are you trying to do?

I assume the projectile is fired by the player and checks if it hit a monster before healing.
For a projectile to get a pointer to whatever it hit, you need to give it the +HIT(pointer) flags like +HITTARGET or +HITTRACER.
However since by default the projectile stores the owner as the target, I recommend using +HITTRACER.
To check if an actor is a monster, you have to check for the ISMONSTER flag, unless all your monsters inherit from a custom Monster base class, in which case your solution would also work.

The healing code would look like this:

Code: Select all

HEAL C 3 {
	If(target && tracer && tracer.bISMONSTER){ //Sanity checks if the projectile owner and hit enemy exist
		target.GiveBody(4,65); //Call the GiveBody function from the target pointer (projectile owner)
	}
}
For this code to work, your projectile also needs the +HITTRACER flag set.
worked perfectly, thanks a million!

Return to “Scripting”