Legacy GM Problem with enemy chasing me(I think it's my alarm event)

S

Soco

Guest
I'm making a jrpg game and I have an enemy that chases me when I get into his sight or aggro range. However, when I leave his sight, he stops chasing me. I'd prefer him to chase me for some time before giving up. I'm thinking about 5 seconds, maybe less, I dunno, that part is unimportant right now. Here's my logic so far, and maybe someone can tell me what I'm doing wrong.

This is my enemy searching for my player.

[
Code:
//if player exists
if (instance_exists(obj_soco)){
    dist = point_distance(x,y,obj_soco.x,obj_soco.y);
    //if in aggro range
    if (dist < sight){
        aggro = true;
        state = scr_e_chase;
        show_debug_message(string("dist < sight, aggro"));
        var dir = point_direction(x,y,obj_soco.x, obj_soco.y);
           
        xaxis = lengthdir_x(1, dir);
        yaxis = lengthdir_y(1, dir);
    //if out of aggro range
    }else if (dist >= sight){
        //if aggro'd
        if (aggro == true){
            show_debug_message(string("dist >= sight, aggro"));
            alarm[2] = room_speed * 3;
            //state = scr_e_chase;
        }else{ //if not aggro'd
            show_debug_message(string("dist >= sight, no aggro"))
            scr_e_choose_next_state();
        }
    }
//if player does not exist
}else{
    scr_e_choose_next_state();   
}
Then the alarm event which should just go off, un-aggro the enemy and make him choose his next state.
Code:
///Aggro alarm

aggro = false;
scr_e_choose_next_state(); //wander or idle
From what I've gathered, the alarm is being set, but isn't counting down. So that code never executes. Why isn't it working!?!?!?!?!?!?!?! I am slightly frustrated lol.
 

jazzzar

Member
because i believe all this code is in an event step, which happens every second, so the alarm is being always set to room_speed*3 , you can avoid this by having a varriable called alarm_trigger being true at the beginning now when you check if (aggro==true) make it like this if (aggro==true && alarm_trigger==true) {//your code+ alarm_trigger=false}
then in the alarm event put alarm_trigger=true;
 
D

Daquaris Chadwick

Guest
Hello,

So, your problem is that your aggro keeps returning true after your alarm is set. Basically it keeps getting reset to room_speed * 3. I would recommend you create a boolean variable that turns on when the alarm is set, and turns off when the alarm ends.

Player Searching Code
Code:
//if out of aggro range
    }else if (dist >= sight){
        //if aggro'd
        if (aggro == true && !alarm_on){
            show_debug_message(string("dist >= sight, aggro"));
            alarm_on = true;
            alarm[2] = room_speed * 3;
            //state = scr_e_chase;
        }else{ //if not aggro'd
            show_debug_message(string("dist >= sight, no aggro"))
            scr_e_choose_next_state();
        }
    }
Alarm
Code:
///Aggro alarm

aggro = false;
alarm_on = false;
scr_e_choose_next_state(); //wander or idle
 

jazzzar

Member
Hello,

So, your problem is that your aggro keeps returning true after your alarm is set. Basically it keeps getting reset to room_speed * 3. I would recommend you create a boolean variable that turns on when the alarm is set, and turns off when the alarm ends.

Player Searching Code
Code:
//if out of aggro range
    }else if (dist >= sight){
        //if aggro'd
        if (aggro == true && !alarm_on){
            show_debug_message(string("dist >= sight, aggro"));
            alarm_on = true;
            alarm[2] = room_speed * 3;
            //state = scr_e_chase;
        }else{ //if not aggro'd
            show_debug_message(string("dist >= sight, no aggro"))
            scr_e_choose_next_state();
        }
    }
Alarm
Code:
///Aggro alarm

aggro = false;
alarm_on = false;
scr_e_choose_next_state(); //wander or idle
exactly what i said but better organized :p
 
Top