Opt in to damage?

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
Enjay
 
 
Posts: 26533
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Opt in to damage?

Post by Enjay »

Is there any easy way to make enemies "opt in" to being damaged by a particular custom type and otherwise default to not being damaged by it?

To explain, as far as I know, the usual way to make custom damage types affect some actors and not others is to set the damage factor for the different actors that I do not want to be affected as zero.

e.g.if I wanted to make a zombie killing bomb, I could give it a custom damage type of "zombieblast" and then I would have to set every actor in the game that is not one of the former humans to not take damage from the "zombieblast" damage type. i.e. I'd have to edit every monster in the game except the zombies.

What I'm asking for is some way to set a damage type to be opt-in. So, perhaps, the explosion instruction on the zombiebomb would have some sort of opt-in parameter to tell the game that only actors that are specifically set to be vulnerable to "zombieblast" would be affected. That way, all I would have to do is edit the zombieman, shotgunner and chaingunner and leave all other enemies alone. It would also mean that any custom enemies from add-ons were unaffected unless I specifically wanted to edit them too.

So, is this possible?
User avatar
Rachael
Posts: 13542
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Opt in to damage?

Post by Rachael »

When the enemy spawns, you can give an unlimited powerup that grants immunity to that damage type (extending from PowerProtection) and when you want the enemy to become vulnerable, remove the PowerProtection.

To give the powerup you'll need to use a PowerupGiver, and then to take it you have to take the actual power item, not the giver.
User avatar
Dan_The_Noob
Posts: 872
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Opt in to damage?

Post by Dan_The_Noob »

I was after this same thing recently, trying to make bosses able to infight in my mod without taking forever to kill or jus getting straight wrecked by plebs.
User avatar
Enjay
 
 
Posts: 26533
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Opt in to damage?

Post by Enjay »

Rachael wrote:When the enemy spawns, you can give an unlimited powerup that grants immunity to that damage type (extending from PowerProtection) and when you want the enemy to become vulnerable, remove the PowerProtection.

To give the powerup you'll need to use a PowerupGiver, and then to take it you have to take the actual power item, not the giver.
I'm not sure if that answers what I was asking - or, if it does, I don't follow. Or perhaps I wasn't clear.

What I'm trying to do is avoid having to edit every enemy to make them invulnerable to a type of damage that only a small subset of enemies should be vulnerable to. The enemies in the subset should never be invulnerable to the particular damage type, all other enemies should always be immune to it.



Hmmm... thinking about your suggestion, did you mean that I could use some ZScript magic to unconditionally give every enemy the new powerup and then do something like "if actortype = zombieman, remove powerup" (also in ZScript)?
User avatar
Rachael
Posts: 13542
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Opt in to damage?

Post by Rachael »

You can indeed give the givers to each enemy as they spawn in ZScript, and discriminate by actor type.

You would have to use event handlers to give the enemies items. Example ZScript:

Code: Select all

version "4.3"

class MyImmunityHandler : EventHandler
{
	override void WorldThingSpawned(WorldEvent e)
	{
		let me=e.Thing;
		if(!(me is "PlayerPawn"))
			me.A_GiveInventory("YourPowerupGiver");
	}
}
Then in your mapinfo:

Code: Select all

gameinfo
{
	AddEventHandlers="MyImmunityHandler"
}
User avatar
Enjay
 
 
Posts: 26533
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Opt in to damage?

Post by Enjay »

Thank you. I'll have a play around with that to see if I can get it working.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Opt in to damage?

Post by Matt »

Alternatively, instead of the usual projectile/melee attack/explosion functions you can do a custom one that calls DamageMobj but only if the particular victim fulfills the criteria.
Post Reply

Return to “Scripting”