Legacy GM how to make hitboxes keep repeating at 1 frame.

S

sravitheja01

Guest
upload_2017-2-18_17-0-7.png

here's my code, when i tested it, the hitbox does form at 1st frame and gets destroyed due to an alarm state i placed in the obj_damage, however how can i make hitbox keep repeating at 1st frame. i know hitbox isnt forming due to the instance_destroy event earlier..but please someone help me with this as i am less of ideas. thank you.
 
Z

zendraw

Guest
im not sure what exactly are you trying to do? maybe explain a bit.
 
S

sravitheja01

Guest
for example.. my enemy does a instance_create obj_hitbox (i think i wrote it as obj_damage) at frame 2 of his animation and i have a placed an alarm event where the hitbox gets destroyed at 1 sec... but after finishing his animation, hit box is not formed in the frame 2 again until i leave the " attack_sight" i placed (thing is "he keeps on animating until i leave the attack_sight") but i want hitbox to keep hitting the frame 2 as long as he keeps animating without relying on attack_sight.
 
Z

zendraw

Guest
well in the switch statement you ask if enemy is up,left,right,down and when it is true you change the sprite index to an attacking animation, so the checks will no longer be true until you switch your sprite to the up,right,down,left ones.
basically you need to change to an attacking sprite and while that sprite is running check if the image index is right and create the damage.
 
S

sravitheja01

Guest
so u mean..now that when i checked if "spr_down" is true i change it to" spr_attack_down" and then i have to swtich them back to "spr_down" to get hit_box again?
pardon me if i am wrong but i have code it like this?

