Ammo add to python code but with bricks to collect additional ammo

mport bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

#self
self = scene.objects[own.name]
movement = scene.objects['player']

#properties
m24ammo = own['m24_ammo']
glockammo = own['glock_ammo']
recoil = own['recoil']
equipped = own['equipped']
reload = own['reload']
change = own['change']
ADS = own['ADS']
shoot = own['shoot']
#automatic fire
auto = cont.sensors['auto']

#single fire
single = cont.sensors['single']

#sounds
m24shot = cont.actuators['m24_fire']
glockshot = cont.actuators['glock_fire']

#animations

Rm24 = cont.actuators['m24recoil']
adsrecoil = cont.actuators['adsrecoil']
Rglock = cont.actuators['Glockrecoil']
adsGrecoil = cont.actuators['adsGrecoil']

#glockfire

if single.positive == True and glockammo >= 1 and equipped == 2 and reload == False and change == False and ADS == 0 and movement['control'] == True and shoot == True:
    own['glock_ammo'] -= 1
    cont.activate(Rglock)
    cont.deactivate(Rglock)
    own.sendMessage("4")
    own.sendMessage("glockflare")
    cont.activate(glockshot)
    cont.deactivate(glockshot)
if single.positive == True and glockammo >= 1 and equipped == 2 and reload == False and change == False and ADS == 2 and movement['control'] == True and shoot == True:
    own['glock_ammo'] -= 1
    cont.activate(adsGrecoil)
    cont.deactivate(adsGrecoil)
    own.sendMessage("4")
    own.sendMessage("glockflare")
    cont.activate(glockshot)
    cont.deactivate(glockshot)

if single.positive == True and reload == True and equipped == 2 or single.positive == True and change == True and equipped == 2:
    cont.deactivate(Rglock)

if single.positive == False and equipped == 2:
    cont.deactivate(adsGrecoil)

#m24 fire   
if auto.positive == True and m24ammo >= 1 and recoil >= 0 and recoil <= 3 and equipped == 1 and reload == False and change == False and ADS == 0 and movement['control'] == True:
    cont.activate(Rm24)
    cont.deactivate(Rm24)
    own['m24_ammo'] -= 1
    own.sendMessage("1")
    own['recoil'] += 1
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)

if auto.positive == True and m24ammo >= 1 and recoil >= 3 and recoil <= 6 and equipped == 1 and reload == False and change == False and ADS == 0 and movement['control'] == True:
    cont.activate(Rm24)
    cont.deactivate(Rm24)
    own['m24_ammo'] -= 1
    own.sendMessage("2")
    own['recoil'] += 1
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)
    
if auto.positive == True and m24ammo >= 1 and recoil == 7 and equipped == 1 and reload == False and change == False and ADS == 0 and movement['control'] == True:
    cont.activate(Rm24)
    cont.deactivate(Rm24)
    own['m24_ammo'] -= 1
    own.sendMessage("3")
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)

    
if auto.positive == True and reload == True and equipped == 1 or auto.positive == True and change == True and equipped == 1:
    cont.deactivate(Rm24)
    cont.deactivate(adsrecoil)
    
if auto.positive == False and equipped == 1 or reload == True and equipped == 1 or change == True and equipped == 1 or movement['control'] == False:
    self['recoil'] = 0

#ads recoil   
if auto.positive == True and m24ammo >= 1 and recoil >= 0 and recoil <= 3 and equipped == 1 and reload == False and change == False and ADS == 2 and movement['control'] == True:
    cont.activate(adsrecoil)
    cont.deactivate(adsrecoil)
    own['m24_ammo'] -= 1
    own.sendMessage("1")
    own['recoil'] += 1
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)

if auto.positive == True and m24ammo >= 1 and recoil >= 3 and recoil <= 6 and equipped == 1 and reload == False and change == False and ADS == 2 and movement['control'] == True:
    cont.activate(adsrecoil)
    cont.deactivate(adsrecoil)
    own['m24_ammo'] -= 1
    own.sendMessage("2")
    own['recoil'] += 1
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)
    
if auto.positive == True and m24ammo >= 1 and recoil == 7 and equipped == 1 and reload == False and change == False and ADS == 2 and movement['control'] == True:
    cont.activate(adsrecoil)
    cont.deactivate(adsrecoil)
    own['m24_ammo'] -= 1
    own.sendMessage("3")
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)

if auto.positive == False and equipped == 1:
    cont.deactivate(adsrecoil)

In this code, there is a limit to how much ammo a weapon has within the scene. So once there is no more ammo to reload, if I want to add a simple pick up using the brick, where do I add to that here, and what to add to give more ammo.

If I remember, the gun reloads twice in total, so once both ammo amount is used the weapon is useless. I want to use the main weapon which is the glock. So the handgun.

#glockfire

if single.positive == True and glockammo >= 1 and equipped == 2 and reload == False and change == False and ADS == 0 and movement['control'] == True and shoot == True:
    own['glock_ammo'] -= 1
    cont.activate(Rglock)
    cont.deactivate(Rglock)
    own.sendMessage("4")
    own.sendMessage("glockflare")
    cont.activate(glockshot)
    cont.deactivate(glockshot)
if single.positive == True and glockammo >= 1 and equipped == 2 and reload == False and change == False and ADS == 2 and movement['control'] == True and shoot == True:
    own['glock_ammo'] -= 1
    cont.activate(adsGrecoil)
    cont.deactivate(adsGrecoil)
    own.sendMessage("4")
    own.sendMessage("glockflare")
    cont.activate(glockshot)
    cont.deactivate(glockshot)

