Is it possible for attacks to give inventory items when they do 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!)
Heisanevilgenius
Posts: 35
Joined: Wed Dec 15, 2021 8:38 pm
Graphics Processor: nVidia (Modern GZDoom)

Is it possible for attacks to give inventory items when they do damage?

Post by Heisanevilgenius »

I've noticed that when you take poison damage, there's not really any visual indication you've been poisoned. You just sort of keep taking damage, which can be confusing if the player doesn't know what's causing it. I thought a good solution would be to give the player a powerup which tints the screen for a short period of time, similar to the radiation suit or berserk pack. But the only way I can figure out to give an inventory item to a player when they're hurt by an attack is if I use A_RadiusGive and add it to the monster/projectile/puff. This would give it to the actor closest to the monster or projectile at the point of impact and I can make the radius small so that it's unlikely to give the inventory item to the wrong target, but this is obviously pretty hacky and there's no guarantee the item would transfer at all or that it would definitely go to the right actor.

Is there a way using Zscript to give an inventory item to the victim when the attack impacts them?
Jarewill
 
 
Posts: 1790
Joined: Sun Jul 21, 2019 8:54 am

Re: Is it possible for attacks to give inventory items when they do damage?

Post by Jarewill »

You can actually make the player play a sound whenever they take poison damage by specifying the *poison playersound in SNDINFO: $playersound player male *poison dsplpain

Poison damage is a bit weird, as it isn't picked up by virtuals like DamageMobj, however the PlayerPawn class has a special virtual function called CheckPoison that you can use.
Here's an example that was taken right from the PlayerPawn definition with an added GiveInventory call:

Code: Select all

	Override void CheckPoison()
	{
		let player = self.player;
		if (player.poisoncount && !(Level.maptime & 15))
		{
			player.poisoncount -= 5;
			if (player.poisoncount < 0)
			{
				player.poisoncount = 0;
			}
			player.PoisonDamage(player.poisoner, 1, true);
			GiveInventory("Clip",1);
		}
	}
Heisanevilgenius
Posts: 35
Joined: Wed Dec 15, 2021 8:38 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Is it possible for attacks to give inventory items when they do damage?

Post by Heisanevilgenius »

That sounds great, although I don't necessarily need it to happen every time the player takes poison damage. I just thought when the original attack hurts them, the player would gain a tinted screen for the full duration that they will keep taking poison damage. Ie, the powerup lasts for 30 seconds if the player takes 1 point of poison damage every second, 30 times.

This is all definitely useable, though!

Thank you!

Return to “Scripting”