How do i make this detect enemies?

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!)
PartiallyInvisible
Posts: 12
Joined: Thu Sep 28, 2023 9:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: Intel (Modern GZDoom)

How do i make this detect enemies?

Post by PartiallyInvisible »

i have this state in my weapon and i want to make it enter the hit state when an enemy is hit, im new to this and im pretty sure there is a very simple solution to this but.

Code: Select all

AltFire:
		PUNG D 4; //we are gonna make this throw us forward later.
		PUNG D 0 A_CheckBlock("ChargeHit", CBF_SETTARGET, AAPTR_DEFAULT, radius + 1);
		Loop;		
	ChargeHit:
		PUNG A 4;
		PUNG B 6 A_CustomPunch(random(50,100),false,CPF_USEAMMO,"BulletPuff",60,0,0,"ArmorBonus","taunt");
		PUNG C 4;
		PUNG B 5;
		Goto Ready;
Heisanevilgenius
Posts: 95
Joined: Wed Dec 15, 2021 8:38 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: How do i make this detect enemies?

Post by Heisanevilgenius »

I have something similar to this that I got to work. This is a little hacky, but, I created a custom puff for the punch. In the custom puff actor's states, you can have separate states if you only want the effect to happen when you hit an actor, or a wall or such.

Then in the state you want the effect to happen you add this:

Code: Select all

A_RadiusGive("CustomInventory",64,RGF_PLAYERS,1);
This gives an item to the closest player within 64 map units. You can change the range if you need it to be larger.

Then you just have the weapon state check if the player has that inventory item:

Code: Select all

PUNG D 0 A_JumpIfInventory("CustomInventory",1,"Hit");
Make sure you have a frame that removes it from your inventory after, such as at the beginning of the Ready state.

Return to “Scripting”