Passing damage value to blood 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
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Passing damage value to blood actor?

Post by D2JK »

I've read that Blood-actors have special functionality:
Blood has special functionality hardcoded into the engine. The blood actor will start at different frames depending on how much damage is done that caused the bleeding.
I thought this could be useful, except that instead of a different starting frame, I wanted to modify the actor's scale depending on the damage amount. However, the functionality seems to go away when creating a new class inheriting from Blood, probably because the inherited class has to be given a different name, which then no longer will trigger the functionality.

Is there a clever way to somehow pass the damage value to custom Blood actors?
User avatar
Tartlman
Posts: 226
Joined: Thu Oct 11, 2018 5:24 am
Location: meme hell
Contact:

Re: Passing damage value to blood actor?

Post by Tartlman »

D2JK wrote:I've read that Blood-actors have special functionality:
Blood has special functionality hardcoded into the engine. The blood actor will start at different frames depending on how much damage is done that caused the bleeding.
I thought this could be useful, except that instead of a different starting frame, I wanted to modify the actor's scale depending on the damage amount. However, the functionality seems to go away when creating a new class inheriting from Blood, probably because the inherited class has to be given a different name, which then no longer will trigger the functionality.

Is there a clever way to somehow pass the damage value to custom Blood actors?
While i have no idea how to do it, i'd say you should look at Xaser's damnums. It basically creates number actors near the enemy that show how much damage you dealt, which probably comes from passing how much damage the enemy took. This is probably what you're looking for, i'd say.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Passing damage value to blood actor?

Post by Void Weaver »

D2JK, you apparently doing something wrong, because custom blood inherited from default 'Blood' inherits its hardcoded spawn frame mechanics too. You can make sure of that's true if make test of this custom blood:

Code: Select all

ACTOR CustomBlood : Blood replaces Blood
{
States
{
Spawn:
//TNT1 AAA 0 //When it open spawn frame damage correlation mechanics will be omitted
BAL1 A 8 //A_SetScale(ScaleX*2) //If Damage is above 12 
BAL2 A 8 //A_SetScale(ScaleX*0.5) //If Damage is between 9 to 12
PLSS A 8 //If Damage is less then 9
Stop
}
}
But if you want
D2JK wrote:modify the actor's (blood?) scale depending on the custom damage amount
you ofc should write your own mechanics OR try to modify it via ZScript, if that possible at all. Not sure is it can be implemented on deco, but I'd want to make the same thing too. :)
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: Passing damage value to blood actor?

Post by D2JK »

Ok, thanks for that info. After testing again, I've realized it does work in Doom, but unfortunately not in Heretic, which is what I'm currently modding. Bummer.

Tartlman: I checked out Xaser's code. It seems he's using WorldThingDamaged event handler. But I didn't see anything that would let me access and modify the spawned blood actor, such as a pointer.

However, after some thinking, a slightly backwards way crossed my mind. I could override the DamageMobj function, record the last damage suffered by the monster into a dedicated variable, then read this variable in the just-spawned blood actor (apparently blood can make use of the PUFFGETSOWNER-flag), and make decisions based on the read value. I'm not sure if all this would be exactly fool-proof: in case multiple simultaneous damage events, only the value from the last one might end up recorded in the variable.

Furthermore, this doesn't strike me as particularly straightforward... but I can't come up with anything better for now.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Passing damage value to blood actor?

Post by Void Weaver »

Hmm... that's really very odd. I only can assume that's a bug, a wrong wiki article or intended limitation, since blood's hardcoded mechanics doesn't work in Heretic at all even with the default blood.

EDIT:
Probably it doesn't work because Heretic game uses BloodSplatter class instead of Blood, and there is no any mention about Doom blood behaviour. Other question why doesn't work 'Blood replaces BloodSplatter' replacement.
Last edited by Void Weaver on Fri Oct 18, 2019 2:07 pm, edited 2 times in total.
User avatar
Tartlman
Posts: 226
Joined: Thu Oct 11, 2018 5:24 am
Location: meme hell
Contact:

Re: Passing damage value to blood actor?

Post by Tartlman »

D2JK wrote:Ok, thanks for that info. After testing again, I've realized it does work in Doom, but unfortunately not in Heretic, which is what I'm currently modding. Bummer.

Tartlman: I checked out Xaser's code. It seems he's using WorldThingDamaged event handler. But I didn't see anything that would let me access and modify the spawned blood actor, such as a pointer.

However, after some thinking, a slightly backwards way crossed my mind. I could override the DamageMobj function, record the last damage suffered by the monster into a dedicated variable, then read this variable in the just-spawned blood actor (apparently blood can make use of the PUFFGETSOWNER-flag), and make decisions based on the read value. I'm not sure if all this would be exactly fool-proof: in case multiple simultaneous damage events, only the value from the last one might end up recorded in the variable.

Furthermore, this doesn't strike me as particularly straightforward... but I can't come up with anything better for now.
Here's a suggestion to make it work: Make the blood actor have a function that sets it to the correct state, and then pass the worldthingdamaged damage to the function. That should work pretty well, just make sure that the function is loaded before the event handler.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: Passing damage value to blood actor?

Post by D2JK »

But the WorldThingDamaged event has no way to refer to the spawned blood actor, such as a pointer. If it did, I could directly assign a new scale value anyway.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: Passing damage value to blood actor?

Post by D2JK »

I looked up the SpawnBlood function in the source, which spawns the blood actors.

Short version: the function spawns the blood and gets the pointer to it. Then, depending on the current gametype, it advances the spawn state of the spawned blood actor, accessing it through the pointer.

Unfortunately, there is no record of the triggering damage value remaining after the SpawnBlood function has finished, so there's nothing to check on the Blood-actor side. In Heretic gametype, not even the very first state entered.
User avatar
Tartlman
Posts: 226
Joined: Thu Oct 11, 2018 5:24 am
Location: meme hell
Contact:

Re: Passing damage value to blood actor?

Post by Tartlman »

D2JK wrote:I looked up the SpawnBlood function in the source, which spawns the blood actors.

Short version: the function spawns the blood and gets the pointer to it. Then, depending on the current gametype, it advances the spawn state of the spawned blood actor, accessing it through the pointer.

Unfortunately, there is no record of the triggering damage value remaining after the SpawnBlood function has finished, so there's nothing to check on the Blood-actor side. In Heretic gametype, not even the very first state entered.
My guess is probably no, but is it at all possible to override P_SpawnBlood? That might make solving this problem trivial.
Post Reply

Return to “Scripting”