[SOLVED] Firing when I have no ammo to fire with?

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] Firing when I have no ammo to fire with?

Post by Alexagon »

So I'm making an altfire for the revolver I have that shoots all 6 shots with one press. Everythig is working except for two things:

1. When I'm completely out of ammo in both the clip and reserve the altfire still shoots and can shoot endlessly. The odd thing is, earlier today it was working without this issue, but all of a sudden without editing the code it's no longer working as intended and this issue showed up.

2. The altfire shoots 6 shots regardless oif how much ammo is left in the clip when I use the altfire.

Here's the code I have for the revolver (it's a bit long so bear with me):
Spoiler:
Would anyone be so kind as to help me solve these issues?
Last edited by Alexagon on Sun Jun 09, 2019 8:32 pm, edited 1 time in total.
User avatar
Dan_The_Noob
Posts: 870
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Firing when I have no ammo to fire with?

Post by Dan_The_Noob »

Firstly, holy shit that's a lot of offsets O_O

may be easier to just make duplicate animation frames and adjust them that way so you can call them as a sequence.

but ALSO
your AltFire code:
Spoiler:
My change to the first few lines:

Code: Select all

      TNT1 A 0 A_JumpIfInventory("PistolMag",6,"Loaded") //checks if mag full, skips to fire sequence
TNT1 A 0 A_PlaySound("dryfire") //plays click if not available
goto Ready //jumps back to not firing
      TNT1 A 0 A_TakeInventory("PistolMag", 1, TIF_NOTAKEINFINITE) //this should be AFTER shots to make sure it takes ammo when check has been made
      TNT1 A 0 A_JumpIfInventory("PistolMag", 1, 1)//this is checking if the mag has at least 1 bullet so it's not needed (because you want 6 and also have taken 1 before this so it will never be 6 here)
Loaded:
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Firing when I have no ammo to fire with?

Post by wildweasel »

Dan_The_Noob wrote:may be easier to just make duplicate animation frames and adjust them that way so you can call them as a sequence.
Easier, but also takes up a lot more space.

