Wiki

Clone wiki

NuclearThroneTogether / Scripting / Objects / CustomHitme

CustomHitme is a special object intended for creating custom allies, enemies, or anything else that conventionally can be hit by projectiles.

Variables

Script references for callback variables (on_*) can be obtained via script_ref_create.

on_begin_step

Called by the game in Begin Step event.

on_step

Called by the game in Step event.

on_end_step

Called by the game in End Step event.

on_draw

Called by the game in Draw event.

If you don't set this, the instance will draw as per usual.

on_hurt

Is called with arguments (damage, knockback_velocity, knockback_direction) when the instance should be taking damage.

on_destroy

Called by the game when instance is destroyed.

spr_shadow

Can be set to a sprite index to use as shadow. Is spr_shd16 by default.

team

Numeric: objects do not get hit by projectiles of the same team.

size

Numeric: affects a few collision-related behaviours. See explanation on Player variables page.

Examples

mines.mod.gml

trace("Press B to deploy mines.");
#define step
with (Player) if (button_pressed(index, "horn")) {
    with (instance_create(mouse_x[index], mouse_y[index], CustomHitme)) {
        team = other.team;
        sprite_index = sprGoldDisc;
        on_step = script_ref_create(test_step);
        on_hurt = script_ref_create(test_hurt);
        my_health = 8;
        friction = 0.5;
    }
}
#define test_step
image_angle += 15;
#define test_hurt(damage, kb_vel, kb_dir)
my_health -= damage;
if (my_health <= 0) {
    repeat (3) instance_create(x + random_range(-1, 1), y + random_range(-1, 1), Explosion);
    instance_destroy();
} // else motion_add(kb_dir, kb_vel)

Updated