case spr_enemy_right : sprite_index = spr_enemy_attack_right
if (image_index >=0 || image<= 1)
{
instance_create(x,y, obj_hitbox)
if (image_index = 6) (last frame)
{
sprite_index = spr_enemy_right;
attack = 0
break; ??? i am still new to this..but this is wat u meant? thank you
 
S

sravitheja01

Guest
well in the switch statement you ask if enemy is up,left,right,down and when it is true you change the sprite index to an attacking animation, so the checks will no longer be true until you switch your sprite to the up,right,down,left ones.
basically you need to change to an attacking sprite and while that sprite is running check if the image index is right and create the damage.
so u mean..now that when i checked if "spr_down" is true i change it to" spr_attack_down" and then i have to swtich them back to "spr_down" to get hit_box again?
pardon me if i am wrong but i have code it like this?

case spr_enemy_right : sprite_index = spr_enemy_attack_right
if (image_index >=0 || image<= 1)
{
instance_create(x,y, obj_hitbox)
if (image_index = 6) (last frame)
{
sprite_index = spr_enemy_right;
attack = 0
break; ??? i am still new to this..is this wat u meant? thank you
 
Z

zendraw

Guest
try this
Code:
case spr_enemy_right :
case spr_enemy_attack_right:
sprite_index = spr_enemy_attack_right
if (image_index >=0 || image<= 1)
{
instance_create(x,y, obj_hitbox)
}
attack = 0
break;
basically you ask if the sprite index is spr_enemy_right or spr_enemy_attack_right and if either is true you set the sprite index to spr_enemy_attack_right and create the hitbox object. there is ofcorse a more efficient way to do this but i dont want to mess with your coding process.

also about the switch statement
when you add break after a couple of cases, its like you ask if either of those cases is true
so
switch (move)
{
case 1:
case 2:
case 3:
//do somthing
break;
}

is the same as
if (move==1 or move==2 or move==3) {do somthing};
 
S

sravitheja01

Guest
attack state is really making
try this
Code:
case spr_enemy_right :
case spr_enemy_attack_right:
sprite_index = spr_enemy_attack_right
if (image_index >=0 || image<= 1)
{
instance_create(x,y, obj_hitbox)
}
attack = 0
break;
basically you ask if the sprite index is spr_enemy_right or spr_enemy_attack_right and if either is true you set the sprite index to spr_enemy_attack_right and create the hitbox object. there is ofcorse a more efficient way to do this but i dont want to mess with your coding process.

also about the switch statement
when you add break after a couple of cases, its like you ask if either of those cases is true
so
switch (move)
{
case 1:
case 2:
case 3:
//do somthing
break;
}

is the same as
if (move==1 or move==2 or move==3) {do somthing};
please with all due respect if there is another method which does work and more logical please do tell me, i know my code isnt the best. and if u have a better code do share with me as i am banging my head since 5 days with this code and finishing this will eventually finish up my boss attack script.. thank you
 
Z

zendraw

Guest
try this

Code:
var dis=distance_to_point(x, y, obj_player.x, obj_player.y);

if (dis<=attack_range)
{
    var xx=0;
    var yy=0;
    switch (sprite_index)
    {
            case spr_enemy_right: sprite_index=spr_enemy_attack2; attack=1; break;
            case spr_enemy_left: sprite_index=spr_enemy_attack4; attack=1; break;
            case spr_enemy_up: sprite_index=spr_enemy_attack1; attack=1; break;
            case spr_enemy_down: sprite_index=spr_enemy_attack3; attack=1; break;
        
            case spr_enemy_attack2: xx=14; break;
            case spr_enemy_attack4: xx=-14; break;
            case spr_enemy_attack1: yy=-14; break;
            case spr_enemy_attack3: yy=14; break;
    }
    
    if (attack==1)
    {
        if (image_index>=0 && image_index<=1)
        {
            instance_create(x+xx, y+yy, obj_damage);
        }
    }
} else
{
    if (image_index>5.5)
    {
        switch (sprite_index)
        {
                case spr_enemy_attack2: sprite_index=spr_enemy_right; break;
                case spr_enemy_attack4: sprite_index=spr_enemy_left; break;
                case spr_enemy_attack1: sprite_index=spr_enemy_up; break;
                case spr_enemy_attack3: sprite_index=spr_enemy_down; break;
        }
    }
}
 
S

sravitheja01

Guest
try this

Code:
var dis=distance_to_point(x, y, obj_player.x, obj_player.y);

if (dis<=attack_range)
{
    var xx=0;
    var yy=0;
    switch (sprite_index)
    {
            case spr_enemy_right: sprite_index=spr_enemy_attack2; attack=1; break;
            case spr_enemy_left: sprite_index=spr_enemy_attack4; attack=1; break;
            case spr_enemy_up: sprite_index=spr_enemy_attack1; attack=1; break;
            case spr_enemy_down: sprite_index=spr_enemy_attack3; attack=1; break;
       
            case spr_enemy_attack2: xx=14; break;
            case spr_enemy_attack4: xx=-14; break;
            case spr_enemy_attack1: yy=-14; break;
            case spr_enemy_attack3: yy=14; break;
    }
   
    if (attack==1)
    {
        if (image_index>=0 && image_index<=1)
        {
            instance_create(x+xx, y+yy, obj_damage);
        }
    }
} else
{
    if (image_index>5.5)
    {
        switch (sprite_index)
        {
                case spr_enemy_attack2: sprite_index=spr_enemy_right; break;
                case spr_enemy_attack4: sprite_index=spr_enemy_left; break;
                case spr_enemy_attack1: sprite_index=spr_enemy_up; break;
                case spr_enemy_attack3: sprite_index=spr_enemy_down; break;
        }
    }
}
ill try and let u know :)
 
S

sravitheja01

Guest
okay but copy/paste the code, rewriting it is a torture.
i tried still the same, and at this point i am feeling my attack_system is flawed, perhaps some advice?, i really want to make meelee boss which relies on player position but at the same thing should complete its animation even when player moves
 
Z

zendraw

Guest
well i cant give you an advice without your code. what i can advice you is to write down on a glass the basics of how the boss behaves and first make one thing but finish it, then proceed to the next thing.
for instance the plan may be,
-boss moves to player
-boss attacks

so first work on the 'boss moves to player' until you finish with this part of the boss`s behavior
then proceed with boss attacks
so when hes near enough if [in normal state] ->[attack] ...end of animation[return to normal state]
and this will create an endless loop pursue->normal->attacking->normal
overall be clear what part of your code does what.
you can do this easily with scripts and switch scripts

in the boss step event put
script_execute(state)//state is the var that holds the current state

-in pursue state scrpt
if (dis<range) {state=attack; sprite index =attack sprite; image speed=w/e...}//set here the things
//pursue code below

-in attack state scrpt
if (image index>=0 && image index<=1) {create damage}
if (image index>=5.5) {state=normal; sprite index=normal; etc..}

-in normal state scrpt
if (dis<range) {state=attack; sprite index =attack sprite; image speed=w/e...}
else {state=pursue; sprite index=pursue sprite imagespeed=w/e...}

this is the logic and the simplest way to do it.
if you have only 2 states pursue and attack then just switch betwean them.
 
S

sravitheja01

Guest
thank you for taking ur time, u can see my code right above , i have posted both the chase and attack state, but here's a gif to provide how my states execute, here 1, 2,3,4 are attack_sprite_direction on the enemy pink sprite, the only problem i have is after final frame ends i want boss to make it wait for a particalar 5secs and reset back to chase state. ( i have used alarms but i am not really good them so they didnt work)
check my gif for better clarity
https://gyazo.com/e08f74a1ee87ac2c75bb9da476bafe76 in the gif u can boss instantly follows up player when he enters its chase_radius. this is the only obstacle i am facing.
 
S

sravitheja01

Guest
well i cant give you an advice without your code. what i can advice you is to write down on a glass the basics of how the boss behaves and first make one thing but finish it, then proceed to the next thing.
for instance the plan may be,
-boss moves to player
-boss attacks

so first work on the 'boss moves to player' until you finish with this part of the boss`s behavior
then proceed with boss attacks
so when hes near enough if [in normal state] ->[attack] ...end of animation[return to normal state]
and this will create an endless loop pursue->normal->attacking->normal
overall be clear what part of your code does what.
you can do this easily with scripts and switch scripts

in the boss step event put
script_execute(state)//state is the var that holds the current state

-in pursue state scrpt
if (dis<range) {state=attack; sprite index =attack sprite; image speed=w/e...}//set here the things
//pursue code below

-in attack state scrpt
if (image index>=0 && image index<=1) {create damage}
if (image index>=5.5) {state=normal; sprite index=normal; etc..}

-in normal state scrpt
if (dis<range) {state=attack; sprite index =attack sprite; image speed=w/e...}
else {state=pursue; sprite index=pursue sprite imagespeed=w/e...}

this is the logic and the simplest way to do it.
if you have only 2 states pursue and attack then just switch betwean them.
thank you for taking ur time, u can see my code right above , i have posted both the chase and attack state, but here's a gif to provide how my states execute, here 1, 2,3,4 are attack_sprite_direction of the enemy pink sprite, the only problem i have is after final frame ends i want boss to make it wait for a particalar 5secs and reset back to chase state. ( i have used alarms but i am not really good them so they didnt work)
check my gif for better clarity
https://gyazo.com/e08f74a1ee87ac2c75bb9da476bafe76 in the gif u can see boss instantly follows up player when he enters its chase_radius. this is the only obstacle i am facing. i understood regarding what to do with hitboxes.. but this is also yet another problem of mine.
 
Z

zendraw

Guest
well when the boss finishes attacking set him to spr_enemy_exhausted and an alarm like this
alarm[0]=5*room_speed
5 is the seconds you want
room_speed is how meny frames does the game perform each second
so if its 30f per second it will be 5*30=150;

in the alarm simply reset the sprites to the spr_enemy_right/left etc

and when when you check if enemy can attack simply add another check && sprite_index!=spr_enemy_exhausted

overall after the enemy attacks he will get exhausted and after 5 sec when he regains his strength he will return to normal state and will be able to pursue and attack

also the alarms are basically an event that is run only once when the clock reaches 0
the alarms alre like a timer like you have 4 seconds before w/e happens, like those timers where if you dont escape the building in 1 min you die.
so to run an alarm event you simply set how much time before the event is run.
 
S

sravitheja01

Guest
well when the boss finishes attacking set him to spr_enemy_exhausted and an alarm like this
alarm[0]=5*room_speed
5 is the seconds you want
room_speed is how meny frames does the game perform each second
so if its 30f per second it will be 5*30=150;

in the alarm simply reset the sprites to the spr_enemy_right/left etc

and when when you check if enemy can attack simply add another check && sprite_index!=spr_enemy_exhausted

overall after the enemy attacks he will get exhausted and after 5 sec when he regains his strength he will return to normal state and will be able to pursue and attack

also the alarms are basically an event that is run only once when the clock reaches 0
the alarms alre like a timer like you have 4 seconds before w/e happens, like those timers where if you dont escape the building in 1 min you die.
so to run an alarm event you simply set how much time before the event is run.
yes i have followed ur method and alarm is working but the only thing is even if it goes to exhaust state, when i go in the range of chase state it again goes back to chasing sprite. but the exhaust sprite if player doesnt move changes back to attack sprite after 5 sec. but if moved its the same thing again. check this gif
https://gyazo.com/b1b2040503e99272dd639aef916d1b0f

and here's my code
upload_2017-2-19_18-51-12.png
upload_2017-2-19_18-51-40.png
and the alarm
upload_2017-2-19_18-52-44.png
i am feeling we are really getting near to what were trying out. :D
 
Z

zendraw

Guest
well your resetting the sprite to a left/right/up/down one somewhere in your code. make sure you change the sprite to left/right/up/down only in the alarm event.
in your scr_chase_state add && sprite_index!=spr_enemy_exhaust in the if statement (dis<sight && dis<atk_range)
 
S

sravitheja01

Guest
well your resetting the sprite to a left/right/up/down one somewhere in your code. make sure you change the sprite to left/right/up/down only in the alarm event.
in your scr_chase_state add && sprite_index!=spr_enemy_exhaust in the if statement (dis<sight && dis<atk_range)
yes when in attack range i can still roam around enemy and he will attack me only when 5 secs complete until then he will be in stall state...just when i cross the attack range and enter chase sight range..he will instantly follow me. i tried dis < sight && dis < atk_range it messed it, since dis < atk_range is set to attack_script in my code. we just need to also have repititon of the alarm in chase state.
 

Attachments

S

sravitheja01

Guest
the procedure goes like this

if ( dis < sight_range ) - > chase state
if ( dis < sight_range) && (dis > attack_range) - > // direction code //
if ( dis < attack_range) -> attack state
if( dis > attack_range ) -> chase state // this is where enemies doesnt give đź’©đź’©đź’©đź’© to our alarm. lol //
if (dis > sight_range ) -> idle state ...
 
Z

zendraw

Guest
noo remove this part

if (dis<=sightrange && dis<attackrange)
{
sprite=spr_exhaust;
}

i meant to add this -> && sprite_index!=spr_exhaust

to this ->if (dis<=sightrange && dis<attackrange)

so in the end it shuld be like this ->if (dis<=sightrange && dis<attackrange && sprite_index!=spr_exhaust)

try this and tell if it works.
 
S

sravitheja01

Guest
upload_2017-2-19_21-48-19.png
yes i tried that, it does set alarm in alarm in attack_range but not in sight_range, making it instantly follow up the player. :/
 
Z

zendraw

Guest
now put it in the if statement right above /*CHASE STATE*/ and it shuld like the one in your last picture

-> if (dis<=sight_range && dis<attack_range && sprite_index!=spr_exhaust) <-

you have to make sure nothing is run when in exhausted state. :)
 
S

sravitheja01

Guest
now put it in the if statement right above /*CHASE STATE*/ and it shuld like the one in your last picture

-> if (dis<=sight_range && dis<attack_range && sprite_index!=spr_exhaust) <-

you have to make sure nothing is run when in exhausted state. :)
wait but never created an exhaust state right? ..we just made a sprite.
 
Z

zendraw

Guest
can you post all the code involving the boss? im kinda shootin in the dark here.
but as text, pls. also put some brackets on those if statements
if (bla bla) {do this};
the code may behave differently without brackets.
 
S

sravitheja01

Guest
S

sravitheja01

Guest
i will surely be in ur debt..if you could find out where there is an error, this Boss AI is the only reason i am pushing , i could just make a basic one with my basic knowledge..but i learnt alot doing this AI script. it is challenging & subpar my skills, but thanks for helping me out since 2 days. your efforts havent been wasted since i learnt a lot of logical states in the scripts. :D
 
A

anthropus

Guest
here's my code, when i tested it, the hitbox does form at 1st frame and gets destroyed due to an alarm state i placed in the obj_damage, however how can i make hitbox keep repeating at 1st frame. i know hitbox isnt forming due to the instance_destroy event earlier..but please someone help me with this as i am less of ideas. thank you.
hi, im a total noob but it sounds like the alarm or something about it is part of the problem. in this video master GML programmer shaun spalding uses a post draw event with a instance_destroy() to destroy the damage hitbox, not an alarm. maybe try that instead of an alarm? idk, its a shot in the dark, so i thought maybe this might help. good luck!
 
Z

zendraw

Guest
anthropus thats not the problem here and the alarm is to switch states, not for the damage.

sravi, ive edited and comment the project, now it works as i think it shuld.
the enemy chases you and attacks if in range, then gets exhausted and after some time repeats the process.

where can i upload it thou?
 
S

sravitheja01

Guest
anthropus thats not the problem here and the alarm is to switch states, not for the damage.

sravi, ive edited and comment the project, now it works as i think it shuld.
the enemy chases you and attacks if in range, then gets exhausted and after some time repeats the process.

where can i upload it thou?
wow...thank you soo much.
send it my mail id i guess.. its [email protected]
 
S

sravitheja01

Guest
ok so ive send you the file, its called Desktop.rar
yes!!!!!! boi!!!!!!!! thank you so much its works exactly the way its meant to.. and please can u provide me "steam id" so i can make conversation without these hassles. u can send it to my email if u want privacy.
 
Top