(Side note: I'd be interested in finding a way to make offset-based animation easier and less messy, so one could have the best of both worlds.)
User avatar
ramon.dexter
Posts: 1520
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Firing when I have no ammo to fire with?

Post by ramon.dexter »

wildweasel wrote:
(Side note: I'd be interested in finding a way to make offset-based animation easier and less messy, so one could have the best of both worlds.)
Well, I used the textures lump approach. I defined the frames as sprites in textures lump,using SLADE's wysiwyg textures editor with offsets and anything. That kept the source without hundreds of duplicate picture files, while allowing lots of frames to be defined. I think buddy Vostyok taught me this method.

sorry for the OT
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Firing when I have no ammo to fire with?

Post by Alexagon »

Dan_The_Noob wrote:Firstly, holy shit that's a lot of offsets O_O

may be easier to just make duplicate animation frames and adjust them that way so you can call them as a sequence.

but ALSO
your AltFire code:
Spoiler:
My change to the first few lines:

Code: Select all

      TNT1 A 0 A_JumpIfInventory("PistolMag",6,"Loaded") //checks if mag full, skips to fire sequence
TNT1 A 0 A_PlaySound("dryfire") //plays click if not available
goto Ready //jumps back to not firing
      TNT1 A 0 A_TakeInventory("PistolMag", 1, TIF_NOTAKEINFINITE) //this should be AFTER shots to make sure it takes ammo when check has been made
      TNT1 A 0 A_JumpIfInventory("PistolMag", 1, 1)//this is checking if the mag has at least 1 bullet so it's not needed (because you want 6 and also have taken 1 before this so it will never be 6 here)
Loaded:
That didn't seem to change anything, and the goto ready part makes it not fire at all but still take ammo.
User avatar
Dan_The_Noob
Posts: 870
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Firing when I have no ammo to fire with?

Post by Dan_The_Noob »

Spoiler:


I can't find "ReadyFull" but i may be blind.

also, it shouldn't take any ammo if it skips to ready... i'll look through the code it just seems really intense with all the animation frames

--EDIT--
OHHHHHH you want the revolver to fanfire when you AltFire!
i took out all the offsets n crap jus to read it and i see now ...
OK let me see.

--EDIT 2--
here's what the code looks like without all the animation offsets (just "do stuff" code left) and i removed A_AlertMonsters playing each shot and the weapon flags etc.
and honestly... I think removing +Weapon.AMMO_OPTIONAL is probably your solution. but you could cleanup things like AltFire could be a reloadcheck loop check.

or you could replace AltFire with just a "Hold:" state for Fire (since it doesn't seem too different anyway?) then use AltFire for the punch stuff.
Spoiler:
Last edited by Dan_The_Noob on Fri May 17, 2019 9:30 pm, edited 4 times in total.
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Firing when I have no ammo to fire with?

Post by Alexagon »

Dan_The_Noob wrote:
Spoiler:


I can't find "ReadyFull" but i may be blind.

also, it shouldn't take any ammo if it skips to ready... i'll look through the code it just seems really intense with all the animation frames

--EDIT--

OHHHHHH you want the revolver to fanfire when you AltFire!
i took out all the offsets n crap jus to read it and i see now ...
OK let me see.
Yeah, sorry if I wasn't too clear about it. And thanks.
User avatar
Dan_The_Noob
Posts: 870
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Firing when I have no ammo to fire with?

Post by Dan_The_Noob »

no problem, here's what i came up with for feedback/fixes
Dan_The_Noob wrote: here's what the code looks like without all the animation offsets (just "do stuff" code left) and i removed A_AlertMonsters playing each shot and the weapon flags etc.
and honestly... I think removing +Weapon.AMMO_OPTIONAL is probably your solution. but you could cleanup things like AltFire could be a reloadcheck loop check.

or you could replace AltFire with just a "Hold:" state for Fire (since it doesn't seem too different anyway?) then use AltFire for the punch stuff.
Spoiler:
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Firing when I have no ammo to fire with?

Post by Alexagon »

Removing the ammo optional part didn't change anything unfortunately. As far as the hold goes, I want to make it so that one click of the altfire makes it empty the entire magazine, to make it a commitment thing.

Would it be helpful if I upload the pk3 for you to take a look at personally?
User avatar
Dan_The_Noob
Posts: 870
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Firing when I have no ammo to fire with?

Post by Dan_The_Noob »

I guess but you already pasted it in the post.
I think the first step is working out a loop. I would recommend a quick google for "A_CheckForReload" help

here's some code i made to give my autoshotgun a burst-fire you can adapt it if you like, i've added some comments to understand each line better.
Spoiler:
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Firing when I have no ammo to fire with?

Post by Alexagon »

Dan_The_Noob wrote:I guess but you already pasted it in the post.
I think the first step is working out a loop. I would recommend a quick google for "A_CheckForReload" help

here's some code i made to give my autoshotgun a burst-fire you can adapt it if you like, i've added some comments to understand each line better.
Spoiler:
So I tried adapting this code for my thing, but it was making it wonky and not making and sounds for some reason so I undid the changes and just added the checkforreload line to the very bottom before goto dryfire and it allows it to do the burst properly which is cool since I can get rid of the copy pasted code I had, but the issues I'm having with clip amount and it shooting when I'm out of ammo are still there.
User avatar
Dan_The_Noob
Posts: 870
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Firing when I have no ammo to fire with?

Post by Dan_The_Noob »

alright, pop up your new altfire code?

have a look, it sounds like you're missing an ammo check, or your ammo check is missing an exit.

Also, yours wouldn't make any sound because my shotgun has the sound applied as an actor property

Code: Select all

weapon.attacksound
i think?
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Firing when I have no ammo to fire with?

Post by Alexagon »

Dan_The_Noob wrote:alright, pop up your new altfire code?

have a look, it sounds like you're missing an ammo check, or your ammo check is missing an exit.

Also, yours wouldn't make any sound because my shotgun has the sound applied as an actor property

Code: Select all

weapon.attacksound
i think?
Oh, gotcha. Oh well I suppose,

Here's what I have right now:
Spoiler:
User avatar
Dan_The_Noob
Posts: 870
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Firing when I have no ammo to fire with?

Post by Dan_The_Noob »

Alexagon wrote: Oh, gotcha. Oh well I suppose,

Here's what I have right now:
Spoiler:
"TNT1 A 0 A_JumpIfInventory("PistolMag", 1, 1)" basically does nothing, it effectively says "if pistol mag has 1 bullet or more, do next step, else do next step" BUT if you change the last 1 to a 2 and add an exit "goto dryfire" it will say "if pistolmag has 1 bullet or more, jump to shooting, else goto dryfire"
also, A_TakeInventory is happening before the ammo check so it could take the last shot before it's fired. so move it further down.

TL;DR
-> move "A_TakeInventory" before "A_FireBullets"
-> make a "goto dryfire" after the "TNT1 A 0 A_JumpIfInventory("PistolMag", 1, 2<<<changed to 2)"
so that if you have no bullets in the mag it will jump to dryfire, if you have at least 1 it will jump to the second thing after and continue to firing.
Alexagon
Posts: 74
Joined: Mon Apr 22, 2019 2:58 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Firing when I have no ammo to fire with?

Post by Alexagon »

Dan_The_Noob wrote:
Alexagon wrote: Oh, gotcha. Oh well I suppose,

Here's what I have right now:
Spoiler:
"TNT1 A 0 A_JumpIfInventory("PistolMag", 1, 1)" basically does nothing, it effectively says "if pistol mag has 1 bullet or more, do next step, else do next step" BUT if you change the last 1 to a 2 and add an exit "goto dryfire" it will say "if pistolmag has 1 bullet or more, jump to shooting, else goto dryfire"
also, A_TakeInventory is happening before the ammo check so it could take the last shot before it's fired. so move it further down.

TL;DR
-> move "A_TakeInventory" before "A_FireBullets"
-> make a "goto dryfire" after the "TNT1 A 0 A_JumpIfInventory("PistolMag", 1, 2<<<changed to 2)"
so that if you have no bullets in the mag it will jump to dryfire, if you have at least 1 it will jump to the second thing after and continue to firing.
Welp, you just fixed the problems I was having with this revolver. I'm still learning this stuff so I appreciate the patience. And thanks for the help in general!
Post Reply

Return to “Scripting”