Any way to check an actor's state from ZScript?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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!)
Cacodemon345
Posts: 422
Joined: Fri Dec 22, 2017 1:53 am
Graphics Processor: ATI/AMD (Modern GZDoom)

Any way to check an actor's state from ZScript?

Post by Cacodemon345 »

Hi, can someone help me with events? I can't understand how to get an actor's state when it dies. I need it. I know you can use an WorldEventDied, but I can't find how to use it to get states.
(Sorry if it seems a bit vague.)
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: Any way to check an actor's state from ZScript?

Post by Blue Shadow »

By using [wiki]InStateSequence[/wiki]. Example:

Code: Select all

class ThingDiedTest : EventHandler
{
    override void WorldThingDied (WorldEvent e)
    {
        if (e.Thing && e.Thing.InStateSequence(e.Thing.CurState, e.Thing.ResolveState("Missile")))
        {
            Console.Printf("%s died while shooting!", e.Thing.GetClassName());
        }
    }
} 
If something died while shooting (during the Missile state sequence), it logs "<class name of the thing> died while shooting!".

Note that at the time the event is called, the actor is yet to enter its death state. So checking whether the actor is in Death, XDeath, etc., won't work.
Cacodemon345
Posts: 422
Joined: Fri Dec 22, 2017 1:53 am
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: Any way to check an actor's state from ZScript?

Post by Cacodemon345 »

I think I will need to find other ways to check if the actor is in a Death state. Because it seems like it isn't going to work at all.
User avatar
hideousdestructor
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Any way to check an actor's state from ZScript?

Post by hideousdestructor »

Is it realy necessary that you do this script while it's in its death state? If you're testing whether it's being gibbed you can check if the thing has an xdeath state and whether its health is equal to or below negative gibhealth.
Cacodemon345
Posts: 422
Joined: Fri Dec 22, 2017 1:53 am
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: Any way to check an actor's state from ZScript?

Post by Cacodemon345 »

Matt wrote:Is it realy necessary that you do this script while it's in its death state? If you're testing whether it's being gibbed you can check if the thing has an xdeath state and whether its health is equal to or below negative gibhealth.
How do I do that?
User avatar
hideousdestructor
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Any way to check an actor's state from ZScript?

Post by hideousdestructor »

if(
youractorpointer.findstate("xdeath")
&& youractorpointer.health <= -youractorpointer.gibhealth
)
Cacodemon345
Posts: 422
Joined: Fri Dec 22, 2017 1:53 am
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: Any way to check an actor's state from ZScript?

Post by Cacodemon345 »

Matt wrote:if(
youractorpointer.findstate("xdeath")
&& youractorpointer.health <= -youractorpointer.gibhealth
)
Thanks, but it isn't going to work with mods that change monster behaviour to only gib if hit with a specific weapon.
Also, I need to find a way to calculate damage taken by monster and add points to the player.

Return to “Scripting”