How to reload only if you have enough ammo

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
User avatar
middlefingerman
Posts: 52
Joined: Mon May 04, 2020 12:55 pm
Location: On the toilet
Contact:

How to reload only if you have enough ammo

Post by middlefingerman »

My code here is attempting to do this, however, if i have 11 clips, it will still reload and load 12 clips
Spoiler: Code
Last edited by middlefingerman on Wed May 27, 2020 3:42 pm, edited 3 times in total.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: How to reload only if you have enough ammo

Post by Jarewill »

So, you are trying to make this pistol reload only if the player has 12 or more clips, right?
When I copied the code and checked it, the pistol didn't reload when I had only 11 clips.

The code works properly for me, the pistol reloads only when the player has at least 12 ammo in reserve.
Maybe the issue is somewhere else?

Does the player start with this pistol?
Putting "replaces Pistol" into the weapon won't make the player start with it.
Instead a new player class has to be defined that has this weapon as a "StartItem".
For reference, here's Doomguy and here's how to add custom classes.
User avatar
middlefingerman
Posts: 52
Joined: Mon May 04, 2020 12:55 pm
Location: On the toilet
Contact:

Re: How to reload only if you have enough ammo

Post by middlefingerman »

I already did that DoomPlayer Stuff, but something is wrong with the Alt-Fire, Which will reload no matter how much ammo i have.
User avatar
middlefingerman
Posts: 52
Joined: Mon May 04, 2020 12:55 pm
Location: On the toilet
Contact:

Re: How to reload only if you have enough ammo

Post by middlefingerman »

What the hell?
Apparently it works now.
It's the same code as earlier...
I don't even know.
User avatar
GoosebumpsFan
Posts: 1
Joined: Wed May 27, 2020 12:10 pm

Re: How to reload only if you have enough ammo

Post by GoosebumpsFan »

oh cool would you mind if i usd this code
User avatar
middlefingerman
Posts: 52
Joined: Mon May 04, 2020 12:55 pm
Location: On the toilet
Contact:

Re: How to reload only if you have enough ammo

Post by middlefingerman »

Sure, go ahead
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: How to reload only if you have enough ammo

Post by Jarewill »

The only issue with the shotgun that I spotted was that it loads 6 shells into the gun, takes away 12 shells from the player and loops once.
So it takes away 24 shells when reloading, and if the player only has 12 shells, it only loads 6 shells into the shotgun.

Aside that, the shotgun also doesn't reload if the player only has 11 shells, so what is exactly the problem here?
Unless the problem is what I just described, in which case it can be fixed by changing this:
Spoiler:
Edit: And since it was edited out of the OP, then I assume the issue has already been fixed?
User avatar
middlefingerman
Posts: 52
Joined: Mon May 04, 2020 12:55 pm
Location: On the toilet
Contact:

Re: How to reload only if you have enough ammo

Post by middlefingerman »

Yeah.
Oh well
Post Reply

Return to “Scripting”