• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How do I make my enemies talk when switching states?

S

SnicketyLemon

Guest
Hey guys, just a heads up: I am new at gamemaker code and this is my first time posting on GMC.

So: im having troubles with getting the enemy characters to say their lines when they switch states from unaware to alert. When they switch to alert state he is supposed to say "enemy sighted!" but I cannot figure out how to word or where to place the code.
Here is where I placed the code:
Code:
///Are we alert?
if(my_target!=noone)
{
    found_him=true;
}
if(my_target!=noone)
{
    found_him_timer=0;
}
if(found_him)
{
    alert_status=true;
}
if(alert_status&&my_target==noone)
{
    found_him_timer++;
}
if(alert_status&&found_him_timer>=200)
{
    alert_status=false;
    found_him_timer=0;
    found_him=false
}

//Follow if we see the player
if(alert_status)
{
    patrol=false;
    follow=true;
}

//If alert status is cleared, switch to patrol.
if(!alert_status)
{
    follow=false;
    lb=grid*15;
    rb=grid*15;
    patrol=true;
}
Heres the code I attempted to use:
Code:
//play spot sound
if(found_him&&!alert_status)
{
    audio_emitter_pitch(audio_spot_em,1);   
    audio_play_sound_on(audio_spot_em,sound_spot,0,6);
}
I tried moving it all around the code, starting with the bottom, but to no avail :/
Im not sure if the code is even correct, so if anyone has any suggestions, I welcome them!
 

Gamerev147

Member
I see your issue. I don't know if this code will help, but try this:
Code:
///Just play the sound
if (found_him && !alert_status)  {

          audio_play_sound(audio_spot_em, 1, 0);

}
If that doesn't work then I can continue to help if you want. I can do some research... Best of luck! :)
 
S

SnicketyLemon

Guest
No dice. :/ It would appear that the compiler just ignore's the line of code completely, or creates an annoying error sound. Though all is still not lost, there's another piece of code next to "are we alert" named "face sprite and view, and locate our enemies" the code looks like this
Code:
///Face sprite and view, and locate our enemies
//Our target
//Clear priority every step
ds_priority_clear(ally_list);
//If we see the enemy
//allies to player
var i;
for(i=0;i<instance_number(obj_ally_prisoner_camp);i++)
{
    global.ally_prisoner[i]=instance_find(obj_ally_prisoner_camp,i);
    if(!collision_line(x,y-height,global.ally_prisoner[i].x,global.ally_prisoner[i].y,obj_block,false,true))
    {
        if(!global.ally_prisoner[i].in_cell)
        {
            //Add enemy id to the list and prioritize by distance
            ds_priority_add(ally_list,global.ally_prisoner[i].id,point_distance(x,y-height,global.ally_prisoner[i].x,global.ally_prisoner[i].y));
        }
    }
}
//Check player priority to see if the player is visible
var view_distance=1000;
if(see_him&&distance_to_object(obj_player)<=view_distance)
{
    my_target=obj_player.id;
}
else
{
    //Check ally priority to see if its empty
    if(ds_priority_empty(ally_list))
    {
        //Make targe noone if no enemies found
        my_target=noone;
    }
    else
    {
        //Find id of enemy at top of list and make them the target
        my_target=ds_priority_find_min(ally_list);
    }
}
//left
if(ene_dir<0)
{
    if(my_class==machine_gun)
    {
        right_aim=20;
        left_aim=700;
        up_aim=260;
        down_aim=30;
    }
    else if(my_class==medic)
    {
        right_aim=20;
        left_aim=600;
        up_aim=260;
        down_aim=30;
        right_heal_aim=20;
        left_heal_aim=150;
    }
    else if(my_class==flame_thrower)
    {
        right_aim=500;
        left_aim=500;
        up_aim=330;
        down_aim=30;
    }
}
//right
else if(ene_dir>0)
{
    if(my_class==machine_gun)
    {
        right_aim=700;
        left_aim=20;
        up_aim=260;
        down_aim=30;
    }
    else if(my_class==medic)
    {
        right_aim=600;
        left_aim=20;
        up_aim=260;
        down_aim=30;
        left_heal_aim=20;
        right_heal_aim=150;
    }
    else if(my_class==flame_thrower)
    {
        right_aim=500;
        left_aim=500;
        up_aim=330;
        down_aim=30;
    }
}
//Is the player blocked from sight?
if(xray_vision)
{
    scr_enemy_face_ghost_platforms();
}
else
{
    scr_enemy_face();
}
I'll scour that to see if I cant figure something out, though if you come up with anything just keep me posted!
 

SnoutUp

Member
You could just add shouldPlayAlertSound = true; wherever that's needed and when play that sound if shouldPlayAlertSound is true, then set shouldPlayAlertSound to false again, so it wouldn't repeat the SFX over and over again.
Now if you messed up your state code (I didn't look at it) badly, you might want to add alertSoundAlreadyPlayed variable (if you only need that sound once), just in case glitches happen and enemy is getting switched to the alert many times.

Also, try "Programming" forum next time and go easy on bumping, this is not an emergency issue, you can figure this out on your own ;)
 
S

SnicketyLemon

Guest
Thanks a ton snout, ill give it a go. Sorry about the forum issue, I did not know about the programming forum and was thinking tech support was where I needed to go.
Just new to this coding and forum thing.
 
P

ParodyKnaveBob

Guest
Dear newcomer,

I hope my observation does not sound ripe with overtones of cruel villainy, villainous cruelty, nor toned overripeness, but I feel obligated to point out that your namesake would surely be aghast at your not reading -- a word which here means "examining any given subforum's stickied thread(s) to learn the purpose and rules before posting in said subforum."

With all due respect,
ParodyKnaveBob

$:^ D
 
Top