[SOLVED] [ZS] My minigun switch-thingy isn't working. (see last post)

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
yum13241
Posts: 875
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

[SOLVED] [ZS] My minigun switch-thingy isn't working. (see last post)

Post by yum13241 »

What I want: When you press altfire, if it's not spinning already, it'll start spinning and tell the weapon to go to FireMinigun:. If it IS spinning, then it'll stop.

What I'm getting: It spins alright, but FireMinigun: is never reached. I can tell because "I'm a minigun!" is never logged.
Spoiler: Weapon Code

Spoiler: MWSWeapon
Last edited by yum13241 on Wed May 10, 2023 1:14 pm, edited 1 time in total.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZS] My minigun switch-thingy isn't working.

Post by Jarewill »

The first thing I noticed is that you are using the wrong operators in your Altfire and Ready states.
You are using the comparison operator == instead of the assignment operator =.
yum13241
Posts: 875
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: [ZS] My minigun switch-thingy isn't working.

Post by yum13241 »

I keep writing == out of habit instead of = because I once did the opposite. LMAO.

Your solution worked, but I need a way to stop the spinning by pressing altfire. A_jumpIf(player.cmd.buttons & BT_ALTATTACK, "Ready"); does not work, where ever I put it in AltFire:.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZS] My minigun switch-thingy isn't working.

Post by Jarewill »

That might be because you have a A_WeaponReady call in your Altfire state that doesn't disable altfires, meaning that pressing altfire will restart that state.
One potential fix to that would be to separate the spinning state with the Altfire state:

Code: Select all

	AltFire:
		PKCG A 0 A_JumpIf(invoker.minigun == true, "Ready");
		Goto ReadySpin;
	ReadySpin:
		PKCG AAABBBCCCDDD 1 { invoker.minigun = true; A_MWSReady();}
		Loop;
However this way might require the +WEAPON.NOAUTOFIRE flag to be set to prevent constant jumps.
yum13241
Posts: 875
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: [ZS] My minigun switch-thingy isn't working.

Post by yum13241 »

I get a return type mismatch (what does that mean?) with this (I tried finding a solution that doesn't need +WEAPON.NOAUTOFIRE)
Spoiler: borked code
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZS] My minigun switch-thingy isn't working.

Post by Jarewill »

Jumps inside anonymous functions work differently.
If you make it return a value inside an If block, you need to make sure to return a value even if that If block fails.
In case of state jumps, put return ResolveState(null); after the If block at the end of the anonymous function.

Also might be worth noting that your custom A_MWSReady doesn't support any parameters, unless you edited it.
The invoker.minigun check also looks to be not needed as the variable is set to true right before that call.
And unless I am mistaken, it still won't work as the moment it enters the Ready state, it will detect the altfire button being pressed due to AUTOFIRE and go back to the Altfire state.

If you really don't want to use the +NOAUTOFIRE flag, try this code:

Code: Select all

	Ready:
		CHGG A 1 {
			invoker.minigun = false;
			A_WeaponReady(WRF_NOSECONDARY);
			If(player.cmd.buttons&BT_ALTATTACK && !(player.oldbuttons&BT_ALTATTACK)){
				return ResolveState("Altfire");
			}
			return ResolveState(null);
		}
		Loop;
And a similar thing in your Altfire state.
By checking the current and previous button inputs, you can check if the button was just pressed and wasn't held, which will be needed to prevent the jumps to keep happening.
Then having the WRF_NOSECONDARY flag set on A_WeaponReady prevents the normal Altfire behavior from happening.
yum13241
Posts: 875
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: [ZS] My minigun switch-thingy isn't working.

Post by yum13241 »

Also might be worth noting that your custom A_MWSReady doesn't support any parameters, unless you edited it.
I did.

BTW, const MWS_READYFLAGS = WRF_ALLOWUSER1 | WRF_ALLOWUSER2 | WRF_ALLOWUSER3 | WRF_ALLOWUSER4 | WRF_ALLOWZOOM;.


Now I can't deactivate the minigun mode at all.
Spoiler: borked weapon

If doing this in ZScript is hard, imagine doing this in DECORATE! I get nightmares just thinking about it...
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZS] My minigun switch-thingy isn't working.

Post by Jarewill »

The first issue is mine, the Ready state once again uses the comparison operator ==.
That was my bad when I was copying code, which I fixed in an edit, but it looks like you saw the post before I edited it.
The second issue that I assume is happening is in the MinigunDeactivate state, where there's a stray A_MWSReady call without the WRF_NOSECONDARY flag set.

Now thinking about it, is the Altfire state even needed here?
The Ready state jumps to the WindUp anyways, so the Altfire state could just be skipped and there wouldn't be a need for the WRF_NOSECONDARY flag.
yum13241
Posts: 875
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: [ZS] My minigun switch-thingy isn't working.

Post by yum13241 »

Now the weapon just spins once when I press altfire.
Spoiler:
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZS] My minigun switch-thingy isn't working.

Post by Jarewill »

Another mistake on my part.
I copied the code I provided from my project, but in my project there isn't a case where the first frame of a state can switch back.
The issue seems to be that the jump happens and then the checks pass because the old buttons haven't updated in the same frame, jumping back to the Ready state.
It doesn't freeze the game and plays the animation because of the MinigunDeactivate state, which lacks any jumps in the first frame.

Anyways, doing the following seemed to have fixed it for me:
Spoiler:
Also I recommend you to use the [ code ] tag as it makes copying code way easier.
yum13241
Posts: 875
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: [ZS] My minigun switch-thingy isn't working.

Post by yum13241 »

THANK YOU SO MUCH! This is now solved.
Spoiler: My working weapon
Post Reply

Return to “Scripting”