I want to make some pretty advanced NPC behavior which allows the enemy to reload their guns, and run out of reserve ammo, render them defenseless or attack the player in melee. No animations involve.
EnemyReloaded = 0;
if EnemyAmmo > 0
- SHOOT: CreateObject…
if EnemyAmmo <= 0
if ReserveAmmo >= 12
- RELOAD: EnemyAmmo += 12; || ReserveAmmo -= 12; || EnemyReloaded = 1;
if EnemyReloaded != 1 && ReserveAmmo > 0
- EnemyAmmo += ReserveAmmo
- ReserveAmmo = 0;
if EnemyAmmo <= 0 && ReserveAmmo <= 0
Can you explain the reload part? I also want to know how to add reload time to the NPC as well.
When the enemy ammo is 0 or below, it checks if there is 12 or more than 12 ammo left in the reserve and if there is it fills the enemy ammo with just 12 bullets and takes it away from the reserve ammo. The part below that only works if there aren’t 12 bullets left in the reserve. It then takes whats left in the reserve and fills the ammo with it and also takes away the reserve ammo.
To add some reload time you can use the new Wait() function before you add the reserve ammo to the enemy ammo.
I managed to use the Wait function, but there’s a problem. The enemy NPC stopped firing bullets when reserve ammo reached zero. Here’s a screenshot:
That is because the “shooting” event is also checking if the reserve ammo is still above 0.
I fixed the problem, but, there’s something I want to ask you. When I messing around with the Wait function, the enemy NPC double reload (At first, the NPC fire exactly 30 bullets. Later on, the NPC starts to automatically reload another 30 after finishing the first 30 bullet without waiting, thus firing a total of 60 bullets). Here’s a screenshot of my event editor:
You can add a “Trigger Once” condition to the event that adds the bullets. I think that should fix it.
That seems to be alright. Does it work?
Yes, it worked. Thank you very much for all of this.
You’re welcome. I’m glad I could help.