chefdez
Member
Hello everyone,
My enemy objects are no longer individually firing their ammo, instead if one of them is aware and firing, it will deplete the ammunition of every enemy instance in the room. Maybe someone can help me spot the mistake? I have been implementing "other" more often but removing it from my code doesn't seem to change the issue.
Enemy Aware Script
Alarm[0]:
My enemy objects are no longer individually firing their ammo, instead if one of them is aware and firing, it will deplete the ammunition of every enemy instance in the room. Maybe someone can help me spot the mistake? I have been implementing "other" more often but removing it from my code doesn't seem to change the issue.
Code:
// Create event:
canShoot = true;
enemypistolReload = 75;
enemyAmmo_p = 6;
inst = instance_nearest(x, y, obj_enemy);
enum EnemyState {
Unaware,
Aware,
};
state = EnemyState.Unaware;
Code:
var dir = point_direction(x, y, obj_player.x, obj_player.y);
var BulletSpeed = 10;
sprite_index = spr_enemyPistol;
image_speed = 0.2;
image_angle = dir;
shootTimer = 20
if shootTimer > 0
shootTimer--;
if shootTimer <= 0
{
if canShoot = true && global.healthPoints > 0
{
var bid = instance_create(x, y, obj_EnemyBullet) ;
bid.direction = dir ;
bid.speed = BulletSpeed ;
bid.image_angle = dir ;
audio_play_sound(snd_glock, 1, false);
shootTimer = 20
canShoot = false;
alarm[0] = 50;
}
if enemyAmmo_p = 0 && canShoot = false
if enemypistolReload > 0
{
enemypistolReload--;
if enemypistolReload <= 0
{
enemyAmmo_p = 6;
enemypistolReload = 75;
canShoot = true;
}
}
}
Code:
canShoot = true
enemyAmmo_p -= 1; // On the FIRST shot, it does NOT deplete the ammo by 1. It STAYS at 6 ! Why? Then // goes down to 5, 4, 3, 2, and on the last shot the enemy bullet is not created all while depleting ammo from // all other enemy instances.
if enemyAmmo_p <= 0
canShoot = false;