[SOLVED] Adding a spin alt-fire to a chaingun?

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!)
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

[SOLVED] Adding a spin alt-fire to a chaingun?

Post by Alexagon »

I'm not sure if this is the best place to post this. I'm also very very inexperienced at modding/scripting.

So I'm using a modified version of Led's generic weapons mod and I wanted to add an alt fire for the chaingun that lets you hold it to spin the barrel. Would this be possible to include in the script using only the resources the mod includes? Or would i need to download something else and add it in myself?

Would someone be able to guide me through on how I might be able to accomplish this?
Last edited by Alexagon on Sun Jun 09, 2019 8:32 pm, edited 1 time in total.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Void Weaver »

As variant you can try wildweasel's nice sequence.

This is one of his possible examples:

Code: Select all

Actor WindUpGun : Chaingun replaces Chaingun
{
   Weapon.AmmoUse1 1
   Weapon.AmmoUse2 1
   Weapon.AmmoType1 "Clip"
   Weapon.AmmoType2 "Clip"
   Weapon.SlotNumber 4
   States
{
AltFire:
CHGG BBBBBBAAAAABBBBAAABB 1 // The wind-up. I've got this on one line because it's a bit cleaner-looking.
CHGG A 1 A_Refire // If the trigger hasn't been let go of by now, this'll go to Hold.
WindDown:
CHGG BBAAABBBBAAAAA 1 A_Refire // So the player can keep firing without waiting for the thing to spin down first.
CHGG A 1 A_Refire("AltFire") // Too late, can't do that anymore.
Goto Ready
AltHold:
CHGG A 0 A_GunFlash
CHGG A 0 A_PlaySound("weapons/chngun", CHAN_WEAPON)
CHGG A 1 Bright A_FireBullets(3, 3, -1, 6, "BulletPuff", 1)
CHGG B 0 A_GunFlash("Flash2")
CHGG B 0 A_PlaySound("weapons/chngun", CHAN_WEAPON)
CHGG B 1 Bright A_FireBullets(3, 3, -1, 6, "BulletPuff", 1)
CHGG A 0 A_GunFlash
CHGG A 0 A_PlaySound("weapons/chngun", CHAN_WEAPON)
CHGG A 1 Bright A_FireBullets(3, 3, -1, 6, "BulletPuff", 1)
CHGG B 0 A_GunFlash("Flash2")
CHGG B 0 A_PlaySound("weapons/chngun", CHAN_WEAPON)
CHGG B 1 Bright A_FireBullets(3, 3, -1, 6, "BulletPuff", 1)
CHGG A 1 A_Refire
Goto WindDown // Reuse the wind-down states we made Flash:
}
}
Also can be helpful A_CheckForReload and A_ResetReloadCounter f-tions for wind up cycles handling.
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: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Matt »

I'm assuming we're doing some kind of TF2-style hold-to-spin sorta deal.

Here's an example in ZS that might be a bit more maintainable.
Spoiler:
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Alexagon »

@Void Weaver: That method seems to just add a spin animation before firing, if I'm doing it right. I'm looking for an alt fire that primes the shots by spinning so you can shoot without the initial spin animation first.
Matt wrote:I'm assuming we're doing some kind of TF2-style hold-to-spin sorta deal.

Here's an example in ZS that might be a bit more maintainable.
Spoiler:
This is more what I'm looking for. I only used the altfire and winddown sections and it seemed to help but it wouldnt let me fire from the spinning state. I only used those since I figured the whole thing you posted referred to the classic chaingun.

When I added the althold section i was told that "sprite names need to be exactly 4 character, but I didn't see any extra brackets or parentheses that need to be closed or opened so i have no clue how to fix that.

But it's on the right track!

EDIT: So I seemed to have gotten it to show the correct sprites and such for the alt fire spinning, but I can't get the initial click sound to only play once (it keeps looping as the button is helped), but I don't know how to get it to fire from the spinning state without it doing the regular startup spin animation it normally has.
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: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Matt »

I won't be able to tell what happened without seeing the code, but from what you describe it sounds like you've taken some of the bits out of context into the old weapon code and didn't add in the vital stuff that made everything work.

It would probably be easier to take what I posted and add in the other weapon's resources, edit the windup/down animations (and that click would probably go into the windup animation somewhere), etc. until it looks like Led's weapon but with this extra feature.

And do note that this is ZScript not Decorate, it needs to be place in zscript lump not decorate lump.
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Alexagon »

Matt wrote:I won't be able to tell what happened without seeing the code, but from what you describe it sounds like you've taken some of the bits out of context into the old weapon code and didn't add in the vital stuff that made everything work.

It would probably be easier to take what I posted and add in the other weapon's resources, edit the windup/down animations (and that click would probably go into the windup animation somewhere), etc. until it looks like Led's weapon but with this extra feature.

And do note that this is ZScript not Decorate, it needs to be place in zscript lump not decorate lump.
I only know how to work with decorate atm, with what little know how I have. Mind if I share the decorate code I have and see if you can't spot the flaws?
Spoiler:
User avatar
Dan_The_Noob
Posts: 872
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Dan_The_Noob »

I only know how to work with decorate atm, with what little know how I have. Mind if I share the decorate code I have and see if you can't spot the flaws?

