Alarm Triggered by Movement Speed

S

snskinner29

Guest
Ok, I'm trying to set up an event for an NPC so that when its speed reaches zero, it triggers an alarm that counts down and ends the game when it reaches 0 but resets when the NPC begins moving again.
Basically, the player has to keep the NPC moving or the game ends. I've got it working to where the NPC moves in response to the player, declerates nicely to a stop, and changes the sprite to the placeholder doom sprite. When the player approaches, the NPC starts moving again and switches back to its normal sprite.
My trouble is with the alarm. It either wont fire or wont reset. I'm fairly new to coding so I'm not sure what's going on. Here's my code:

//Make Sol move away from player
if distance_to_object(Player1_1) <= 256
{
hspeed = (move_away + accel);
if (move_away <= max_speed);
else
move_away = max_speed;
direction = 0;
}
else

//Friction code for deceleration
if abs(speed) > 0
{
friction = 0.01;
sprite_index = spr_Sol_fade
}
else
{
friction = 0;
sprite_index = spr_Sol
}

//Event Trigger for Ragnarok Countdown
if abs(speed) = 0
{
sprite_index = spr_Sol_b;
alarm[1] = 300;

}
else
{
sprite_index = spr_Sol;
alarm[1] = -1;
}

What I want is so that when the NPC stops, the alarm begins counting down, giving the player time to catch up before the alarm finishes and ends the game, and to have the alarm reset each time the NPC starts moving again.
 
I

InkSho

Guest
a different method iv kinda used before for other things is if your hspeed is 0, make it count a variable 1 frame at a time and if the variable hits a certain number then itll end the game, otherwise make the keys to move reset the variable back to 0
 
Top