diff --git a/src/client/game/ui_scripting/lua/context.cpp b/src/client/game/ui_scripting/lua/context.cpp index 0d975d0d..1db94910 100644 --- a/src/client/game/ui_scripting/lua/context.cpp +++ b/src/client/game/ui_scripting/lua/context.cpp @@ -2,6 +2,7 @@ #include "context.hpp" #include "error.hpp" #include "value_conversion.hpp" +#include "../../scripting/execution.hpp" #include "../script_value.hpp" #include "../execution.hpp" @@ -262,6 +263,51 @@ namespace ui_scripting::lua updater_table["getcurrentfile"] = updater::get_current_file; state["updater"] = updater_table; + + if (::game::environment::is_sp()) + { + struct player + { + }; + auto player_type = state.new_usertype("player_"); + state["player"] = player(); + + player_type["notify"] = [](const player&, const sol::this_state s, const std::string& name, sol::variadic_args va) + { + if (!::game::CL_IsCgameInitialized() || !::game::sp::g_entities[0].client) + { + throw std::runtime_error("Not in game"); + } + + const sol::state_view view{s}; + const auto to_string = view["tostring"].get(); + + std::vector args{}; + for (auto arg : va) + { + args.push_back(to_string.call(arg).get()); + } + + ::scheduler::once([s, name, args]() + { + try + { + std::vector arguments{}; + + for (const auto& arg : args) + { + arguments.push_back(arg); + } + + const auto player = scripting::call("getentbynum", {0}).as(); + scripting::notify(player, name, arguments); + } + catch (...) + { + } + }, ::scheduler::pipeline::server); + }; + } } }