diff --git a/include/TLuaEngine.h b/include/TLuaEngine.h index 07ede1b3..e020850a 100644 --- a/include/TLuaEngine.h +++ b/include/TLuaEngine.h @@ -263,6 +263,7 @@ class TLuaEngine : public std::enable_shared_from_this, IThreaded { 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::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 9f1f5339..42440b11 100644 --- a/src/TLuaEngine.cpp +++ b/src/TLuaEngine.cpp @@ -595,6 +595,16 @@ sol::table TLuaEngine::StateThreadData::Lua_GetPlayerIdentifiers(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 sol::nil; + } +} + + sol::table TLuaEngine::StateThreadData::Lua_GetPlayers() { sol::table Result = mStateView.create_table(); mEngine->Server().ForEachClient([&](std::weak_ptr Client) -> bool { @@ -892,6 +902,9 @@ 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::variant { + return Lua_GetPlayerRole(ID); + }); MPTable.set_function("Sleep", &LuaAPI::MP::Sleep); // const std::string& EventName, size_t IntervalMS, int strategy MPTable.set_function("CreateEventTimer", [&](sol::variadic_args Args) {