[ZScript]Item that deals continuous damage (poison)

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
Cherno
Posts: 1309
Joined: Tue Dec 06, 2016 11:25 am

[ZScript]Item that deals continuous damage (poison)

Post by Cherno »

I am having touble scripting an item that deals damage over time, as if the owner has been poisoned.

Code: Select all

class SpitterAcidItem : Inventory
{
	int eDelay;
	property EffectDelay : eDelay;
	Default
	{
		// How long it takes for the effect to go away. This is measured in tics.
		SpitterAcidItem.EffectDelay 64;
	}

	override void AttachToOwner (Actor other)
	{
		Super.AttachToOwner(other);
	}

	override void DoEffect ()
	{
		if (owner)
		{
                        //deal damage here

			
			if (eDelay-- == 0)
			{
				// The effect is over;
				Destroy();
			}
		}
	}
}
Things tried so far:
  • owner.health = owner.health -1 (obviously a very bad and hacky way, but actually the only one that sorta worked! Only that nothing happens if the healths hits 0.
  • Thing_Damage(owner.tid, 1, 0);//nothing happens
  • A_DamageSelf(25);//the wiki page has an example of an item that uses this function in it's PickUp state, so only one-time damage dealing. Nothing happens when used inside DoEffect().
Note that I am aware that DoEffect is called every tic so the poison would be quite potent to say the least, but that's already taken care of. All I really need to know is how to damage the item's owner, hopefully without resorting to using ACS scripts (which should be the last resort).

Any ideas? :)
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: [ZScript]Item that deals continuous damage (poison)

Post by Blue Shadow »

Cherno wrote:
  • A_DamageSelf(25);//the wiki page has an example of an item that uses this function in it's PickUp state, so only one-time damage dealing. Nothing happens when used inside DoEffect().
It should be:

Code: Select all

owner.A_DamageSelf(25);
Calling it without 'owner' means the item itself is the caller, i.e., the item tries to damage itself.
User avatar
Cherno
Posts: 1309
Joined: Tue Dec 06, 2016 11:25 am

Re: [ZScript]Item that deals continuous damage (poison)

Post by Cherno »

Blue Shadow wrote:
Cherno wrote:
  • A_DamageSelf(25);//the wiki page has an example of an item that uses this function in it's PickUp state, so only one-time damage dealing. Nothing happens when used inside DoEffect().
It should be:

Code: Select all

owner.A_DamageSelf(25);
Calling it without 'owner' means the item itself is the caller, i.e., the item tries to damage itself.
Weird, I could have sworn that I tried that too. Apparently, I did not! Your solution works. Thank you.

Still, its funny that it seems to work differently in a CustomInventory's Pickup state, as detailed in the wiki page example code.
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: [ZScript]Item that deals continuous damage (poison)

Post by Blue Shadow »

The Pickup state is executed in the context of whichever actor picked up the item, not the item itself, like the case is with DoEffect().
Post Reply

Return to “Scripting”