1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Need help with an alarm for enemy AI.

Discussion in 'Programming' started by pixeltroid, Mar 5, 2019.

  1. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    603
    Ive made an enemy that, if he gets too close to the player, uses an alternate attack (obj_thunderbolt).

    His condition to launch close attack is set to "false" (cancloseattack = "false"). It gets set to true only once he gets close enough to the player.

    The close attack works, but it happens continuously. I want it so that when he uses the close quarters attack, there should be an interval of a few seconds -- as defined by the alarm 4

    Code:
    if (place_meeting(x-2,y,obj_player)) {
    cancloseattack = true{ 
    if (image_xscale > 0) { 
    close = instance_create(x+16, y-8, obj_thunderbolt2);
    close.direction = 180
    close.image_angle = close.direction
    close.speed = 0;
    sprite_index = spr_zs2_shoot2
    }
    else if (image_xscale < 0) { 
    close = instance_create(x-16, y-8, obj_thunderbolt2);
    cancloseattack = false
    close.direction = 0
    close.image_angle = close.direction
    close.speed = 0;
    sprite_index = spr_zs2_shoot2
    }
    cancloseattack = false
    }
    alarm[4] = 50 
    }
    
    What am I doing wrong??? How do Imake it so that he cannot use the attack until alarm 4 is reset?
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,642
    You need to check if the alarm isn't already greater than 0.

    And 50 isn't a few seconds.
     
  3. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    603
    I know... I meant to say a short interval.

    ah ok.
    I changed the first line to

    Code:
    if (distance_to_point(obj_player.x,y) <= 4) && !alarm[4] > 0 
    And now it seems to be working! :)

    Thanks!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice