Skip to content

Commit

Permalink
Add set/getPlayerScriptDebugLevel
Browse files Browse the repository at this point in the history
Also remove setPlayerDebugView* functions
  • Loading branch information
knitz12 committed Feb 21, 2019
1 parent 7e920ec commit 0402ebf
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 38 deletions.
19 changes: 15 additions & 4 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,14 @@ const SString& CStaticFunctionDefinitions::GetPlayerVersion(CPlayer* pPlayer)
return pPlayer->GetPlayerVersion();
}

bool CStaticFunctionDefinitions::GetPlayerDebuggerLevel(CPlayer* pPlayer, unsigned int& uiLevel)
{
assert(pPlayer);

uiLevel = pPlayer->GetScriptDebugLevel();
return true;
}

bool CStaticFunctionDefinitions::SetPlayerName(CElement* pElement, const char* szName)
{
assert(pElement);
Expand Down Expand Up @@ -3066,19 +3074,22 @@ bool CStaticFunctionDefinitions::SetPlayerDebuggerVisible(CElement* pElement, bo
return false;
}

bool CStaticFunctionDefinitions::SetPlayerDebuggerMode(CElement* pElement, unsigned int uiMode)
bool CStaticFunctionDefinitions::SetPlayerDebuggerLevel(CElement* pElement, unsigned int uiLevel)
{
assert(pElement);

if (uiMode >= 0 && uiMode <= 3)
if (uiLevel >= 0 && uiLevel <= 3)
{
RUN_CHILDREN(SetPlayerDebuggerMode(*iter, uiMode));
RUN_CHILDREN(SetPlayerDebuggerLevel(*iter, uiLevel));

if (IS_PLAYER(pElement))
{
CPlayer* pPlayer = static_cast<CPlayer*>(pElement);

return pPlayer->SetScriptDebugLevel(uiMode);
if (pPlayer->SetScriptDebugLevel(uiLevel))
{
return SetPlayerDebuggerVisible(pElement, uiLevel != 0);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class CStaticFunctionDefinitions
static bool GetPlayerIP(CElement* pElement, SString& strOutIP);
static CAccount* GetPlayerAccount(CElement* pElement);
static const SString& GetPlayerVersion(CPlayer* pPlayer);
static bool GetPlayerDebuggerLevel(CPlayer* pPlayer, unsigned int& uiLevel);

// Player set functions
static bool SetPlayerMoney(CElement* pElement, long lMoney, bool bInstant);
Expand All @@ -132,7 +133,7 @@ class CStaticFunctionDefinitions
static bool TakePlayerMoney(CElement* pElement, long lMoney);
static bool ShowPlayerHudComponent(CElement* pElement, eHudComponent component, bool bShow);
static bool SetPlayerDebuggerVisible(CElement* pElement, bool bVisible);
static bool SetPlayerDebuggerMode(CElement* pElement, unsigned int uiMode);
static bool SetPlayerDebuggerLevel(CElement* pElement, unsigned int uiLevel);
static bool SetPlayerWantedLevel(CElement* pElement, unsigned int iLevel);
static bool ForcePlayerMap(CElement* pElement, bool bVisible);
static bool SetPlayerNametagText(CElement* pElement, const char* szText);
Expand Down
81 changes: 50 additions & 31 deletions Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void CLuaPlayerDefs::LoadFunctions()
{"getPlayerACInfo", GetPlayerACInfo},
{"resendPlayerModInfo", ResendPlayerModInfo},
{"resendPlayerACInfo", ResendPlayerACInfo},
{"getPlayerScriptDebugLevel", GetPlayerScriptDebugLevel},

// Player set funcs
{"setPlayerMoney", SetPlayerMoney},
Expand All @@ -63,8 +64,7 @@ void CLuaPlayerDefs::LoadFunctions()
{"setPlayerName", SetPlayerName},
{"detonateSatchels", DetonateSatchels},
{"takePlayerScreenShot", TakePlayerScreenShot},
{"setPlayerDebugViewActive", SetPlayerDebugViewActive},
{"setPlayerDebugViewMode", SetPlayerDebugViewMode},
{"setPlayerScriptDebugLevel", SetPlayerScriptDebugLevel},

// All seeing eye
{"getPlayerAnnounceValue", GetPlayerAnnounceValue},
Expand Down Expand Up @@ -153,8 +153,7 @@ void CLuaPlayerDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "setCameraMatrix", "setCameraMatrix");
lua_classfunction(luaVM, "setCameraInterior", "setCameraInterior");
lua_classfunction(luaVM, "setCameraTarget", "setCameraTarget");
lua_classfunction(luaVM, "setDebugViewActive", "setPlayerDebugViewActive");
lua_classfunction(luaVM, "setDebugViewMode", "setPlayerDebugViewMode");
lua_classfunction(luaVM, "setScriptDebugLevel", "setPlayerScriptDebugLevel");

lua_classfunction(luaVM, "isMapForced", "isPlayerMapForced");
lua_classfunction(luaVM, "isMuted", "isPlayerMuted");
Expand All @@ -177,6 +176,7 @@ void CLuaPlayerDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "getCameraInterior", "getCameraInterior");
lua_classfunction(luaVM, "getCameraMatrix", "getCameraMatrix");
lua_classfunction(luaVM, "getCameraTarget", "getCameraTarget");
lua_classfunction(luaVM, "getScriptDebugLevel", "getPlayerScriptDebugLevel");

lua_classvariable(luaVM, "account", NULL, "getPlayerAccount");
lua_classvariable(luaVM, "cameraInterior", "setCameraInterior", "getCameraInterior");
Expand All @@ -199,6 +199,7 @@ void CLuaPlayerDefs::AddClass(lua_State* luaVM)
lua_classvariable(luaVM, "mapForced", "forcePlayerMap", "isPlayerMapForced");
lua_classvariable(luaVM, "nametagText", "setPlayerNametagText", "getPlayerNametagText");
lua_classvariable(luaVM, "nametagShowing", "setPlayerNametagShowing", "isPlayerNametagShowing");
lua_classvariable(luaVM, "scriptDebugLevel", "setPlayerScriptDebugLevel", "getPlayerScriptDebugLevel");
// lua_classvariable ( luaVM, "nametagColor", "setPlayerNametagColor", "getPlayerNametagColor", CLuaPlayerDefs::SetPlayerNametagColor,
// OOP_GetPlayerNametagColor ); lua_classvariable ( luaVM, "announceValue", "setPlayerAnnounceValue", "getPlayerAnnounceValue",
// CLuaPlayerDefs::SetPlayerAnnounceValue, OOP_GetPlayerAnnounceValue ); // .announceValue[key]=value lua_classvariable ( luaVM, "hudComponent",
Expand Down Expand Up @@ -945,47 +946,40 @@ int CLuaPlayerDefs::TakePlayerScreenShot(lua_State* luaVM)
return 1;
}

int CLuaPlayerDefs::SetPlayerDebugViewActive(lua_State* luaVM)
int CLuaPlayerDefs::SetPlayerScriptDebugLevel(lua_State* luaVM)
{
CElement* pElement;
bool bActive;
CElement* pElement;
unsigned int uiMode;
bool bHideDebugger = false;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
argStream.ReadBool(bActive);

if (!argStream.HasErrors())
if (argStream.NextIsBool())
{
if (CStaticFunctionDefinitions::SetPlayerDebuggerVisible(pElement, bActive))
bool bTemp;

argStream.ReadBool(bTemp);

if (bTemp)
{
lua_pushboolean(luaVM, true);
return 1;
argStream.SetCustomError("You can only pass false to hide the debug window or a level (0-3)");
}
else
bHideDebugger = true;
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaPlayerDefs::SetPlayerDebugViewMode(lua_State* luaVM)
{
CElement* pElement;
unsigned int uiMode;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
argStream.ReadNumber(uiMode);

if (uiMode < 0 || uiMode > 3)
{
argStream.SetCustomError("Invalid Mode (0-3)");
argStream.ReadNumber(uiMode);

if (uiMode < 0 || uiMode > 3)
{
argStream.SetCustomError("Invalid level (0-3)");
}
}

if (!argStream.HasErrors())
{
if (CStaticFunctionDefinitions::SetPlayerDebuggerMode(pElement, uiMode))
if (CStaticFunctionDefinitions::SetPlayerDebuggerLevel(pElement, bHideDebugger ? 0 : uiMode))
{
lua_pushboolean(luaVM, true);
return 1;
Expand Down Expand Up @@ -1488,6 +1482,31 @@ int CLuaPlayerDefs::ResendPlayerACInfo(lua_State* luaVM)
return 1;
}

int CLuaPlayerDefs::GetPlayerScriptDebugLevel(lua_State* luaVM)
{
// int getPlayerScriptDebugLevel ( player thePlayer )
CPlayer* pPlayer;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pPlayer);

if (!argStream.HasErrors())
{
unsigned int uiLevel;

if (CStaticFunctionDefinitions::GetPlayerDebuggerLevel(pPlayer, uiLevel))
{
lua_pushnumber(luaVM, uiLevel);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaPlayerDefs::BindKey(lua_State* luaVM)
{
CPlayer* pPlayer;
Expand Down
4 changes: 2 additions & 2 deletions Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CLuaPlayerDefs : public CLuaDefs
LUA_DECLARE(GetPlayerAccount);
LUA_DECLARE(GetPlayerVersion);
LUA_DECLARE(GetPlayerACInfo);
LUA_DECLARE(GetPlayerScriptDebugLevel);

// Player set functions
LUA_DECLARE(SetPlayerMoney);
Expand All @@ -64,8 +65,7 @@ class CLuaPlayerDefs : public CLuaDefs
LUA_DECLARE(SetPlayerName);
LUA_DECLARE(DetonateSatchels);
LUA_DECLARE(TakePlayerScreenShot);
LUA_DECLARE(SetPlayerDebugViewActive);
LUA_DECLARE(SetPlayerDebugViewMode);
LUA_DECLARE(SetPlayerScriptDebugLevel);

// All seeing eye
LUA_DECLARE(GetPlayerAnnounceValue);
Expand Down

0 comments on commit 0402ebf

Please sign in to comment.