Player crouch

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!)
tomppa84
Posts: 12
Joined: Fri Sep 09, 2022 6:45 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support

Player crouch

Post by tomppa84 »

Is there a way to uncrouch the player with ACS? I have a cutscene where I want the player to stand up.
User avatar
Player701
 
 
Posts: 1651
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: Player crouch

Post by Player701 »

I'm not aware of a way to do this with pure ACS, but provided ZScript is available to you, you can use the following code and then leverage the ACS ScriptCall feature to call it:

Code: Select all

class Uncroucher : Object
{
    static void Uncrouch(int playerNumber)
    {
        if (playerNumber >= 0 && playerNumber < MAXPLAYERS && playeringame[playerNumber])
        {
            players[playerNumber].Uncrouch();
        }
    }
}
How to call the above code from ACS (assuming the player is the activator):

Code: Select all

script "UncrouchScript" (void)
{
    ScriptCall("Uncroucher", "Uncrouch", PlayerNumber());
}
Note that you will need to freeze the player beforehand; otherwise, if the crouch key is still being held, the player will switch to the crouch state again immediately after ScriptCall.
tomppa84
Posts: 12
Joined: Fri Sep 09, 2022 6:45 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support

Re: Player crouch

Post by tomppa84 »

I get this error when I try this:

Code: Select all

Script error, "ozzy.pk3:zscript.txt" line 226:
Can't call play function Uncrouch from data context
User avatar
Player701
 
 
Posts: 1651
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: Player crouch

Post by Player701 »

Sorry, my bad. If you're already using ZScript in your project, you have probably added a version specifier in the beginning of your ZScript lump. Starting from a certain version, the default scope changed from play to data, so you need to explicitly specify that the Uncroucher class has play scope. Simply add play after class Uncroucher : Object, and it should work.
tomppa84
Posts: 12
Joined: Fri Sep 09, 2022 6:45 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support

Re: Player crouch

Post by tomppa84 »

Now it works! Thank you!

Return to “Scripting”