• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Problem With Ammo System

K

koirapoika74

Guest
So I've tried to implement an ammo system in my game but all the guns seem to hold the same values instead of holding their own. How would I accomplish this?

In oGunPickup Object
there is a code that gives the gun its ammo depending on whitch sprite it has.

if image_index=0 ammo=6
if image_index=1 ammo=14
if image_index=2 ammo=4

And in oPlayer object

if (mouse_check_button_pressed(mb_right)) {
if place_meeting(x,y,oGunPickup) && oGunPickup.ammo > 0{
ammo = oGunPickup.ammo}


// Throw old gun
with (instance_create(x, y, oGunPickup)) {
image_index = oldGun;


with oGunPickup{
ammo = oPlayer.ammo}




direction = point_direction(other.x, other.y, mouse_x, mouse_y);
speed = 14;
 
Last edited by a moderator:
K

koirapoika74

Guest
that doesnt really work because every time i change the gun it only creates a new 'dropped' gun object with the used guns sprite to the ground and it cant carry values over. Or atleast i could not get it to work
 
Last edited by a moderator:

Nidoking

Member
Look, you do this:

with (instance_create(x, y, oGunPickup)) {
image_index = oldGun;


with oGunPickup{
ammo = oPlayer.ammo}
The second with is inside the first, right? So it's still in the context of the newly-created oGunPickup. Why, then, do you use another with to set the ammo for ALL oGunPickups?
 
K

koirapoika74

Guest
when i write
ammo = oPlayer.ammo only it doent work for some reason
 

Nidoking

Member
I'm going to take the liberty of assuming that by "doesn't work" you meant to type "the dropped weapon gets the ammo count of the weapon that the player just picked up" and missed a couple of keys along the way, because surely, you meant to say something useful and not the most useless thing anyone on this forum can say. If I'm correct, that would be because you already did

if place_meeting(x,y,oGunPickup) && oGunPickup.ammo > 0{
ammo = oGunPickup.ammo}
That changes the player's ammo variable. If you want to set the new instance's ammo to the old value of the player's ammo, you'll have to store that somewhere first. I suggest a local variable, var oldammo.
 
Top