add entity events: on_attacked, on_used

This commit is contained in:
MihailRis
2024-07-16 14:04:05 +03:00
parent a36ffaacd9
commit 50050dbe40
6 changed files with 44 additions and 0 deletions
+18
View File
@@ -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);