I'm trying to make melee weapon do combos in zcript, but it won't work. Help?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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
DonDevRed
Posts: 49
Joined: Sat Nov 14, 2020 6:32 pm
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support

I'm trying to make melee weapon do combos in zcript, but it won't work. Help?

Post by DonDevRed »

Hello there. I've been trying to learn how to use zscript for a new mod I'm doing for a side project, and I want it to be melee-focused. However, as I been learning about pointers, custom variables and whatnot, I thought I had something here that should've worked.

This is the code I have. The idea was to have a string variable store the combo order previously inputed so that it does different attack with each new input (ex. "light_light_heavy").

Code: Select all

States
	{
		Select:
		scth a 0 A_Raise(255);
		wait;
		
		Ready:
		scth abcb 8 
		{
			invoker.previousAttack = "none";
			A_WeaponReady(WRF_DISABLESWITCH);
		}
		loop;
		
		Fire:
		tnt1 a 2
		{
			if (invoker.previousAttack == "light") 
				A_Jump(256, "Combo_LL");
		}
		scth de 2;
		tnt1 a 2;
		lat1 abcde 2 A_CustomPunch(3 * random(1, 5), TRUE, 0);
		scth ed 2
		{
			invoker.previousAttack = "light";
			A_WeaponReady(WRF_DISABLESWITCH);
		}
		goto Ready;
		
		Combo_LL:
		lat2 abcd 2 A_CustomPunch(4 * random(1, 5), TRUE, 0);
		scth ed 2;
		goto Ready;
		
		
		Deselect:
		scth a 2 A_Lower(255);
		wait;
	}
	
I run Doom and it runs okay, but when I try to click Fire twice, it only does the first attack. It doesn't transition into the second within the assigned frames.

What am I missing? Or did I set this up incorrectly?
Kan3x
Posts: 67
Joined: Tue Nov 08, 2022 4:19 pm

Re: I'm trying to make melee weapon do combos in zcript, but it won't work. Help?

Post by Kan3x »

You need to use "return" to exit the anonymous function and jump to the state you want.

So something like this should be fine:

Code: Select all

tnt1 a 2
		{
			if (invoker.previousAttack == "light") {
				return A_Jump(256, "Combo_LL");
			}
		}
User avatar
DonDevRed
Posts: 49
Joined: Sat Nov 14, 2020 6:32 pm
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support

Re: I'm trying to make melee weapon do combos in zcript, but it won't work. Help?

Post by DonDevRed »

It doesn't work. It gives me an error saying "Return type mismatch".
Kan3x
Posts: 67
Joined: Tue Nov 08, 2022 4:19 pm

Re: I'm trying to make melee weapon do combos in zcript, but it won't work. Help?

Post by Kan3x »

Sorry, I completely forgot A_Jump functions do not work in if statements etc.
You need to use ResolveState() and have a null return later, something like this:

Code: Select all

tnt1 a 2
		{
			if (invoker.previousAttack == "light") {
				return ResolveState("Combo_LL");
			}
			return ResolveState(null);
		}
(everything is written down in the link that I sent to you, though, you could've read that instead of straight up copying and pasting my wrong code, lol)
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: I'm trying to make melee weapon do combos in zcript, but it won't work. Help?

Post by Jarewill »

While the question was already answered, I just wanted to add that in your particular case you can use A_JumpIf:
tnt1 a 2 A_JumpIf(invoker.previousAttack == "light", "Combo_LL");
User avatar
DonDevRed
Posts: 49
Joined: Sat Nov 14, 2020 6:32 pm
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support

Re: I'm trying to make melee weapon do combos in zcript, but it won't work. Help?

Post by DonDevRed »

Kan3x wrote: Tue Mar 07, 2023 7:30 am Sorry, I completely forgot A_Jump functions do not work in if statements etc.
You need to use ResolveState() and have a null return later, something like this:

Code: Select all

tnt1 a 2
		{
			if (invoker.previousAttack == "light") {
				return ResolveState("Combo_LL");
			}
			return ResolveState(null);
		}
(everything is written down in the link that I sent to you, though, you could've read that instead of straight up copying and pasting my wrong code, lol)
Eheh, sorry. But still, thanks. :D

It works just fine now.
Post Reply

Return to “Scripting”