I have posted a similar thing many times this past month: AI’s are too unique for a script someone gives you off the internet to have a chance of working properly in your game.
What Goran has done is built a very simple Finite State Machine (FSM), which is perfect for a simple AI like this. Obviously he hasn’t given the whole script, which would define the variables ‘player_seen’ and ‘player_in_range’ as well as the functions ‘shoot_at_player’ and 'walk_toward_player, but these are easy to find.
player_seen can be done with a simple raycast:
hit = enemy.rayCastTo(player)
if hit != player:
player_seen = False
player_seen = True
Player in range is another simple few lines:
distance = enemy.getDistanceTo(player)
if distance > 15:
player_in_range = False
player_in_range = True
Shoot at player is a little more complex, so I shan’t go into the details here, but what I would do is use getAxisVect to find the direction the enemy is facing, use a raycast to find what the bullet hit, and then subtract from a property (something like health).
walk_towards_player is a simple function, thanks to the navmesh feature, and you can simply activate a steering/navigation logic brick.