diff --git a/src/client/component/scripting.cpp b/src/client/component/scripting.cpp index 5418a772..f47559e9 100644 --- a/src/client/component/scripting.cpp +++ b/src/client/component/scripting.cpp @@ -66,6 +66,8 @@ namespace scripting e.arguments.emplace_back(*value); } + lua::engine::handle_endon_conditions(e); + scheduled_notifies.access([&](notify_list& list) { list.push_back(e); @@ -75,7 +77,7 @@ namespace scripting vm_notify_hook.invoke(notify_list_owner_id, string_value, top); } - void clear_scheduler_notifies() + void clear_scheduled_notifies() { scheduled_notifies.access([](notify_list& list) { @@ -87,7 +89,7 @@ namespace scripting { client_spawn_hook.invoke(client); scr_auto_respawn->current.enabled = true; - clear_scheduler_notifies(); + clear_scheduled_notifies(); lua::engine::start(); } @@ -98,7 +100,7 @@ namespace scripting canonical_string_table.clear(); } - clear_scheduler_notifies(); + clear_scheduled_notifies(); lua::engine::stop(); g_shutdown_game_hook.invoke(free_scripts); } @@ -177,7 +179,7 @@ namespace scripting if (save_game != nullptr) { scr_auto_respawn->current.enabled = true; - clear_scheduler_notifies(); + clear_scheduled_notifies(); lua::engine::start(); } return result; diff --git a/src/client/game/scripting/lua/context.cpp b/src/client/game/scripting/lua/context.cpp index a7cf604f..2b8eefd7 100644 --- a/src/client/game/scripting/lua/context.cpp +++ b/src/client/game/scripting/lua/context.cpp @@ -877,10 +877,15 @@ namespace scripting::lua void context::notify(const event& e) { - this->scheduler_.dispatch(e); this->event_handler_.dispatch(e); } + void context::handle_endon_conditions(const event& e) + { + this->scheduler_.dispatch(e); + this->event_handler_.handle_endon_conditions(e); + } + void context::load_script(const std::string& script) { if (!this->loaded_scripts_.emplace(script).second) diff --git a/src/client/game/scripting/lua/context.hpp b/src/client/game/scripting/lua/context.hpp index e6175953..8281bb50 100644 --- a/src/client/game/scripting/lua/context.hpp +++ b/src/client/game/scripting/lua/context.hpp @@ -29,6 +29,7 @@ namespace scripting::lua void run_frame(); void notify(const event& e); + void handle_endon_conditions(const event& e); std::string load(const std::string& code); diff --git a/src/client/game/scripting/lua/engine.cpp b/src/client/game/scripting/lua/engine.cpp index d7fb2241..af1c0e75 100644 --- a/src/client/game/scripting/lua/engine.cpp +++ b/src/client/game/scripting/lua/engine.cpp @@ -69,6 +69,14 @@ namespace scripting::lua::engine } } + void handle_endon_conditions(const event& e) + { + for (auto& script : get_scripts()) + { + script->handle_endon_conditions(e); + } + } + void run_frame() { for (auto& script : get_scripts()) diff --git a/src/client/game/scripting/lua/engine.hpp b/src/client/game/scripting/lua/engine.hpp index bab42cdd..c425c73a 100644 --- a/src/client/game/scripting/lua/engine.hpp +++ b/src/client/game/scripting/lua/engine.hpp @@ -7,6 +7,7 @@ namespace scripting::lua::engine void start(); void stop(); void notify(const event& e); + void handle_endon_conditions(const event& e); void run_frame(); std::optional load(const std::string& code); diff --git a/src/client/game/scripting/lua/event_handler.cpp b/src/client/game/scripting/lua/event_handler.cpp index b0f8f876..01b13306 100644 --- a/src/client/game/scripting/lua/event_handler.cpp +++ b/src/client/game/scripting/lua/event_handler.cpp @@ -31,7 +31,6 @@ namespace scripting::lua callbacks_.access([&](task_list& tasks) { this->merge_callbacks(); - this->handle_endon_conditions(event); for (auto i = tasks.begin(); i != tasks.end();) { @@ -157,6 +156,7 @@ namespace scripting::lua }; callbacks_.access(deleter); + new_callbacks_.access(deleter); } event_arguments event_handler::build_arguments(const event& event) const diff --git a/src/client/game/scripting/lua/event_handler.hpp b/src/client/game/scripting/lua/event_handler.hpp index 981392e7..da35ddd4 100644 --- a/src/client/game/scripting/lua/event_handler.hpp +++ b/src/client/game/scripting/lua/event_handler.hpp @@ -40,6 +40,8 @@ namespace scripting::lua void clear(); + void handle_endon_conditions(const event& event); + private: sol::state& state_; std::atomic_int64_t current_listener_id_ = 0; @@ -50,7 +52,6 @@ namespace scripting::lua void remove(const event_listener_handle& handle); void merge_callbacks(); - void handle_endon_conditions(const event& event); void add_endon_condition(const event_listener_handle& handle, const entity& entity, const std::string& event);