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

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 a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: [SOLVED] Firing when I have no ammo to fire with?

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

by Dan_The_Noob » Sat May 18, 2019 2:01 am

No problem, i only started this like a week ago, so i'm learning at the same time.

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

by Alexagon » Sat May 18, 2019 1: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!

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

by Dan_The_Noob » Sat May 18, 2019 1: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.

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

by Alexagon » Sat May 18, 2019 1: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 all

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?

by Dan_The_Noob » Sat May 18, 2019 1: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 all

weapon.attacksound
i think?

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

by Alexagon » Sat May 18, 2019 12: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.

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

by Dan_The_Noob » Sat May 18, 2019 12: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:

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

by Alexagon » Fri May 17, 2019 10: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?

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

by Dan_The_Noob » Fri May 17, 2019 9: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:

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

by Alexagon » Fri May 17, 2019 9: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.

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

by Dan_The_Noob » Fri May 17, 2019 9: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:

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

by Alexagon » Fri May 17, 2019 8: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 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.

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

by ramon.dexter » Fri May 17, 2019 11:08 am

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?

by wildweasel » Fri May 17, 2019 10: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.)

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

by Dan_The_Noob » Fri May 17, 2019 3: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 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:

Top