Interrupting reload in ZScript

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!)
dodopod
Posts: 66
Joined: Wed Oct 04, 2017 2:00 pm

Interrupting reload in ZScript

Post by dodopod »

I'm trying to make a shotgun that can reload, using ZScript. Reloading is divided into 3 states, like this:

Code: Select all

Reload:
    SHTG AAAAAAAAAAAA 1 A_Lower;
    // Fallthrough
Reload.LoadShell:
    SHTG A 35
    {
        A_PlaySound("misc/w_pkup", CHAN_WEAPON);
        A_Reload(1);
    }
    SHTG A 0 A_JumpIfReloaded("Reload.Finish");
    Loop;
Reload.Finish:
    SHTG AAAAAAAAAA 1 A_Raise;
    SHTG BC 5;
    SHTG D 4 A_PlaySound("misc/w_pkup", CHAN_WEAPON);
    SHTG CB 5;
    SHTG A 1 A_Raise;
    Wait;
As you can see, I've defined 2 action functions (A_Reload & A_JumpIfReloaded). Hopefully, it's pretty obvious what they do. What I want is for the player to be able to interrupt the reload, by pressing the reload key again. I can do this by checking input in A_JumpIfReloaded, but that only works if the player happens to be holding the key down when the function is called. Is there any way to detect if the player presses the key between function calls?
dodopod
Posts: 66
Joined: Wed Oct 04, 2017 2:00 pm

Re: Interrupting reload in ZScript

Post by dodopod »

Nevermind, I got it. I overrode tick:

Code: Select all

override void Tick()
{
    Super.Tick();
    if (owner.player.cmd.buttons & BT_RELOAD && !(owner.player.oldbuttons & BT_RELOAD))
        bReloadPressed = true;
}
Then, I replaced A_WeaponReady with a function that checks and unsets bReloadPressed, and changed A_JumpIfReloaded to do the same. Simple enough. For some reason, I was under the impression that Tick couldn't change the state of the player's current weapon, since something like this won't print anything

Code: Select all

override void Tick()
{
    Super.Tick();
    if (InStateSequence(curState, GetReadyState()))
        Console.Printf("ready");
}

Return to “Scripting”