From 5be4f892c60859665cecfad77f209a40bf1d38f6 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 9 Jan 2022 03:02:54 +0100 Subject: [PATCH] Small fix --- src/client/game/ui_scripting/lua/context.cpp | 75 +++----------------- 1 file changed, 11 insertions(+), 64 deletions(-) diff --git a/src/client/game/ui_scripting/lua/context.cpp b/src/client/game/ui_scripting/lua/context.cpp index 84d44f79..c3595c28 100644 --- a/src/client/game/ui_scripting/lua/context.cpp +++ b/src/client/game/ui_scripting/lua/context.cpp @@ -1155,77 +1155,24 @@ namespace ui_scripting::lua ::scheduler::once([s, name, args = std::vector(va.begin(), va.end())]() { - std::vector arguments{}; - - for (auto arg : args) + try { - arguments.push_back(script_convert({s, arg})); - } + std::vector arguments{}; - const auto player_value = scripting::call("getentbynum", {0}); - if (player_value.get_raw().type != ::game::SCRIPT_OBJECT) + for (auto arg : args) + { + arguments.push_back(script_convert({s, arg})); + } + + const auto player = scripting::call("getentbynum", {0}).as(); + scripting::notify(player, name, arguments); + } + catch (...) { - return; } - - const auto player = player_value.as(); - - scripting::notify(player, name, arguments); }, ::scheduler::pipeline::server); }; - player_type["getorigin"] = [](const player&) - { - if (!::game::CL_IsCgameInitialized() || !::game::g_entities[0].client) - { - throw std::runtime_error("Not in game"); - } - - return scripting::vector( - ::game::g_entities[0].origin[0], - ::game::g_entities[0].origin[1], - ::game::g_entities[0].origin[2] - ); - }; - - player_type["setorigin"] = [](const player&, const scripting::vector& velocity) - { - if (!::game::CL_IsCgameInitialized() || !::game::g_entities[0].client) - { - throw std::runtime_error("Not in game"); - } - - ::game::g_entities[0].origin[0] = velocity.get_x(); - ::game::g_entities[0].origin[1] = velocity.get_y(); - ::game::g_entities[0].origin[2] = velocity.get_z(); - }; - - player_type["getvelocity"] = [](const player&) - { - if (!::game::CL_IsCgameInitialized() || !::game::g_entities[0].client) - { - throw std::runtime_error("Not in game"); - } - - return scripting::vector( - ::game::g_entities[0].client->velocity[0], - ::game::g_entities[0].client->velocity[1], - ::game::g_entities[0].client->velocity[2] - ); - }; - - player_type["setvelocity"] = [](const player&, const scripting::vector& velocity) - { - if (!::game::CL_IsCgameInitialized() || !::game::g_entities[0].client) - { - throw std::runtime_error("Not in game"); - } - - ::game::g_entities[0].client->velocity[0] = velocity.get_x(); - ::game::g_entities[0].client->velocity[1] = velocity.get_y(); - ::game::g_entities[0].client->velocity[2] = velocity.get_z(); - }; - state.script(animation_script); } }