From 9a0270cb0980683e4f697a74ee844787b9ad16f1 Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Sat, 28 Sep 2024 21:05:04 +0200 Subject: [PATCH] Return nil instead of "" when there's no client --- include/TLuaEngine.h | 2 +- src/TLuaEngine.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/TLuaEngine.h b/include/TLuaEngine.h index 060ce1f..e020850 100644 --- a/include/TLuaEngine.h +++ b/include/TLuaEngine.h @@ -263,7 +263,7 @@ private: sol::table Lua_TriggerGlobalEvent(const std::string& EventName, sol::variadic_args EventArgs); sol::table Lua_TriggerLocalEvent(const std::string& EventName, sol::variadic_args EventArgs); sol::table Lua_GetPlayerIdentifiers(int ID); - std::string Lua_GetPlayerRole(int ID); + std::variant Lua_GetPlayerRole(int ID); sol::table Lua_GetPlayers(); std::string Lua_GetPlayerName(int ID); sol::table Lua_GetPlayerVehicles(int ID); diff --git a/src/TLuaEngine.cpp b/src/TLuaEngine.cpp index 5e88597..5708fe7 100644 --- a/src/TLuaEngine.cpp +++ b/src/TLuaEngine.cpp @@ -595,12 +595,12 @@ sol::table TLuaEngine::StateThreadData::Lua_GetPlayerIdentifiers(int ID) { } } -std::string TLuaEngine::StateThreadData::Lua_GetPlayerRole(int ID) { +std::variant TLuaEngine::StateThreadData::Lua_GetPlayerRole(int ID) { auto MaybeClient = GetClient(mEngine->Server(), ID); if (MaybeClient) { return MaybeClient.value().lock()->GetRoles(); } else { - return ""; + return sol::nil; } } @@ -893,7 +893,7 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI MPTable.set_function("GetPlayerIdentifiers", [&](int ID) -> sol::table { return Lua_GetPlayerIdentifiers(ID); }); - MPTable.set_function("GetPlayerRole", [&](int ID) -> std::string { + MPTable.set_function("GetPlayerRole", [&](int ID) -> std::variant { return Lua_GetPlayerRole(ID); }); MPTable.set_function("Sleep", &LuaAPI::MP::Sleep);