Ammo counter

Hello… again,
I am now trying to make an Ammo Counter, I’ve got the overlay scene working and everything.
Now all I see is a small “0” in the bottom corner (to count the ammo)

Because I’ve never used overlay scenes before, how could I make the counter thing go down?

EDIT: I know how to make the counter go up, how would I start it at say 20 and work it’s way down?

You have a couple of options and it all depends on how you are storing your ammo value.

The easy way is to put the ammo amount in the global dictionary and just have your ammo counter display that.
You can also use messages to pass data between scenes so you could have an object send a message to the counter
that tells it what to display.

Using my noodle, I realized that the numbers in the “game property” box was what set the default amount. I then did Add -1, so now it goes down (hooray!!)

Now I just need to have it go back to 20 once you reload

UPDATE: It now resets (kinda…)
What I did was when pressing “R” it adds 20 bullets to the gun. If you don’t shoot, then it still adds 20 (now you have 40)
How can I make the number go back to 20, rather than ADDING 20?

EDIT: Figured it out, instead of making it “ADD”, make it assign. Damn it, made this thread for nothing

NEW QUESTION:
How do I make limits on stuff? For example, after reloading 5 times, you’re out of mags. How would I make it so you CAN’T reload anymore?
The ammo & bullet counter both share the same properties, if that helps

Second question: How do I make the key to reloading only work after a shot has been fired?

You use an “And” controller to only trigger reloading if they press the “R” and their magazine count is > 0. You will have to have the magazine count as a property on the object that is doing the reloading.

My brain is broken. So many different objects, SO LITTLE TIME X[

I’ve got the two planes (the overlay scene which project the counters)
and the empty which sends the messages. I’m assuming I would add the mag count to the RELOAD plane? (or the ammo plane?)

Sorry, I’m just uber confused, and I know I shouldn’t be…

Here ya go bud

you can also “Sync” the properties with globals:D

here is a example of a global with lists (second blend keyDictAndDoor)

So, get a handle of the logic controlled gun, pew pew!

than set up a python script that copies the properties from the gun (currently held) to a global

than have your “overlay” copy those globals as it’s own value

Attachments

LogicGunAndMag.blend (490 KB)KeyDictandDoor(Commented).blend (579 KB)

Here is my file, all I need to do is make it so you CAN’T reload once you’ve run out of clips
I literally spent ALL day so far doing this… sigh

Attachments

TheFile.zip (647 KB)

My gun can’t reload after 5 clips,

check it out,

(property “Mags”)

you could have the player colliding with a magazine add 1 to that, and delete the “picked up” mag

Here, I renamed all the bricks so it’s easier to get the hang of

I’ll even help with the Pick it up system


Property7 =( Anim = 0)
:smiley:

Attachments

LogicGunAndMag(NamedLogic).blend (490 KB)

Not sure what I’m lookin’ for here…
too many bricks :C

Ok, If you press shoot, Do you have bullets in the clip? are you already in mid animation? if not already in mid shooting, and you have bullets then start animation firing and add projectile, while subtracting 1 from clip.

Reload button press- Do you have 40 in there already? if not , are you shooting? if not do you have any extra mags? if you have mags, play animation, reload, and subtract 1 mag.

this controls the animationstate as well as ammo and magazines.

the property “Anim” is what is controlling the actions,

So when I set Anim to 1 - this triggers the shooting animation
because of the "Property - Interval - Anim - Min 1 - max 9 ---------and-------------Add 1 to “Anim”

Changing Anim to 1 causes it to then go 2-3-4-5-6-7-8-9-10

and the next step is the

if Anim = 10 --------------------and------------------anim = 0

(reset for next animation)

added prettyness :smiley:

Attachments

LogicGunAndMag(NamedLogicPretty).blend (558 KB)

Update - added more pretty

Attachments

LogicGunAndMag(NamedLogicPrettier).blend (562 KB)

Just so that you get an overall concept of this;

Essentially you’re dealing with a single concept: the number of magazines. In reality, each magazine has its own value for how much ammo it contains. However, unless you’re actually implementing magazines as separate objects, we tend to merge this into a single object. So, we’d create a property “mag” that represents how many magazines we have available. Then the ammo count represents the amount of ammo in the current magazine.

We then decrement (reduce) the ammo count by one every time we make a shot. To make a shot, we must check that it is valid, meaning that we have ammo (ammo > 0) and we have clicked the left mouse. You can use the expression controller for this; assuming your ammo property is called “ammo” and your mouse sensor is called “shoot”:


ammo > 0 and shoot

This would connect to your shooting actuators, and a property actuator that adds -1 to the ammo count.

Now, to facilitate reloading, use a similar expression controller, with the reload key “reload”


ammo == 0 and reload and mag > 0

This would activate a property actuator setting the ammo to full. We’d have another property actuator that adds -1 to the magazine count. It will only do this if we have a magazine available.

We could also add support for a reload delay. Simply add a timer property called “delay” and a float property called “shoot_interval”, which represents the time between shots. Now, our shooting logic controller looks like this:


shoot and ammo > 0 and delay >= shoot_interval

Now we add another actuator to the shoot controller that sets the delay property to 0.0

In this instance you don’t need to use the expression controller; you can use property sensors (for the most part) however, It’s cleaner to use in my opinion.

And another update - now the “Ammo counter” is on the gun

MR. goose,

download this one please:D

Attachments

LogicGunAndMag(NamedLogicPrettierColorChange).blend (588 KB)

Well, I’ve got an idea on how to work the reloading once I get to that stage… I just want my gun (post #8) to not reload once there are no mags left. Wouldn’t this be easily achievable with a message or something?

That file is awesome :3

Thanks :smiley:

I think I am finally starting to get the hang of For loops in logic, and triggering python with them :smiley:

In the reload logic cluster


the red lines mean - is animation 0?

is ammo between 0 and 39?

is r being pressed?

do you have a Mag ? min 1 - max 5--------------- ?

that means if you have a magazine left reload, so if Mags = 0

No reload :smiley:

this limits you to 5 mags

you can change it to anything :smiley:

Attachments

LogicGunAndMag(TriggerAndCases).blend (603 KB)

Yep, the limit of 5 is fine.
I’ll continue this after supper, sorry for (me) being so stupid X[

You are not stupid, logic is hard to “wrap around your brain” until you have a “key”

A file that is explained out / commented to you :smiley:

same with all forms of complex math for me or coding

(moved clip drop spot) + tinkered

Attachments

ReapeatingPistol.blend (603 KB)

And finally a holographic display :smiley:

Attachments

HolographicHud.blend (688 KB)