All right, for one thing, you are calling a fairly slow function distance_to_object(argument0) over and over again. You can remedy this with a variable at the start.
Secondly, I don't think these guys have infrared goggles, so add a check to see whether or not they can actually see you.
And, I'm not 100% sure it'll work completely properly, as I am now at school, but I added a bit of code that allows the npc to pace around if it doesn't see the player. When I get home, I will test it out.
Remember to replace the following line with the info it asks for:
*I've tested this and it doesn't work properly. I'm working on it...*
wall_id = [whatever the wall is called]
Code:
var dist, wall_id, canseeplayer, angle, angle2, x2, y2, pace_buffer;
pace_buffer = 40
angle = floor(random(4))
x2 = pace_buffer
y2 = 0
wall_id = [whatever the wall is called]
dist = distance_to_object(argument0);
canseeplayer = ( collision_line(x,y,argument0.x,argument0.y,wall_id,false,true) == 0 )
if canseeplayer {
if dist > 75 {
if dist < 150 {
attack=1
}
if dist < 100 {
if shoot=1 {
instance_create(x,y,argument1)
alarm[0]=argument3
shoot=0
}
speed=0
}
}
if dist < 50 {
speed=0
attack=0
}
if dist < 175 {
image_angle=point_direction(x,y,argument0.x,argument0.y)
}
if dist < 25 {
if dist > 75 {
attack=1
}
}
}
else
{
image_angle = angle * 90
if collision_line(x,y,x+x2,y+y2,wall_id,false,true) == 0
{
x += x2 / 20
y += y2 / 20
}
else {
angle2 = floor(random(4))
if angle == angle2
angle2 += 1
if angle2 == 4
angle2 = 0
angle = angle2
x2 = 0
y2 = 0
switch ( angle ) {
case 0 : x2 = pace_buffer break
case 1 : y2 = pace_buffer break
case 2 : x2 = pace_buffer break
case 3 : y2 = pace_buffer break
}
}
}
//arg0: Player obj name
//arg1: Bullet obj name
//arg2: Player bullet obj name
//arg3: Shoot timer
//arg4: Name of obstacle obj. (Ex: wall)
//Include in Create event:
//shoot=1
//attack=0
//image_angle=random(360)
//Include in Step event:
//basic_ai(arg0,arg1,arg2,arg3,arg4)