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

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.

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

Postby Alexagon » Fri May 17, 2019 2:14 am

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 9:32 pm, edited 1 time in total.
Alexagon
 
Joined: 22 Apr 2019
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia (Modern GZDoom)

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

Postby Dan_The_Noob » Fri May 17, 2019 4:09 am

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 allExpand view
      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
Dan_The_Noob
 
Joined: 07 May 2019
Twitch ID: Dan_The_Noob
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

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

Postby wildweasel » Fri May 17, 2019 11:12 am

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
wildweasel
change o' pace.
Moderator Team Lead
 
Joined: 15 Jul 2003

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

Postby ramon.dexter » Fri May 17, 2019 12:08 pm

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
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia

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

Postby Alexagon » Fri May 17, 2019 9:30 pm

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 allExpand view
      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.
Alexagon
 
Joined: 22 Apr 2019
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia (Modern GZDoom)

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

Postby Dan_The_Noob » Fri May 17, 2019 10:12 pm

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 10:30 pm, edited 4 times in total.
User avatar
Dan_The_Noob
 
Joined: 07 May 2019
Twitch ID: Dan_The_Noob
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

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

Postby Alexagon » Fri May 17, 2019 10:23 pm

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.
Alexagon
 
Joined: 22 Apr 2019
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia (Modern GZDoom)

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

Postby Dan_The_Noob » Fri May 17, 2019 10:31 pm

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:
User avatar
Dan_The_Noob
 
Joined: 07 May 2019
Twitch ID: Dan_The_Noob
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

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

Postby Alexagon » Fri May 17, 2019 11:16 pm

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?
Alexagon
 
Joined: 22 Apr 2019
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia (Modern GZDoom)

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

Postby Dan_The_Noob » Sat May 18, 2019 1:16 am

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:
User avatar
Dan_The_Noob
 
Joined: 07 May 2019
Twitch ID: Dan_The_Noob
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

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

Postby Alexagon » Sat May 18, 2019 1:57 am

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.
Alexagon
 
Joined: 22 Apr 2019
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia (Modern GZDoom)

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

Postby Dan_The_Noob » Sat May 18, 2019 2:22 am

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 allExpand view
weapon.attacksound
i think?
User avatar
Dan_The_Noob
 
Joined: 07 May 2019
Twitch ID: Dan_The_Noob
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

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

Postby Alexagon » Sat May 18, 2019 2:34 am

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 allExpand view
weapon.attacksound
i think?

Oh, gotcha. Oh well I suppose,

Here's what I have right now:
Spoiler:
Alexagon
 
Joined: 22 Apr 2019
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia (Modern GZDoom)

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

Postby Dan_The_Noob » Sat May 18, 2019 2:49 am

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.
User avatar
Dan_The_Noob
 
Joined: 07 May 2019
Twitch ID: Dan_The_Noob
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

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

Postby Alexagon » Sat May 18, 2019 2:59 am

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!
Alexagon
 
Joined: 22 Apr 2019
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Next

Return to Scripting

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest