My weapon shoots endlessly.

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
BUKASHKA228
Posts: 3
Joined: Sun Jul 05, 2020 11:08 pm

My weapon shoots endlessly.

Post by BUKASHKA228 »

My weapon shoots endlessly. After the gun fires 12 bullets, it must reload, but it continues to fire and does not use bullets.

Code: Select all

actor NewPistol : Weapon
{
Weapon.AmmoType1 "NewPistolLoaded"
 Weapon.AmmoUse1 1
 Weapon.AmmoGive1 0
 Weapon.AmmoType2 "9mmAmmo"
 Weapon.AmmoUse2 0
 Weapon.AmmoGive2 20
 Weapon.SlotNumber 2 
 Inventory.Pickupmessage "Picked up a pistol."
 + Weapon.Ammo_Optional
 + Weapon.Ammo_CheckBoth
 States
 {
 Ready:
  PISG A 1 A_WeaponReady(WRF_ALLOWRELOAD)
  Loop
 Deselect:
  PISG A 1 A_Lower
  Loop
 Select:
  PISG A 1 A_Raise
  Loop
 Fire:
  PISG A 0 A_JumpIfNoAmmo("Reload")
  PISG A 4
  PISG B 6 A_FireBullets(4,4,-1,6,"BulletPuff",1)
  PISG C 4
  PISG B 5 A_ReFire
  Goto Ready
 Reload:
  PISG A 0 A_JumpIfInventory("NewPistolLoaded", 12, 2)
  PISG A 0 A_JumpIfInventory("9mmAmmo", 1, "ReloadWork")
  PISG A 1 
  Goto Ready
 ReloadWork:
  PISG A 1 Offset(0,35) A_PlayWeaponSound("weapons/shotgr")
  PISG A 1 Offset(0,38)
  PISG A 1 Offset(0,44)
  PISG A 1 Offset(0,52)
  PISG A 1 Offset(0,62)
  PISG A 1 Offset(0,72)
  PISG A 1 Offset(0,82)
 ReloadLoop: // Here's where the magic happens!
  TNT1 A 0 A_TakeInventory("9mmAmmo", 1)
  TNT1 A 0 A_GiveInventory("NewPistolLoaded", 1) 
  TNT1 A 0 A_JumpIfInventory("NewPistolLoaded", 12, "ReloadFinish") 
  TNT1 A 0 A_JumpIfInventory("9mmAmmo", 1, "ReloadLoop") 
  Goto ReloadFinish 
 ReloadFinish:
  TNT1 A 8
  PISG A 1 Offset(0,82)
  PISG A 1 Offset(0,72)
  PISG A 1 Offset(0,62)
  PISG A 1 Offset(0,52)
  PISG A 1 Offset(0,44)
  PISG A 1 Offset(0,38)
  PISG A 1 Offset(0,35)
  PISG A 1 Offset(0,32)
  Goto Ready
 Flash:
  PISF A 3 Bright A_Light2
  PISF A 3 Bright A_Light1
  PISF A 0 Bright A_Light0
  Goto LightDone
 Spawn:
  PIST A -1
  Stop
 }
}
Just in case, I’ll insert this:

Code: Select all

ACTOR 9mmAmmo : Ammo replaces Clip
{
 Inventory.Amount 10 
 Inventory.MaxAmount 150
 Ammo.BackpackAmount 30 
 Ammo.BackpackMaxAmount 300 
 Inventory.Icon "CLIPA0" 
 Inventory.PickupMessage "Picked up some 9mm ammo."
 States
 {
 Spawn:
  CLIP A -1
  Stop
 }
}

ACTOR NewPistolLoaded : Ammo
{
 Inventory.MaxAmount 12
 +IGNORESKILL
}
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: My weapon shoots endlessly.

Post by Jarewill »

I think it's because your weapon has the +Weapon.Ammo_CheckBoth, which means that A_JumpIfNoAmmo will not jump unless the player is out of NewPistolLoaded and 9mmAmmo.
BUKASHKA228
Posts: 3
Joined: Sun Jul 05, 2020 11:08 pm

Re: My weapon shoots endlessly.

Post by BUKASHKA228 »

Thanks for the info. I would also like to make sure that as soon as there are 0 rounds in the store, the gun itself is reloaded. And it turns out that he makes 13 shots, well, or I can just make 11 rounds.
Sometimes some words may seem abnormal or off topic, I just don’t know English well (despite the fact that I it in a special school).
Post Reply

Return to “Scripting”