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

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!)
User avatar
Dan_The_Noob
Posts: 880
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 think you would need to have a check of some kind in the ready state and AltFire basically be just adding or removing the "toggle" (which could be done like pistolmag with 1 bullet)

something like

Code: Select all

AltFire:
{
A_JumpIfInventory("Spinner",1,3)
A_GiveInventory("Spinner", 1)
goto Ready
A_TakeInventory("Spinner",1)
goto Ready
}
then some spin thing in ready based around A_JumpIfInventory("Spinner",1,##) I guess?
I haven't tried this type of thing, i don't like idle sounds :P
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 »

A ZScript lump is just a file called "zscript" like a Decorate lump is just a file called "decorate".
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:A ZScript lump is just a file called "zscript" like a Decorate lump is just a file called "decorate".
Okay, yeah I did that. I didn't seem to do anything ingame though.
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 »

Did you do the other stuff in that post though? (and do *not* try to combine what I'm saying with what Dan is saying, I believe we are working at cross purposes here)
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 »

Matt wrote:Did you do the other stuff in that post though? (and do *not* try to combine what I'm saying with what Dan is saying, I believe we are working at cross purposes here)
Spoiler:
I did, and this is what I get:

Script error, "li-wpnitm.pk3:actors/weapons/minigun.txt" line 149:
Invalid parameter 'a_jumpifpressingfire'
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 »

Did you also do the "If you make ModWeapon (or whichever of its ancestors inherits from Weapon) inherit" part?
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 »

Alexagon wrote:
Void Weaver wrote:Alexagon, maybe my english are too bad but I still don't understand what (alt-)firing effects you want to achieve? Should is Altfire mode supposed to be are sorta of toggleable (by alt-fire button) wind-up "awaited-for-Fire-button" state?
I want it so that while holding the altfire key, the barrel on the minigun spins and only spins. Then if I press fire while the barrel is spinning, I want it to fire without any delay.

Essentially I want to be able to be prepared to shoot with the minigun instead of waiting for the first few frames to pass before actually firing.
Oh, got it. :) Well that's easy, even without any scripts. There are 2 variants:

VAR #1 - this is the same mechanics which you looking for. While you hold Alt-fire barrels are spin, if you press Fire at the same time it will immediately shoots.

Code: Select all

Actor WindUpChecker : Inventory {Inventory.MaxAmount 1}

Actor HoldChaingun : Chaingun replaces Chaingun
{
   Weapon.AmmoUse1 1
   Weapon.AmmoUse2 1
   Weapon.AmmoType1 "Clip"
   Weapon.AmmoType2 "Clip"
   Weapon.SlotNumber 4
   States
   {
Fire:
      TNT1 A 0 A_JumpIfNoAmmo("Dryfire")
      TNT1 A 0 A_PlaySound ("weapons/minig/start")
      TNT1 A 0 A_JumpIfInventory("WindUpChecker",1,"Hold")
      CHGG B 2 
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG CD 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG ABCD 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_Refire
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG ABCD 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG ABC 2 A_WeaponReady
      CHGG DABCDAB 3 A_WeaponReady
      CHGG CD 4 A_WeaponReady
      Goto Ready
   Altfire:
      TNT1 A 0 A_TakeInventory("WindUpChecker")
	  TNT1 A 0 A_PlaySound ("weapons/minig/start")
   AltHold:
	  TNT1 A 0 A_PlaySound("weapons/minig/spin",6)
      CHGG ABCD 1 
	  {
	  A_WeaponReady(WRF_DISABLESWITCH|WRF_NOSWITCH|WRF_NOSECONDARY);
	  A_GiveInventory("WindUpChecker");
	  }
	  VLCN A 0 A_Refire
   AltWinddown:
      CHGG ABCDAABBCCDD 1
      TNT1 A 0 A_TakeInventory("WindUpChecker")
	  goto ready
    Hold:
      TNT1 A 0 A_TakeInventory("WindUpChecker")
      TNT1 A 0 A_JumpIf(ACS_NamedExecuteWithResult("ToggleMinigun")==0, "NoReloadHold")
      TNT1 A 0 A_JumpIfNoAmmo("EmptyWindDown")
      TNT1 A 0 A_AlertMonsters
      TNT1 A 0 A_PlaySound("weapons/minig/spin",6)
      TNT1 A 0 A_GunFlash
      CHGG A 1 Offset(0,35) A_FireBullets (5, 5, 1, 8, "BulletPuff")
      TNT1 A 0 Radius_Quake (1, 2, 0, 1, 0)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_SetPitch(pitch-1.0)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG B 1 Offset(0,37) A_Firecustommissile("ChaingunCasingSpawner",0,0,-12,-18)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG C 1 Offset(0,39) A_FireBullets (5, 5, 1, 8, "BulletPuff")
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_SetPitch(pitch-0.6)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_Firecustommissile("ChaingunCasingSpawner",0,0,-12,-18)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG D 1 Offset(0,37)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_SetPitch(pitch+1.6)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_ReFire
	  Goto Ready
	  }
}
VAR #2 - this a bit different mechanics. Alt-fire itself consist from 2 toggleable modes: spin on\spin off. While in spin mode it also will immediately shoots while Fire is pressed.

Code: Select all

Actor ToggleChaingun : Chaingun replaces Chaingun
{
   Weapon.AmmoUse1 1
   Weapon.AmmoUse2 1
   Weapon.AmmoType1 "Clip"
   Weapon.AmmoType2 "Clip"
   Weapon.SlotNumber 4
   States
   {
	Fire:
      TNT1 A 0 A_JumpIfNoAmmo("Dryfire")
      TNT1 A 0 A_PlaySound ("weapons/minig/start")
      TNT1 A 0 A_JumpIfInventory("WindUpChecker",1,"Hold")
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG B 2 
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG CD 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG ABCD 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_Refire
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG ABCD 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG ABC 2 A_WeaponReady
      CHGG DABCDAB 3 A_WeaponReady
      CHGG CD 4 A_WeaponReady
      Goto Ready
   
	Altfire:
   	  CHGG ABCD 1
	  TNT1 A 0 A_JumpIfInventory("WindUpChecker",1,3)
	  TNT1 A 0 A_GiveInventory("WindUpChecker")
	  TNT1 A 0 A_PlaySound ("weapons/minig/start")
	  Goto AltHoldd
      TNT1 A 0 A_TakeInventory("WindUpChecker")
	  Goto AltWinddown
	AltHoldd:
	  TNT1 A 0 A_PlaySound("weapons/minig/spin",6)
      CHGG ABCD 1 
	  {
	  A_WeaponReady(WRF_DISABLESWITCH|WRF_NOSWITCH);
	  If(CountInv("WindUpChecker")==0){Return state("AltWinddown");}
      Else{Return state("");}
	  }
	  Loop
    AltWinddown:
      CHGG ABCDAABBCCDD 1
      CHGG AABBCCDD 2
	  Goto Ready
    Hold:
      TNT1 A 0 A_JumpIf(ACS_NamedExecuteWithResult("ToggleMinigun")==0, "NoReloadHold")
      TNT1 A 0 A_JumpIfNoAmmo("EmptyWindDown")
      TNT1 A 0 A_AlertMonsters
      TNT1 A 0 A_PlaySound("weapons/minig/spin",6)
      TNT1 A 0 A_GunFlash
      CHGG A 1 Offset(0,35) A_FireBullets (5, 5, 1, 8, "BulletPuff")
      TNT1 A 0 Radius_Quake (1, 2, 0, 1, 0)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_SetPitch(pitch-1.0)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG B 1 Offset(0,37) A_Firecustommissile("ChaingunCasingSpawner",0,0,-12,-18)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG C 1 Offset(0,39) A_FireBullets (5, 5, 1, 8, "BulletPuff")
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_SetPitch(pitch-0.6)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_Firecustommissile("ChaingunCasingSpawner",0,0,-12,-18)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      CHGG D 1 Offset(0,37)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_SetPitch(pitch+1.6)
      TNT1 A 0 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      TNT1 A 0 A_ReFire
	  TNT1 A 0 A_JumpIfInventory("WindUpChecker",1,"AltHoldd")
	  Goto Ready
	  }
}
I did use your basic code, so I have replace your sprites with vanilla CHgun ones.

EDIT:
Code bugs fixed.
Last edited by Void Weaver on Sun May 19, 2019 4:32 pm, edited 2 times in total.
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 »

Thanks, Void Weaver, that variation 1 worked perfectly.

Thanks so much! To all of you, I really appreciate the help.
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 »

Glad to help. ^_^

But I forget to place else one "TNT1 A 0 A_TakeInventory("WindUpChecker")" line right after entering into "Hold" state of the 1st variant - without it a some glitch are possible.
Also "TNT1 A 0 A_JumpIfInventory("WindUpChecker",1,"Hold")" lines in both variants should be logically moved down and placed after "TNT1 A 0 A_PlaySound ("weapons/minig/start")".
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 wrote:Glad to help. ^_^

But I forget to place else one "TNT1 A 0 A_TakeInventory("WindUpChecker")" line right after entering into "Hold" state of the 1st variant - without it a some glitch are possible.
Also "TNT1 A 0 A_JumpIfInventory("WindUpChecker",1,"Hold")" lines in both variants should be logically moved down and placed after "TNT1 A 0 A_PlaySound ("weapons/minig/start")".
I added that first line.

I'm having an issue now: Chaingun drops from chaingunners can't be picked up anymore. I added the spawn function to the HoldChaingun actor to get them to even appear but now they don't do anything. I added a pickup line after the spawn one but that didn't do anything.
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 »

What is HoldChaingun actor?
If it CustomInventory item then seems that you made a some mistake in its states.
User avatar
Dan_The_Noob
Posts: 880
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: I added that first line.

I'm having an issue now: Chaingun drops from chaingunners can't be picked up anymore. I added the spawn function to the HoldChaingun actor to get them to even appear but now they don't do anything. I added a pickup line after the spawn one but that didn't do anything.
try add an "+ALWAYSPICKUP" flag to the chaingun?
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: I added that first line.

I'm having an issue now: Chaingun drops from chaingunners can't be picked up anymore. I added the spawn function to the HoldChaingun actor to get them to even appear but now they don't do anything. I added a pickup line after the spawn one but that didn't do anything.
try add an "+ALWAYSPICKUP" flag to the chaingun?
I tried that, it makes so it says "You got a pickup" and does nothing else. i know how to get it to give me ammo but how do i make it so that it gives me the actual weapon?

Also, do either of you know how to make a custom ammo drop? I'm trying to make a box of bolts for my cryobow, but when I do a randomspawner for the rocket box and box of bolts, it doesn't spawn the bolts. I made a custom ammo for single bolts with a randomspawner for single rockets and that works just fine. It's the box that doesn't work. Here's the code for that:
Spoiler:
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 »

Oh, no... The Pickup state Curse strikes again. :\

The "Pickup:" state works ONLY FOR CustomInventory items. And it was already mentioned in your previous thread.
Btw, looks that you have the same trouble as TS of this thread, check it.
User avatar
Dan_The_Noob
Posts: 880
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: I tried that, it makes so it says "You got a pickup" and does nothing else. i know how to get it to give me ammo but how do i make it so that it gives me the actual weapon?

Also, do either of you know how to make a custom ammo drop? I'm trying to make a box of bolts for my cryobow, but when I do a randomspawner for the rocket box and box of bolts, it doesn't spawn the bolts. I made a custom ammo for single bolts with a randomspawner for single rockets and that works just fine. It's the box that doesn't work. Here's the code for that:
if you have 1 working example of an ammo pickup you can pretty much just copy it with different values to make another.
I did this to fix some wonky ammo types.

Here's one for a box of nails
Spoiler:
Post Reply

Return to “Scripting”