diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 763651a0322..23968957cbd 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1925,14 +1925,6 @@ const CMtaVersion& CStaticFunctionDefinitions::GetPlayerVersion(CPlayer* pPlayer return pPlayer->GetPlayerVersion(); } -bool CStaticFunctionDefinitions::GetPlayerScriptDebugLevel(CPlayer* pPlayer, unsigned int& uiLevel) -{ - assert(pPlayer); - - uiLevel = pPlayer->GetScriptDebugLevel(); - return true; -} - bool CStaticFunctionDefinitions::SetPlayerName(CElement* pElement, const char* szName) { assert(pElement); diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index dafb06f22d1..a64c73266e2 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -127,7 +127,6 @@ class CStaticFunctionDefinitions static bool GetPlayerIP(CElement* pElement, SString& strOutIP); static CAccount* GetPlayerAccount(CElement* pElement); static const CMtaVersion& GetPlayerVersion(CPlayer* pPlayer); - static bool GetPlayerScriptDebugLevel(CPlayer* pPlayer, unsigned int& uiLevel); // Player set functions static bool SetPlayerMoney(CElement* pElement, long lMoney, bool bInstant); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp index bea1d3e9c17..8b9b3b216f2 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp @@ -43,7 +43,7 @@ void CLuaPlayerDefs::LoadFunctions() {"getPlayerACInfo", GetPlayerACInfo}, {"resendPlayerModInfo", ResendPlayerModInfo}, {"resendPlayerACInfo", ResendPlayerACInfo}, - {"getPlayerScriptDebugLevel", GetPlayerScriptDebugLevel}, + {"getPlayerScriptDebugLevel", ArgumentParser}, // Player set funcs {"setPlayerMoney", SetPlayerMoney}, @@ -65,7 +65,7 @@ void CLuaPlayerDefs::LoadFunctions() {"setPlayerName", SetPlayerName}, {"detonateSatchels", DetonateSatchels}, {"takePlayerScreenShot", TakePlayerScreenShot}, - {"setPlayerScriptDebugLevel", SetPlayerScriptDebugLevel}, + {"setPlayerScriptDebugLevel", ArgumentParser}, // All seeing eye {"getPlayerAnnounceValue", GetPlayerAnnounceValue}, @@ -946,47 +946,23 @@ int CLuaPlayerDefs::TakePlayerScreenShot(lua_State* luaVM) return 1; } -int CLuaPlayerDefs::SetPlayerScriptDebugLevel(lua_State* luaVM) +bool CLuaPlayerDefs::SetPlayerScriptDebugLevel(CElement* const element, const std::variant variant) { - CElement* pElement; - unsigned int uiMode; - bool bHideDebugger = false; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pElement); - if (argStream.NextIsBool()) + unsigned int level; + if (std::holds_alternative(variant)) { - bool bTemp; - argStream.ReadBool(bTemp); - - if (bTemp) - argStream.SetCustomError("You can only pass false to hide the debug window or a level (0-3)"); - else - bHideDebugger = true; - } - else - { - argStream.ReadNumber(uiMode); - - if (uiMode < 0 || uiMode > 3) - argStream.SetCustomError("Invalid level (0-3)"); - } - - if (argStream.HasErrors()) - { - return luaL_error(luaVM, argStream.GetFullErrorMessage()); - } - - if (CStaticFunctionDefinitions::SetPlayerScriptDebugLevel(pElement, bHideDebugger ? 0 : uiMode)) - { - lua_pushboolean(luaVM, true); - return 1; + // cant be a true bool + if (std::get(variant)) + throw std::invalid_argument("You can only pass 'false' to hide the debug window, pass in a level(0-3) to enable it"); + level = 0; } else { - lua_pushboolean(luaVM, false); - return 1; + level = std::get(variant); + if (level > 3) + throw std::invalid_argument("Invalid level (0-3)"); } + return CStaticFunctionDefinitions::SetPlayerScriptDebugLevel(element, level); } int CLuaPlayerDefs::SetPlayerWantedLevel(lua_State* luaVM) @@ -1511,31 +1487,9 @@ int CLuaPlayerDefs::ResendPlayerACInfo(lua_State* luaVM) return 1; } -int CLuaPlayerDefs::GetPlayerScriptDebugLevel(lua_State* luaVM) +unsigned int CLuaPlayerDefs::GetPlayerScriptDebugLevel(CPlayer* const player) { - // int getPlayerScriptDebugLevel ( player thePlayer ) - CPlayer* pPlayer; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); - - if (argStream.HasErrors()) - { - return luaL_error(luaVM, argStream.GetFullErrorMessage()); - } - - unsigned int uiLevel; - - if (CStaticFunctionDefinitions::GetPlayerScriptDebugLevel(pPlayer, uiLevel)) - { - lua_pushnumber(luaVM, uiLevel); - return 1; - } - else - { - lua_pushboolean(luaVM, false); - return 1; - } + return player->GetScriptDebugLevel(); } int CLuaPlayerDefs::BindKey(lua_State* luaVM) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h index c1cc811e6f5..50a5f670471 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h @@ -46,7 +46,7 @@ class CLuaPlayerDefs : public CLuaDefs LUA_DECLARE(GetPlayerAccount); LUA_DECLARE(GetPlayerVersion); LUA_DECLARE(GetPlayerACInfo); - LUA_DECLARE(GetPlayerScriptDebugLevel); + static unsigned int GetPlayerScriptDebugLevel(CPlayer* const player); // Player set functions LUA_DECLARE(SetPlayerMoney); @@ -66,7 +66,7 @@ class CLuaPlayerDefs : public CLuaDefs LUA_DECLARE(SetPlayerName); LUA_DECLARE(DetonateSatchels); LUA_DECLARE(TakePlayerScreenShot); - LUA_DECLARE(SetPlayerScriptDebugLevel); + static bool SetPlayerScriptDebugLevel(CElement* const element, const std::variant variant); // All seeing eye LUA_DECLARE(GetPlayerAnnounceValue); diff --git a/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h b/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h index da1d77d67d1..d3db3507819 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h +++ b/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h @@ -38,7 +38,7 @@ struct CLuaFunctionParserBase accumulator += "/" + TypeToName(); if constexpr (is_variant::count != 1) - return TypeToNameVariant::rest_t>(accumulator); + return TypeToNameVariant::rest_t>(accumulator); } template