@QueenTeaYT That's more or less the way to go. In case you are wondering why that happens: both player touch and event touch trigger whenever an action that would make the player and the event have the same coordinates is queued (respectively a player action or an event action), even if it cannot be executed because they collide. In this case, while the event chases the player, if the player stands on a tile and the event tries to step on the same tile, the event is triggered.
Executing the event commands, however, only takes a single frame, but in the next frame (it does not actually happen each frame, but it is still very fast), when the event tries to chase the player once again, the same thing happens. This loop only stops when the player coordinates change and the event can move.
To be completely honest, using "Wait" might still lead to nasty issues if not timed properly (the damage might be dealt twice: once when hitting the player, once again as soon as the player moves another step after the wait command ends). The way to time it properly to avoid the aforementioned issue is this:
Code:
pick_a_var = var_id_here # E.g. 12, do not use it in your game for anything else
pick_a_switch = switch_id_here # Read below
cd = set_a_cooldown_for_damage_here # E.g. 30
unless $game_variables[pick_a_var].is_a?(Array)
$game_variables[pick_a_var] = [-1, -1, 0]
end # You can write this in a single line, but it might be too long.
same_x = ($game_variables[pick_a_var][0] == $game_player.x)
same_y = ($game_variables[pick_a_var][1] == $game_player.y)
change_xy = !(same_x && same_y)
cd_expired = ($game_variables[pick_a_var][2] == cd)
if (change_xy || cd_expired)
$game_variables[pick_a_var] = [$game_player.x, $game_player.y, 0]
$game_switches[pick_a_switch] = true
# Alternatively -> $game_self_switches[[$game_map.map_id, @event_id, pick_a_switch]] = true
# If you are using a self switch, pick_a_switch can be 'A', 'B', 'C' or 'D',
# it doesn't make any difference, as long as you use quotation marks.
else
$game_variables[pick_a_var][2] += 1
end
In your event you can then check for the said switch, if it is true, you deal damage, if it is false, you do nothing.
This logic basically checks if you have already dealt damage to the player in that position and prevents your event from dealing damage once again until the player moves or until too many attempts to hurt the player fail (otherwise the player could just stay still in the same place forever and become invulnerable). The amount of failed attempts is up to you, it depends on how many times you want the player to be able to avoid damage while standing, I recommend using a high enough number like 30 or 60. Anyway, if the player moves, the event can deal damage once again.
All this goes in a script call. It basically works in the same way as the Wait command that Shaz suggested, but prevents the nasty interaction that I mentioned above.
EDIT
You could even deal damage within the script call itself, without having to use a switch, but I think that this option should be good enough for you, and it also allows you to control damage easily without having to edit the script call later on.
EDIT 2
@Shaz the reason why I would refrain from using a wait command here is that, if not timed properly, it would also prevent the player from moving smoothly (this is not a parallel process after all).
Spoiler: Situation Analysis
According to the amount of frames left for the player sprite to complete its movement, the event can wait less than that amount, the same as that amount or more than that amount.
- Less
The event deals damage, the player is still moving (thus on the same square) and the event triggers once again. This repeats until the movement is completed. After that you have two different situations:
- The player can queue a new action (which means that the wait command expired)
When this is the case, the event still runs once more together with the first frame of the player movement, then the wait command starts counting, but it is irrelevant since the player is already moving.
- The player cannot queue a new action (which means that the wait command is still waiting)
If this happens the player can only queue a new action once the wait command stops counting, which leads to the previous point.
- Same
The event deals damage, the player ends the movement, and can queue a new action immediately. This, however, is the same as the first point of the previous case, so it is still somewhat incorrect.
- More
The event deals damage, the player ends the movement, but no new action can be queued because the wait command is still ongoing. This is the same as the second point of the first case, which means that the player will have to wait before being able to move.