Weapon input buffer

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
User avatar
neoworm
Posts: 1743
Joined: Fri Sep 23, 2005 9:17 am
Location: Czech Republic

Weapon input buffer

Post by neoworm »

I am working on melee weapons for HeXen and run to some problems.
I want all the melee attacks to work more like in fighter games - one click one attack and mixture of primary and secondary to create various combos. I used A_WeaponReady with disabled refire but it have problem that it switches the instantly and thus amking precise animations really hard to pull off. I would like to use system that buffers the input and releases it when I want so it have large enough window to press the key and then precise moment when it switches states.

I found how to get the input in ZSCript and created three action functions. One to get the input and store it in variable, another to switch state depending on the variable and clear it. And last to clear the buffer just to be sure.

I got to the point it runs but it doesn't work. I really don't know what to do with that. I don't know how to debug in GZDooM and without it it's just up to my skills which are really limited.
I don't know if I am handling the variables properly. The pointers when working with weapons and inventory are still mystery to me.
Also there can be problem that I created the functions in class other weapons are inheriting from.
Or I just wrote the if statement wrong. I want to check if the primary fire is pressed and wasn't pressed in previous tic.

If sombody can try to look at it and help, I would be really glad.

Code:
Spoiler:
User avatar
Matt
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
Contact:

Re: Weapon input buffer

Post by Matt »

What kind of combos are you wanting to add? There are multiple different solutions of varying complexity and it might be better to stick with the simpler ones if the more complex ones aren't going to be used.

As a more general tip, you might need a counter that resets to zero whenever no buttons are being pressed, goes up by one every tic whenever any button is being pressed, and has to be above a certain number before the input is considered.
User avatar
neoworm
Posts: 1743
Joined: Fri Sep 23, 2005 9:17 am
Location: Czech Republic

Re: Weapon input buffer

Post by neoworm »

I have expanded Corvus staff to have 6 different attacks and I want to do three sequences for now. Later when I get to powered staff I will want add more that will use the enchantment to do some iteresting attacks. So quite complex if I manage to get that far.
I have combo working with Cleric's mace using A_WeaponReady and inventory counter. But for more complex ones the counters are really messy to iterate. Right now the main reason I wanted to do this is speed to make the sequences and precision of the animation switching. If I can choose to which state jump directly from, what is basically A_Refire, I can make and iterate the sequences really fast. Also the method with A_WeaponReady have problem because it needs +NOREFIRE and on Firemace I want primary to be melee with combos and secondary normal Firemace behaviour with fullauto, so I need another method.
User avatar
Matt
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
Contact:

Re: Weapon input buffer

Post by Matt »

I dunno if this helps, but here's how I handled the SSG, which has the following possibilities:

Fire
Altfire
Both at the same time
Fire or Altfire while holding User2
User1
User2
User3
User4

WRF_ALL is a custom-defined constant that includes all the buttons.
PressingFire(), etc. are custom-defined functions that check player.cmd.buttons, and were made solely because I didn't want to be typing that stuff out all the time; similar with setweaponstate().

User1, 3 and 4 all just go to another weapon state right away and aren't combined with anything else, so I just leave A_WeaponReady to enable them.

The combinable buttons, however, are not checked by that A_WeaponReady call. Instead, I check to see exactly which combination is being done before deciding on what state to go to or what overlay to add, and bypass A_WeaponReady entirely if any of the first 4 combinations apply.

I don't do that button-timer trick here, but I assume that would be straightforward enough.


What this won't handle is sequences of buttons one after the other. I suppose these could be stored in an array???
User avatar
neoworm
Posts: 1743
Joined: Fri Sep 23, 2005 9:17 am
Location: Czech Republic

Re: Weapon input buffer

Post by neoworm »

I think I found a problem I didn't even knew that could be a problem - I don't know how to properly switch weapon state with ZScript. I tought it's done by ResolveState() because of this snippet from GZDooM.pk3:

Code: Select all

action state A_JumpIf(bool expression, statelabel label)
{
	return expression? ResolveState(label) : null;
}
but it's evidently not the case or not enough and I can't properly decode following:

Code: Select all

action void SetWeaponState(statelabel st,int layer=PSP_WEAPON)
{
	if(player)player.setpsprite(layer,invoker.findstate(st));
}
Can I ask for a little bit in depth explanation what does it do exactly?
The documentation is really not exhaustive, to say it lightly, and I am completely lost.
User avatar
Matt
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
Contact:

Re: Weapon input buffer

Post by Matt »

I don't even know if SetPSprite() is documented anywhere right now! I just remember seeing it a while ago on a thread...

Basically it's

Code: Select all

Player.SetPSprite(int layer, state state)
where layer is the layer you want to set this state in, and state is the state to go to.

It's a little like A_Overlay except generalized for any overlay including the weapon.

My little "SetWeaponState" function is just a shorthand for all this, always assuming that I want to affect the main weapon layer (PSP_WEAPON is a constant defined in GZDoom) and I will be identifying the state by label instead of a numeric constant or something. (In hindsight I might've named it "SetWeaponStateLabel" because it's intended to behave just like "SetStateLabel" for weapons, but it was a bit awkward and plodding.)

FindState is... well, FindState. As always (unless you change the scope of your states block), you need to specify "invoker" here to mean the weapon rather than the user.
User avatar
neoworm
Posts: 1743
Joined: Fri Sep 23, 2005 9:17 am
Location: Czech Republic

Re: Weapon input buffer

Post by neoworm »

I hope I will get to it on the weekend.
The documentation is really full of holes right now. I would be interested in seeing what else is tied to player class. But I think only way to find out now is to dive deep into GZDooM repository and I am really not up to that right now.

Thanks anyway.

EDIT:
Got it working as intended. Now working on minor extensions to cover some exceptions.
Post Reply

Return to “Scripting”