Page 1 of 2

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

PostPosted: Fri May 17, 2019 2:14 am
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?

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

PostPosted: Fri May 17, 2019 4:09 am
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 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:

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

PostPosted: Fri May 17, 2019 11:12 am
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.)

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

PostPosted: Fri May 17, 2019 12:08 pm
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

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

PostPosted: Fri May 17, 2019 9:30 pm
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 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.

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

PostPosted: Fri May 17, 2019 10:12 pm
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:

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

PostPosted: Fri May 17, 2019 10:23 pm
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.

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

PostPosted: Fri May 17, 2019 10:31 pm
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:

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

PostPosted: Fri May 17, 2019 11:16 pm
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?

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

PostPosted: Sat May 18, 2019 1:16 am
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:

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

PostPosted: Sat May 18, 2019 1:57 am
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.

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

PostPosted: Sat May 18, 2019 2:22 am
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 allExpand view
weapon.attacksound
i think?

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

PostPosted: Sat May 18, 2019 2:34 am
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 allExpand view
weapon.attacksound
i think?

Oh, gotcha. Oh well I suppose,

Here's what I have right now:
Spoiler:

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

PostPosted: Sat May 18, 2019 2:49 am
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.

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

PostPosted: Sat May 18, 2019 2:59 am
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!