if single.positive == True and reload == True and equipped == 2 or single.positive == True and change == True and equipped == 2:
    cont.deactivate(Rglock)

if single.positive == False and equipped == 2:
    cont.deactivate(adsGrecoil)

This is the fire and ammo/ used?

So at the most basic, collision with glockammo property then adds more ammo,

Collision

I don’t know. Seems like a code only solution?

Collision Python script or property

Collision And property Add +5 or something

collectammo

So a overlay scene will state ammo collected and remove after, once the collision has occurred, the bricks isn’t the problem. It is how it would work with that code.

without seeing the reload code (maybe i missed it in that cluster) i dont know for sure, but if the ammo pool is a normal game property, a simple collision sensor on the powerup which sends a message to the player, then the message sensor activates a property add actuator.

import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

#properties
reload = own['reload']
timer = own['timer']
m24ammo = own['m24_ammo']
glockammo = own['glock_ammo']
change = own['change']
equipped = own['equipped']
ads = own['ADS']

#input
Rkey = cont.sensors['R']
auto = cont.sensors['auto']
single = cont.sensors['single']

self = scene.objects[own.name]
movement = scene.objects['player']

#m24 reload animation
reloadm24 = cont.actuators['reloadm24']
Rm24 = cont.actuators['m24recoil']

#glock reload animation
reloadGlock = cont.actuators['reloadGlock']

Rglock = cont.actuators['Glockrecoil']

#reload sound
m24R = cont.actuators['reload_m24']
glockR = cont.actuators['reload_glock']

#m24 reload criteria
if m24ammo <= 0 and auto.positive and reload == False and change == False and equipped == 1 and ads <= 0 and movement['control'] == True:
    self['reload'] = True
    cont.deactivate(Rm24)
    
#glock reload criteria
if glockammo <= 0 and single.positive and reload == False and change == False and equipped == 2 and ads <= 0 and movement['control'] == True:
    self['reload'] = True
    cont.deactivate(Rglock)

#m24 reload    
if Rkey.positive and reload == False and change == False and m24ammo != 30 and ads <= 0 and movement['control'] == True:
    self['reload'] = True
    cont.deactivate(Rm24)
    
if Rkey.positive and reload == False and change == False and glockammo != 18 and ads <= 0 and movement['control'] == True:
    self['reload'] = True
    cont.deactivate(Rglock)
    
#reloading for m24
if reload == True and timer == 0 and equipped == 1:
    own.sendMessage("m24_reload")  
if reload == True and timer < 181 and equipped == 1:
    cont.activate(reloadm24)
    own['timer'] += 1
if reload == True and timer == 146 and equipped == 1:
    cont.activate(m24R)
if reload == True and timer == 181 and equipped == 1:
    cont.deactivate(reloadm24)
    self['m24_ammo'] = 30
    self['ADS'] = 0
    self['reload'] = False
    self['timer'] = 0
    
#reloading for Glock
if reload == True and timer == 0 and equipped == 2:
    own.sendMessage("Glock_reload")
if reload == True and timer < 121 and equipped == 2:
    cont.activate(reloadGlock)
    own['timer'] += 1
if reload == True and timer == 94 and equipped == 2:
    cont.activate(glockR)

if reload == True and timer == 121 and equipped == 2:
    cont.deactivate(reloadGlock)   
    self['glock_ammo'] = 18
    self['ADS'] = 0
    self['reload'] = False
    self['timer'] = 0

This is the reload.

I got the idea from an old tutorial. It was either that or battery pickup for the light. I don’t know, it seemed an interesting addon for a mini game.

Don’t think so. There is no limit.
The ammo Property says how many ammo is loaded into the weapon. When the ammo is 0, the weapon reloads and the ammo gets filled up.

I wanted a feature where I collect. I think the aim is for the player to escape to the train down the stairs, while escaping the AI, I tried using an empty to load the AI, but that didn’t work. I tried duplicating that AI, it turned out messy.

So far only one AI.

The cube Ai was for a custom enemy, something more planned beyond this basic edit.

So collecting an item like a bottle, or ammo or battery would add to the player’s challenge.

When I fired the glock gun there is no more ammo. I’m sure it only reloads twice. I will display a video, of what happens.

Ah okay, the glock does seem to reload.

Hmm, okay then. Well, perhaps to get the battery for the light on the gun?

I was able to duplicate both AI. They both seek the player.

a little nickpicky, but self shouldnt be used generally unless in a class function. btw, self = scene.objects[own.name] is redundant as it basically just points to own anyway.

to add an ammo pool, simply create properties like “glock_mags” and “m24_mags” or something and right under the self['m24_ammo'] = 30 add the line own["m24_mags"] -= 1 (magazine used). then you can have property actuators add to that value. be sure to add and own["m24_mags"] >= 1 in the reload trigger.

Hmm, well it appears to not have that problem. The code was made by somebody else, so I don’t know.

It may not add to a challenge for the player, for Ammo. More a task and AI that would be. At the end of the day, there is more than one weapon, there is a limit on Grenades, and smoke grenades. Then you have a great knife. I also wanted to add another item but that didn’t work out.

So if I had one weapon, it may of made sense to have an ammo limit, due to the fact that one weapon alone is all the player has. Even one weapon alone, means the player has ammo.

I got the idea from an old tutorial. It was either that or battery pickup for the light.

I wanted a feature where I collect. I think the aim is for the player to escape to the train down the stairs, while escaping the AI, I tried using an empty to load the AI, but that didn’t work. I tried duplicating that AI, it turned out messy.. .