Gun reloading doesn't check for ammo amount

Started by ASamInTheWild2011 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Dec 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Gun reloading doesn't check for ammo amount

(Sorry if the solution to this problem is really obvious or if the code is unnecessarily rough, I have never done this much work with variables before and I don't understand what I'm doing wrong!)

 

Essentially, I'm trying to make a reload system for my gun item. How it is meant to work is it tries to figure out how much ammo it should add to the gun based on the amount of ammo in the player's inventory, then puts that amount of ammo into the gun and subtracts that amount of ammo from the player's inventory.

The reloading works fairly well, but there is one huge problem in that the gun always loads 10 rounds, even if the player has less than 10. The rest of the system works fine, (the gun doesn't reload if there is no ammo in the inventory and the reloading only takes however much ammo is needed to get to 10 rounds) it's just that the gun always reloads to 10 rounds (if that makes any sense). If anyone could help in any way it would be much appreciated!

 

Joined Nov 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
check the amount of ammo the…
Wed, 02/18/2026 - 16:41

check the amount of ammo the player has before doing the reloading loop, and prevent it from going past that number. For example after the

"Set number  Global: (pistol_ammo_to_load) yadda yadda"

you could say 

"if          (player_ammo_amount) < (pistol_ammo_to_load)

then      Set number  Global: (pistol_ammo_to_load) to: (player_ammo_amount)"