Forcing monsters to wake up on any 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!)

Forcing monsters to wake up on any damage

Postby D2JK » Tue Sep 17, 2019 6:26 am

This is just a minor peeve, but still: what would be the best way to ensure that a monster, in their Look state, wakes up immediately when it takes any damage? Right now, sometimes monsters seems completely oblivious to the fact that someone shot them (or are clawing them or punching them or something), and they may 'tolerate' a surprising amount of damage before reacting.

I tried to look for a flag in the Behavior section in the wiki, but couldn't find anything. What I suppose I could do, would be to make them constantly check if their health has dipped from their spawn health value... but maybe there is another option, preferably with no unrelated side-effects?
D2JK
 
Joined: 30 Aug 2014

Re: Forcing monsters to wake up on any damage

Postby Cherno » Tue Sep 17, 2019 9:17 am

Hmm, are you sure that this "lazy" behavior is not related to the monster's A_Chase frame lengths?
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: Forcing monsters to wake up on any damage

Postby D2JK » Tue Sep 17, 2019 9:40 am

No, that shouldn't be it... if I've waited for a few seconds for a reaction, that should rule it out.

In one extreme case, I shot a rocket at monster's leg, and expected him to wake up, but nothing happened. In this particular case, there was no line-of-sight directly from the centre of the monster to the centre of my player pawn.

That's not to say only LoS matters. In another case, a monster chased an idle monster in an open room. The chasing monster could land a few melee blows before the idle monster reacted to the beating.
D2JK
 
Joined: 30 Aug 2014

Re: Forcing monsters to wake up on any damage

Postby Void Weaver » Tue Sep 17, 2019 12:13 pm

Well, if you wnt to consider specific cse for the some specific monster then PainThreshold 0 WITH PainChance 256 would be excelent solution, but since there is no wy to change PainChnce vlue so isn't option.

Other inversive way to hit monster with +FORCEPAIN missile\puff, but it can cause painlock for a some fast-sequnced attacks, so that isn't good solution too.

For other hcky way you can try to hit missile\puff with +HIT(POINTER) flag and specific DamageType "Harmful", and then make check for POINTER's hp (A_JumpIfHealthLower), nd IF its hp less than 100% of its SpawnHelth then swithch DamgeType to regular one like "None" via A_SetDamageType for exmple.
The trigger to awkening would be 'PainChance "Harmful", 256' property for each monster. Yep, it's too hacky but it should work I guess.

I'm sure that ZScript should provide a much smooth way to lwys awake monsters.
User avatar
Void Weaver
Keeper of the Diablo bestiary storage Also amateur DECORATE-spaghetti weaver ಠ_ಠ
 
Joined: 18 Dec 2014

Re: Forcing monsters to wake up on any damage

Postby Boondorl » Tue Sep 17, 2019 4:27 pm

Depends on the tool you use. I actually fixed this myself in ZScript:
Code: Select allExpand view
override int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags, double angle)
{
    int newdam = super.DamageMobj(inflictor, source, damage, mod, flags, angle);
      
    if (health > 0 && newdam > 0 && SeeState && target && InStateSequence(CurState, SpawnState))
    {
        A_PlaySound(SeeSound, CHAN_VOICE, 1, false, bBoss ? ATTN_NONE : ATTN_NORM);   
        SetState(SeeState);
    }

    return newdam;
}

Now, this was used for a set of custom monsters so you couldn't just throw it in a DamageMobj function if you want it to be universal, but you could probably use similar checking in an Inventory item and then give it to every monster on spawn via an event handler.

The health checking in the Spawn state isn't the worst solution, honestly. You wouldn't want to check against its spawn health but rather against its health from the previous frame.

Looking through the source code, I know exactly why this happens too. Normally when a monster takes damage it's always supposed to wake up, but there's a small error present. This snippet is the error:
Code: Select allExpand view
if (target->state == target->SpawnState && target->SeeState != nullptr)
{
    target->SetState(target->SeeState);
}

The person who wrote this is checking wrong. This will only be true if the monster is in the first frame of its Spawn state. This causes it to work only half the time since most monsters will have two frames in their Spawn state. To fix this it would need to check if its current state was within its entire Spawn sequence. The reason it's like this is because that's also how it was in the original Doom code, likely due to the way state sequences were structured.
User avatar
Boondorl
 
Joined: 11 Jul 2018

Re: Forcing monsters to wake up on any damage

Postby D2JK » Tue Sep 17, 2019 9:22 pm

Thank you, I was also curious if it would be possible to find the cause in the source code, but didn't quite get around to that yet... and there it is.
D2JK
 
Joined: 30 Aug 2014


Return to Scripting

Who is online

Users browsing this forum: No registered users and 7 guests