Instant death to player when shooting a certain actor

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
User avatar
AshHouswares
Posts: 145
Joined: Fri Jun 03, 2022 11:31 am
Graphics Processor: Not Listed

Instant death to player when shooting a certain actor

Post by AshHouswares »

I need some help. I have an actor (an NPC not a monster). It has infinite health with no health defined in the zscript. I need to make it so that if player is scummy enough to shoot a bullet at this actor, the player is instantly obliterated, killed and gibbed into a million pieces. How can I implement this? The player pawn isn't really suitable because that just acts as a duplicate with equal health and takes multiple shots to kill. I need this to be INSTANT death by GIBBING if they even fire a SINGLE SHOT at this NPC.

Any advice please? Thanks.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Instant death to player when shooting a certain actor

Post by Jarewill »

With ZScript you can override the actor's DamageMobj virtual to instead deal damage to whoever damaged it:

Code: Select all

	Override int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags, double angle){
		If(source.player){source.DamageMobj(self,self,999,"Extreme",DMG_THRUSTLESS);} //If a player damaged it, kill them
		Return 0; //Deal no damage to the actor itself
	}
I just hope you know what you are doing with this, because a thing like this can get very frustrating to the player if misused. :?
User avatar
AshHouswares
Posts: 145
Joined: Fri Jun 03, 2022 11:31 am
Graphics Processor: Not Listed

Re: Instant death to player when shooting a certain actor

Post by AshHouswares »

It's being used only for one single NPC. A little animal in an area with no enemies or any reason to fire a gun. Anyone that decides they want to shoot an animal for no reason deserves all they get. I suppose I could (if it is possible) lock the players ability to use weapons in their sector as an alternative. But I think if they wish to shoot in the first place. They deserve to be gibbed.

So will this method work even if the NPC has no health at all? Ie; is invincible? Currently they have no health or pain states in their code. Complete invulernable. Also where would I put this is and how to implement it? I assume in the maps script box but I'm a little at loss with this one sorry.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Instant death to player when shooting a certain actor

Post by Jarewill »

The only thing this needs to work is for the actor to have the +SHOOTABLE flag set.
Then you just drop off the code I provided anywhere in your actor's code outside any other blocks. (Outside Default and States)
So it would look something like this:

Code: Select all

Class Thing : Actor{
	Default{
	}
	States{
	}
	//Code I provided goes here
}
I will note that even if you don't define health in the Default block, it will default to 1000 health, as that's specified in the base Actor class.
However the function I provided will make sure the NPC won't take any damage at all, because of the Return 0;.
User avatar
AshHouswares
Posts: 145
Joined: Fri Jun 03, 2022 11:31 am
Graphics Processor: Not Listed

Re: Instant death to player when shooting a certain actor

Post by AshHouswares »

Ahhhh I get ya now. Thank you once again, so much. All the help you offered me you deserve a credit in the game by this point.
Post Reply

Return to “Scripting”