Trigger script with weapon attack?

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
Azagthoth
Posts: 63
Joined: Wed Jan 20, 2021 4:06 pm

Trigger script with weapon attack?

Post by Azagthoth »

Hello. According to the wiki, ACS_NamedExecute should be usable in DECORATE but I can't find any examples of how to do this. Let's say I want to trigger a script every time I punch/fire with "ACTOR Fist : Weapon", how would I do that? Or maybe I could make an ACS script that does this without changing the actor somehow? Or maybe I could add an AltFire attack to fist that doesn't do anything except triggering the script? Any ideas?
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Trigger script with weapon attack?

Post by Player701 »

You just call it like any other action function:

Code: Select all

actor MyFist : Fist
{
    States
    {
        Fire:
            PUNG B 4
            PUNG C 4
            {
                A_Punch;
                ACS_NamedExecute("MyScript", 0);
            }
            PUNG D 5
            PUNG C 4
            PUNG B 5 A_ReFire
            Goto Ready
    }
}
The above example uses an anonymous function, which is equivalent to the following code:

Code: Select all

PUNG C 4 A_Punch
TNT1 A 0 ACS_NamedExecute("MyScript", 0)
Please note, however, that unless you're aiming for Zandronum compatibility, a ZScript-based solution would likely be a better way to solve your problem, although it depends on what exactly you intend to accomplish. In modern GZDoom, ACS should generally be used for map events only, with very few exceptions like SetAmmoCapacity.
Azagthoth
Posts: 63
Joined: Wed Jan 20, 2021 4:06 pm

Re: Trigger script with weapon attack?

Post by Azagthoth »

Code: Select all

actor MyFist : Fist
{
    States
    {
        Fire:
            PUNG B 4
            PUNG C 4
            {
                A_Punch;
                ACS_NamedExecute("MyScript", 0);
            }
            PUNG D 5
            PUNG C 4
            PUNG B 5 A_ReFire
            Goto Ready
    }
}
I tried it but I got this error:

Script error, "THate.pk3:decorate.txt" line 8:
Sprite names must be exactly 4 characters

I'm very new to doom scripting so I'm probably missing something obvious but could you please explain in detail how to do this. I do need Zandronum compatibility btw.
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Trigger script with weapon attack?

Post by Player701 »

Zandronum probably does not support anonymous functions (though I haven't used it in a very long time, so can't be sure). Try replacing this part of the code

Code: Select all

PUNG C 4
{
    A_Punch;
    ACS_NamedExecute("MyScript", 0);
}
with the second example from my previous post.
Azagthoth
Posts: 63
Joined: Wed Jan 20, 2021 4:06 pm

Re: Trigger script with weapon attack?

Post by Azagthoth »

Yeah, that worked. Thanks!
Post Reply

Return to “Scripting”