Code: Select all

	Altfire:
		TNT1 A 0 A_PlaySound ("weapons/minig/start")
		TNT1 A 0 A_PlaySound("weapons/minig/spin",6)
        VLCN ABCD 1
        VLCN A 0 A_Refire
        goto altwinddown
   
[/quote]

change to this?

Code: Select all

Altfire:
		TNT1 A 0 A_PlaySound ("weapons/minig/start")
AltHold:
		TNT1 A 0 A_PlaySound("weapons/minig/spin",6)
        VLCN ABCD 1
        VLCN A 0 A_Refire
        goto altwinddown
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: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Matt »

Yeah, you've just deleted (or rather omitted) the one thing that makes the entire code work! The anonymous function in the althold state contains the detection code for the player pressing the Fire key so you don't need to call a bunch of A_WeaponReady/A_Refire jump to catch each different possible firing frame.

Create a zscript.txt and copypaste my code and build from there, in the long run it's infinitely more rewarding than drowning in a thousand convoluted goto/refire hacks because "ZScript is too hard".
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Alexagon »

Matt wrote:Yeah, you've just deleted (or rather omitted) the one thing that makes the entire code work! The anonymous function in the althold state contains the detection code for the player pressing the Fire key so you don't need to call a bunch of A_WeaponReady/A_Refire jump to catch each different possible firing frame.

Create a zscript.txt and copypaste my code and build from there, in the long run it's infinitely more rewarding than drowning in a thousand convoluted goto/refire hacks because "ZScript is too hard".
Alright, I added the althold in there but it doesn't seem to fixing my issue. I still can't hold the spinning and fire at the same time.

Also, I'll look into zscript for next time. I really don't want to go through the trouble of changing it all for this project. I appreciate the heads up though.
User avatar
Dan_The_Noob
Posts: 872
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Dan_The_Noob »

Alexagon wrote:
Matt wrote:Yeah, you've just deleted (or rather omitted) the one thing that makes the entire code work! The anonymous function in the althold state contains the detection code for the player pressing the Fire key so you don't need to call a bunch of A_WeaponReady/A_Refire jump to catch each different possible firing frame.

Create a zscript.txt and copypaste my code and build from there, in the long run it's infinitely more rewarding than drowning in a thousand convoluted goto/refire hacks because "ZScript is too hard".
Alright, I added the althold in there but it doesn't seem to fixing my issue. I still can't hold the spinning and fire at the same time.

Also, I'll look into zscript for next time. I really don't want to go through the trouble of changing it all for this project. I appreciate the heads up though.
i think the problem is that you can't hold 2 functions for 1 actor at the same time?

you could make a toggled barrel spin like other mods? but i don't think you can hold both Alt and Primary on 1 weapon.
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Alexagon »

Dan_The_Noob wrote:
Alexagon wrote:
Matt wrote:Yeah, you've just deleted (or rather omitted) the one thing that makes the entire code work! The anonymous function in the althold state contains the detection code for the player pressing the Fire key so you don't need to call a bunch of A_WeaponReady/A_Refire jump to catch each different possible firing frame.

Create a zscript.txt and copypaste my code and build from there, in the long run it's infinitely more rewarding than drowning in a thousand convoluted goto/refire hacks because "ZScript is too hard".
Alright, I added the althold in there but it doesn't seem to fixing my issue. I still can't hold the spinning and fire at the same time.

Also, I'll look into zscript for next time. I really don't want to go through the trouble of changing it all for this project. I appreciate the heads up though.
i think the problem is that you can't hold 2 functions for 1 actor at the same time?

you could make a toggled barrel spin like other mods? but i don't think you can hold both Alt and Primary on 1 weapon.
Gah. Well that sucks. How do I go about making it toggle then?
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: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Matt »

Dan please stop posting about things you know nothing about. What I posted was literally a complete, functioning solution to the problem you're claiming is unsurmountable. (One of several possible solutions and not all of them needing ZScript if one is willing to put up with the spaghetti)

Alexagon you'll need to post the entire actor code for us to see what went wrong.
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Alexagon »

Matt wrote:Dan please stop posting about things you know nothing about. What I posted was literally a complete, functioning solution to the problem you're claiming is unsurmountable. (One of several possible solutions and not all of them needing ZScript if one is willing to put up with the spaghetti)

Alexagon you'll need to post the entire actor code for us to see what went wrong.
Okay. Again, sorry for being somewhat stubborn about the decorate thing I just want to do this small thing then be done with it. Here's the entire entry I have for the minigun:
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: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Matt »

....yikes. I see why redoing from the example isn't really an option.

Don't have time to try out a solution just this moment, but this can be solved without a wacky refire loop by going into having ModWeapon inherit, instead of Weapon, from a child class of Weapon that has the following functions defined:

A_JumpIfPressingFire
A_JumpIfPressingAltfire

Will write something up later.
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Adding a spin alt-fire to a chaingun? Is it possible?

Post by Alexagon »

Matt wrote:....yikes. I see why redoing from the example isn't really an option.

Don't have time to try out a solution just this moment, but this can be solved without a wacky refire loop by going into having ModWeapon inherit, instead of Weapon, from a child class of Weapon that has the following functions defined:

A_JumpIfPressingFire
A_JumpIfPressingAltfire

Will write something up later.
Okay, I really appreciate the help.
Post Reply

Return to “Scripting”