Page 1 of 1

Instant death to player when shooting a certain actor

Posted: Mon Sep 04, 2023 12:47 pm
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.

Re: Instant death to player when shooting a certain actor

Posted: Mon Sep 04, 2023 1:19 pm
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. :?

Re: Instant death to player when shooting a certain actor

Posted: Mon Sep 04, 2023 1:49 pm
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.

Re: Instant death to player when shooting a certain actor

Posted: Mon Sep 04, 2023 2:38 pm
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;.

Re: Instant death to player when shooting a certain actor

Posted: Mon Sep 04, 2023 3:56 pm
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.