Weapon dual wielding (ZScript + A_Overlay)

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
phantombeta
Posts: 2215
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Weapon dual wielding (ZScript + A_Overlay)

Post by phantombeta »

How do I do "Synthfire" in ZScript properly?
Right now I'm using this:

Code: Select all

(GetPlayerInput (MODINPUT_BUTTONS) & BT_ALTATTACK) == BT_ALTATTACK
How would I change this to simulate the NOAUTOFIRE flag? Changing it to check if the button was up in the previous tic?
With DECORATE+ACS Synthfire, I did this by simply removing the Synthfire inventory tokens in the end of the fire, reload, dryfire, etc. states.

(For simulating A_Refire, that simple "key is down" check above should be enough)

EDIT: Yes, I'm aware the "== <value>" part isn't necessary due to C-style int->bool implicit conversion, but hey.
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm

Re: Weapon dual wielding (ZScript + A_Overlay)

Post by Xaser »

Heh, I'm going to have to write an improved reference implementation of that one of these days. :P

An actual answer: In addition to MODINPUT_BUTTONS, you also have MODINPUT_OLDBUTTONS at your disposal, which contains the buttons that were pressed in the previous tic.

Code: Select all

if( (GetPlayerInput(MODINPUT_BUTTONS) & BT_ALTATTACK) && !(GetPlayerInput(MODINPUT_OLDBUTTONS) & BT_ALTATTACK) ) {
    // ...do stuff here
} 
This condition is only true on the very first tic that +ALTATTACK is held, which is exactly what the doctor ordered. It's also worth putting that in an "A_SynthAltFire" custom function (if you haven't already so) for copypasta-prevention.

Hope this helps!
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: Weapon dual wielding (ZScript + A_Overlay)

Post by Gutawer »

Just to note, in ZScript, you can use player.cmd.buttons in place of MODINPUT_BUTTONS, player.original_cmd.buttons in place of INPUT_BUTTONS, player.oldbuttons in place of MODINPUT_OLDBUTTONS, player.original_oldbuttons in place of INPUT_OLDBUTTONS, and for everything else, MODINPUT_* can be found in player.cmd while INPUT_* can be found in player.original_cmd - all of the ZScript player virtuals like MovePlayer, CheckJump etc. use this method instead of the equivalent GetPlayerInput() methods (it's also worth noting that, if done in the PlayerThink virtual, you can absolutely force the player to press buttons if you modify the player.cmd.buttons int :P).
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: Weapon dual wielding (ZScript + A_Overlay)

Post by Major Cooke »

I recommend avoid messing with the player functions like that directly when it comes to weapons. It's much easier to let the action determinism (fire, altfire, reload, etc) be done on the weapons themselves, so stick with GetPlayerInput for the weapons like what Xaser said.

Also, if you need to access it multiple times, you can store it in a variable. This way you're not calling functions more often than you need to.

Code: Select all

int curinput = GetPlayerInput(MODINPUT_BUTTONS);
int oldinput = GetPlayerInput(MODINPUT_OLDBUTTONS);

if ((curinput & BT_ALTATTACK) && !(oldinput & BT_ALTATTACK))
{
}
else if ((curinput & BT_ATTACK) && !(oldinput & BT_ATTACK))
{
}
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: Weapon dual wielding (ZScript + A_Overlay)

Post by Gutawer »

I wasn't recommending that the player virtuals be used to do this, more that the player virtuals use the player.cmd system instead of GetPlayerInput(), and in my opinion, the player.cmd system is nicer to work with and more concise and clear than GetPlayerInput(). It also means you aren't making unecessary function calls, whatever the minor performance impact of that may be.
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: Weapon dual wielding (ZScript + A_Overlay)

Post by Major Cooke »

Right. That was an in-case scenario if he was doing this on the weapons themselves.
User avatar
phantombeta
Posts: 2215
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Weapon dual wielding (ZScript + A_Overlay)

Post by phantombeta »

Xaser wrote:Heh, I'm going to have to write an improved reference implementation of that one of these days. :P

An actual answer: In addition to MODINPUT_BUTTONS, you also have MODINPUT_OLDBUTTONS at your disposal, which contains the buttons that were pressed in the previous tic.

Code: Select all

if( (GetPlayerInput(MODINPUT_BUTTONS) & BT_ALTATTACK) && !(GetPlayerInput(MODINPUT_OLDBUTTONS) & BT_ALTATTACK) ) {
    // ...do stuff here
} 
This condition is only true on the very first tic that +ALTATTACK is held, which is exactly what the doctor ordered. It's also worth putting that in an "A_SynthAltFire" custom function (if you haven't already so) for copypasta-prevention.

Hope this helps!
Thanks. I mostly wanted to know if this was the right way to do it.
Gutawer wrote:Just to note, in ZScript, you can use player.cmd.buttons in place of MODINPUT_BUTTONS, player.original_cmd.buttons in place of INPUT_BUTTONS, player.oldbuttons in place of MODINPUT_OLDBUTTONS, player.original_oldbuttons in place of INPUT_OLDBUTTONS, and for everything else, MODINPUT_* can be found in player.cmd while INPUT_* can be found in player.original_cmd - all of the ZScript player virtuals like MovePlayer, CheckJump etc. use this method instead of the equivalent GetPlayerInput() methods
Those were exposed to ZScript? Nice.
(it's also worth noting that, if done in the PlayerThink virtual, you can absolutely force the player to press buttons if you modify the player.cmd.buttons int :P).
Oh man. I wonder what kinds of evil, evil things people will do with this.
Like pressing a random button every few seconds or minutes, randomly. Or randomly changing the yaw/pitch a bit sometimes to make mouse users think their mouse is broken.
I wonder if you could block +use from respawning the player/restarting the map with that...

Return to “Editing (Archive)”