I´ve got a weapon which can shot 18 times. Every shot adds 1 to “shot counter”.
If you pick up an ammo pack there will be 18 added to “ammo_available”.
If you shot 18 times or you press the r-Key and “ammo_available is > 0 the weapon reloads automaticly.
That works fine but:
Let´s say there are 18 bullets in the weapon, that means you can shot 18 times.
But your “ammo_available” is just 3 bullets.
Then the result is that “shot_counter” counts 18 and adds 18 to “current_ammo”, but “ammo_available”
is now -15 ( because of: “if (ammo_available > 0)”
But that is not correct. If I got lets say just 3 bullets in reserve it should just add this 3 bullets to “current_ammo”
How can I fix the problem?
Here is the code:
var current_ammo = 18;
var ammo_available = 0;
var shot_counter = 0;
function reload()
{
if (ammo_available > 0)
{
ammo_available -= shot_counter;
current_ammo += shot_counter;
current_ammo = min(18, current_ammo);
while (weapon2.frame <=160)
{
weapon2.frame += 3 * time_step;
wait(1);
}
snd_play (reload_wav, 50, 0);
shot_counter = 0;
}
}
action ammo_pack2
{
my.passable = on;
while (player == null) {wait (1);}
while (vec_dist (player.x, my.x) > 70) || (ammo_available >= 180 )
{
my.pan += 3 * time_step;
wait (1);
}
ent_remove (my);
ammo_available += 18; // add more ammo
ammo_available = min(180, ammo_available);
}