Skip to content
Permalink
Browse files

Add set/getPlayerScriptDebugLevel (#826)

* Add setPlayerDebugViewActive and setPlayerDebugViewMode

* Modify setPlayerDebugView* functions to work with the root element

* Remove whitespace changes introduced in 9c8ca2e

* Fix variables naming

* Add set/getPlayerScriptDebugLevel

Also remove setPlayerDebugView* functions

* Update ACL to reflect commit 0402ebf

* Change Set/GetPlayerDebuggerLevel to Set/GetPlayerScriptDebugLevel (CStaticFunctionDefinitions)

* Update make_uname.bat

* Force hard errors
  • Loading branch information...
knitz12 authored and patrikjuvonen committed Sep 2, 2019
1 parent 75babd0 commit ded201f615e46c30f8402937df5dcb956e1c0a77
@@ -136,6 +136,7 @@
<right name="function.setServerConfigSetting" access="false" />
<right name="function.updateResourceACLRequest" access="false" />
<right name="function.shutdown" access="false" />
<right name="function.setPlayerScriptDebugLevel" access="false" />
</acl>
<acl name="Moderator">
<right name="general.ModifyOtherObjects" access="false" />
@@ -230,6 +231,7 @@
<right name="function.setServerConfigSetting" access="true" />
<right name="function.updateResourceACLRequest" access="true" />
<right name="function.shutdown" access="true" />
<right name="function.setPlayerScriptDebugLevel" access="true" />
</acl>
<acl name="RPC">
<right name="function.callRemote" access="true" />
@@ -1864,6 +1864,14 @@ 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);
@@ -3050,8 +3058,6 @@ bool CStaticFunctionDefinitions::TakePlayerScreenShot(CElement* pElement, uint u

bool CStaticFunctionDefinitions::SetPlayerDebuggerVisible(CElement* pElement, bool bVisible)
{
// * Not used by scripts

assert(pElement);
RUN_CHILDREN(SetPlayerDebuggerVisible(*iter, bVisible))

@@ -3068,6 +3074,26 @@ bool CStaticFunctionDefinitions::SetPlayerDebuggerVisible(CElement* pElement, bo
return false;
}

bool CStaticFunctionDefinitions::SetPlayerScriptDebugLevel(CElement* pElement, unsigned int uiLevel)
{
assert(pElement);

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

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

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

return false;
}

bool CStaticFunctionDefinitions::SetPlayerWantedLevel(CElement* pElement, unsigned int uiLevel)
{
assert(pElement);
@@ -11235,7 +11261,7 @@ CBan* CStaticFunctionDefinitions::BanPlayer(CPlayer* pPlayer, bool bIP, bool bUs
// Call the event
CLuaArguments Arguments;
Arguments.PushBan(pBan);

if (pResponsible)
Arguments.PushElement(pResponsible);

@@ -11408,10 +11434,10 @@ CBan* CStaticFunctionDefinitions::AddBan(SString strIP, SString strUsername, SSt
// Call the event
CLuaArguments Arguments;
Arguments.PushBan(pBan);

if (pResponsible)
Arguments.PushElement(pResponsible);

// A script can call kickPlayer in the onPlayerBan event, which would
// show him the 'kicked' message instead of our 'banned' message.
const bool bLeavingServer = pPlayer->IsLeavingServer();
@@ -124,6 +124,7 @@ 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);
@@ -132,6 +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 SetPlayerScriptDebugLevel(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);
@@ -43,6 +43,7 @@ void CLuaPlayerDefs::LoadFunctions()
{"getPlayerACInfo", GetPlayerACInfo},
{"resendPlayerModInfo", ResendPlayerModInfo},
{"resendPlayerACInfo", ResendPlayerACInfo},
{"getPlayerScriptDebugLevel", GetPlayerScriptDebugLevel},

// Player set funcs
{"setPlayerMoney", SetPlayerMoney},
@@ -63,6 +64,7 @@ void CLuaPlayerDefs::LoadFunctions()
{"setPlayerName", SetPlayerName},
{"detonateSatchels", DetonateSatchels},
{"takePlayerScreenShot", TakePlayerScreenShot},
{"setPlayerScriptDebugLevel", SetPlayerScriptDebugLevel},

// All seeing eye
{"getPlayerAnnounceValue", GetPlayerAnnounceValue},
@@ -151,6 +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, "setScriptDebugLevel", "setPlayerScriptDebugLevel");

lua_classfunction(luaVM, "isMapForced", "isPlayerMapForced");
lua_classfunction(luaVM, "isMuted", "isPlayerMuted");
@@ -173,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");
@@ -195,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",
@@ -941,6 +946,49 @@ int CLuaPlayerDefs::TakePlayerScreenShot(lua_State* luaVM)
return 1;
}

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

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
if (argStream.NextIsBool())
{
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;
}
else
{
lua_pushboolean(luaVM, false);
return 1;
}
}

int CLuaPlayerDefs::SetPlayerWantedLevel(lua_State* luaVM)
{
CElement* pElement;
@@ -1431,6 +1479,33 @@ 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())
{
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;
}
}

int CLuaPlayerDefs::BindKey(lua_State* luaVM)
{
CPlayer* pPlayer;
@@ -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);
@@ -64,6 +65,7 @@ class CLuaPlayerDefs : public CLuaDefs
LUA_DECLARE(SetPlayerName);
LUA_DECLARE(DetonateSatchels);
LUA_DECLARE(TakePlayerScreenShot);
LUA_DECLARE(SetPlayerScriptDebugLevel);

// All seeing eye
LUA_DECLARE(GetPlayerAnnounceValue);
@@ -99,4 +101,4 @@ class CLuaPlayerDefs : public CLuaDefs
// Admin funcs
LUA_DECLARE(KickPlayer);
LUA_DECLARE(BanPlayer);
};
};

0 comments on commit ded201f

Please sign in to comment.
You can’t perform that action at this time.