Ammo counter

mah, i never done much with this thing, but i guess that you can “accumulate” ammo , when get some mags.

so , the player can just check “ammo” and “totalAmmo”

we say that a mags is a obj with 2 property :
mag : True
ammo : 20

when you grab it , add the ammo of mag to the “totalAmmo” of player (not the ammo of gun)

this is easy.

more convulted recharge the gun:
(can be bugged)


if ammo < maxAmmo and totalAmmo > 0:
    if totalAmmo - maxAmmo + ammo >= 0:
        totalAmmo -= maxAmmo - ammo
        ammo = maxAmmo
    else :
        ammo += totalAmmo
        totalAmmo = 0


is doable with bricks?

Yes, it is. :wink:

But this is complicated enough to calculate in Python.

You can, however it will step over two ticks. You can’t execute two instructions/conditions in one tick if they depend on the results of one another. You’d essentially have one expression controller set a result variable to True or False, then a property Changed sensor would trigger two more expression controllers that either add ammo or remove it

However, this is the main purpose of a Python Controller.

Wouldn’t that be a good topic for a tutorial challenge? “How to add Reloading to your Blender Game”

Not a bad one! I think it is a shame we don’t use the expression controller more often as it is very compact :slight_smile:

I need to start using it,

“if Ammo < 0 while Anim = 0 while key Space is pressed”

how would I expressionilize that?

“if Ammo < 0 while Anim = 0 while key Space is pressed”

keyboard sensor and expression brick

Ammo <= 0 AND Anim == 0

What if you reload half way through a clip, then your loosing the rest of the ammo that you didn’t use.

You could have “Reserve shells” and have it subtract the number added to the clip, and if the number is less then the “clip size” only add what remains,

In the real world, If I switch clips, I can have a half empty clip, that I pick up.

So loading that in the gun would not be a full clip,

So a “reloading clips” animation would be cool,(putting bullets into a clip until it is full)
with a max number of fast reloads, it would definitely push ammo conservation in a survival horror situation.

So you can hold 6 clips max,one in the gun, and 5 “holsters”

Ammo = 16 in gun - “Clip 0”
Clips = 5
“Clip 1=8 shells”
“Clip 2=16”
“Clip 3=4”
etc.

and you could switch clips, and then hold R - to fill the clip with spare bullets (takes much longer than speed reload)
and unloading clips could be a “gameplay mechanic” to fill your “stockpile”

Because a dropped enemy weapons clip will have had rounds spent from it,
this would be the most realistic option,

So we have

Ammo
stockpile
Switch mag slot left and right
reload magazine
unload magazine

This would also be nifty for multiple ammo types

(clip 1 = armor piercing)
Can a list contain another smaller list?

like

list Clips = [“Clip 1-A-A-I-A-A-E-E-E-E-E-E”,“Clip 2-E-E-E-E-E-E-E-E-E”]

where A = armor piercing, E = Empty , I = incendiary etc ?

Side note: I can picture weapons laying on the ground with a ammo indicator icon above them :smiley:

like a pie chart or something?

I was aware of that, so I decided to not let the player reload until there were no bullets left in the magazine.
Probably not the best approach, but meh