mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add entity events: on_attacked, on_used
This commit is contained in:
parent
a36ffaacd9
commit
50050dbe40
6 changed files with 44 additions and 0 deletions
|
|
@ -348,6 +348,8 @@ void scripting::on_entity_spawn(
|
|||
funcsset.on_save = lua::hasfield(L, "on_save");
|
||||
funcsset.on_aim_on = lua::hasfield(L, "on_aim_on");
|
||||
funcsset.on_aim_off = lua::hasfield(L, "on_aim_off");
|
||||
funcsset.on_attacked = lua::hasfield(L, "on_attacked");
|
||||
funcsset.on_used = lua::hasfield(L, "on_used");
|
||||
lua::pop(L, 2);
|
||||
|
||||
component->env = compenv;
|
||||
|
|
@ -439,6 +441,22 @@ void scripting::on_aim_off(const Entity& entity, Player* player) {
|
|||
});
|
||||
}
|
||||
|
||||
void scripting::on_attacked(const Entity& entity, Player* player, entityid_t attacker) {
|
||||
process_entity_callback(entity, "on_attacked",
|
||||
&entity_funcs_set::on_attacked, [player, attacker](auto L) {
|
||||
lua::pushinteger(L, attacker);
|
||||
lua::pushinteger(L, player->getId());
|
||||
return 2;
|
||||
});
|
||||
}
|
||||
|
||||
void scripting::on_entity_used(const Entity& entity, Player* player) {
|
||||
process_entity_callback(entity, "on_used",
|
||||
&entity_funcs_set::on_used, [player](auto L) {
|
||||
return lua::pushinteger(L, player->getId());
|
||||
});
|
||||
}
|
||||
|
||||
void scripting::on_entities_update() {
|
||||
auto L = lua::get_main_thread();
|
||||
lua::get_from(L, STDCOMP, "update", true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue