[Solved][ZS]Giving to monsters a "Fire Death Effect"

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
Ac!d
Posts: 348
Joined: Tue Apr 02, 2019 5:13 am

[Solved][ZS]Giving to monsters a "Fire Death Effect"

Post by Ac!d »

I followed this topic and the code made by jarewill

I would to create a "Fire Death Effect" for monsters which activate only if the monster or the player doesn't have a Death.Fire state.

Code: Select all

version "4.0"

Class FlamerHandler : EventHandler
{
    Override void WorldThingDied(WorldEvent e)
    {
        If(e.Inflictor&&e.Inflictor.DamageType == "Fire")
        {
            e.Thing.GiveInventory("FireDeathEffect",1);
        }
    }
}
Class FireDeathEffect: Inventory
{
    Override void AttachToOwner(Actor other)
    {
        self.height=other.height;
        Super.AttachToOwner(other);
    }
    Override void DoEffect()
    {
        Super.DoEffect();
        If(Owner && (Owner is "ExplosiveBarrel") && !(Owner is "LostSoul") && !(Owner is "PainElemental") && !(Owner is "CyberDemon") && !(Owner is "SpiderMastermind") && !Owner.FindState("Death.Fire"))
        {
            Owner.bFLY = False; Owner.bNOGRAVITY = False; Owner.bNOBLOOD = True;
            Owner.height = self.height; //Reset the height
            Owner.A_SetTranslation("Scorched"); //Set a color translation
        }
    }
} 

Code: Select all

// TRANSLATE
// Monsters Killed by Flamethrower - by Jekyll Grim Payne
Scorched = "0:255=%[0.00,0.00,0.00]:[0.33,0.33,0.33]"
This code works for custom monters with their own "Death.Fire" state. But not with doom monsters.
Last edited by Ac!d on Sat May 07, 2022 12:50 am, edited 1 time in total.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZS]Giving to monsters a "Fire Death Effect"

Post by Jarewill »

First error I spot is that you check if the Owner is an explosive barrel, without reversing the result.
You should replace:

Code: Select all

If(Owner && (Owner is "ExplosiveBarrel") &&
With:

Code: Select all

If(Owner && !(Owner is "ExplosiveBarrel") &&
However that still won't fix the issue, and I think this might be a bug.
The thing that is failing here is the Death.Fire state check.

Changing it to a Pickup state, which a monster will surely not have, the code works.
However as is, it won't work, even if the vanilla Doom monsters don't have a Death.Fire state.
Using the Burn state instead also doesn't work.

I think this might be a bug in FindState where it only checks for the first part of the state.
What I mean is that it will return true, because the monster has a Death state, even if it doesn't have the specific Death.Fire state.
I might be wrong though.
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: [ZS]Giving to monsters a "Fire Death Effect"

Post by Player701 »

Jarewill wrote:I think this might be a bug in FindState where it only checks for the first part of the state.
What I mean is that it will return true, because the monster has a Death state, even if it doesn't have the specific Death.Fire state.
I might be wrong though.
The second argument of FindState determines if the state label it finds should be an exact match; it defaults to false. Change the code to FindState("Death.Fire", true), and it should work as expected.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZS]Giving to monsters a "Fire Death Effect"

Post by Jarewill »

Player701 wrote:The second argument of FindState determines if the state label it finds should be an exact match; it defaults to false. Change the code to FindState("Death.Fire", true), and it should work as expected.
Ah, I see.
I can confirm setting that argument to true fixes it.
My bad for jumping to conclusions so quickly.
Ac!d
Posts: 348
Joined: Tue Apr 02, 2019 5:13 am

Re: [ZS]Giving to monsters a "Fire Death Effect"

Post by Ac!d »

I have a new problem. I don't know how to remove the "Fire Death Effect" on a monster when he's resurrected.

I tried this line, but it doesn't work.

Code: Select all

Override Void WorldThingRevived(WorldEvent e) { e.Thing.TakeInventory("FireDeathEffect",1); }
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: [ZS]Giving to monsters a "Fire Death Effect"

Post by Player701 »

There's nothing wrong with this line, the problem is likely that the translation is not being reversed, since you call A_SetTranslation only once and never do it again to restore the original translation afterwards.

I would suggest to store the previous translation in the item itself (it is represented by a numerical value internally) and restore it in DetachFromOwner, which is called when the item is being removed from the owner:

Code: Select all

class FireDeathEffect : Inventory
{
    uint oldTranslation;
    
    override void AttachToOwner(Actor other)
    {
        oldTranslation = other.Translation;
        ...
    }
    
    override void DetachFromOwner()
    {
        Owner.Translation = oldTranslation;
    }
    
    ...
}
NB: I haven't had the time to test this code, please tell me if you've got any problems with it, and I will try to answer later today.
Ac!d
Posts: 348
Joined: Tue Apr 02, 2019 5:13 am

Re: [ZS]Giving to monsters a "Fire Death Effect"

Post by Ac!d »

I've tried your code, but it didn't work.

Code: Select all

//TRANSLATE
oldTranslation = "0:255=0:255" // Not really needed, but it looks nicer than "".
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: [ZS]Giving to monsters a "Fire Death Effect"

Post by Player701 »

You don't have to define anything extra in the TRNSLATE lump. The code saves the actor's previous translation and then restores it once the item is taken away. To make it work, you still need to handle the WorldThingRevived event and call TakeInventory there like you did before.
Ac!d
Posts: 348
Joined: Tue Apr 02, 2019 5:13 am

Re: [Solved][ZS]Giving to monsters a "Fire Death Effect"

Post by Ac!d »

Mea culpa, the code works indeed. The TRNSLATE lump is not useful if a monster has a translation on him.
Post Reply

Return to “Scripting”