M
Mikael.K
Guest
The script my weapon "hit box" execute when colliding with an enemy looks like this.
The script makes a ds_list of all the possible "victims" that it collides with, and reduce the hp of those instances with the damage variable.
The problem I'm having is that the hp is reduced by damage for all the frames that the hit box is colliding with the victim. I want the hit to be just once per attack.
I want to avoid having a variable in the potential victims, like been_hit, and set that to true when colliding with an object that does damage, and reset to false when the object that damaged the instance is destroyed.
The problem with this is that the struck victim is invincible for as long as the object that damaged the instance exists.
Any ideas on how to add code to the script so that the hit box knows which instances has been damaged already?
GML:
/// @param victim
/// @param xpush
/// @param ypush
/// @param damage
var collision_list = ds_list_create();
var number = instance_place_list(x, y, argument0, collision_list, false);
if number > 0
{
for (var entry = 0; entry < number; entry += 1;)
{
if collision_list[| entry] != owner // owner is the instance that created the hit box. As not to damage self.
{
with(collision_list[| entry])
{
// do damage
hp -= argument3;
// push object
if can_be_pushed
{
scr_push(argument1,argument2);
}
}
}
}
}
ds_list_destroy(collision_list);
The problem I'm having is that the hp is reduced by damage for all the frames that the hit box is colliding with the victim. I want the hit to be just once per attack.
I want to avoid having a variable in the potential victims, like been_hit, and set that to true when colliding with an object that does damage, and reset to false when the object that damaged the instance is destroyed.
The problem with this is that the struck victim is invincible for as long as the object that damaged the instance exists.
Any ideas on how to add code to the script so that the hit box knows which instances has been damaged already?