Skip to content

Commit cd55542

Browse files
committed
Add CClient* support to Lua argument parser
1 parent 9653039 commit cd55542

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*****************************************************************************/
1010
#pragma once
1111
#include "CElementIDs.h"
12+
#include "CConsoleClient.h"
1213

1314
// Forward declare enum reflection stuff
1415
enum eLuaType
@@ -119,6 +120,10 @@ inline SString GetClassTypeName(CElement*)
119120
{
120121
return "element";
121122
}
123+
inline SString GetClassTypeName(CClient*)
124+
{
125+
return "client";
126+
}
122127
inline SString GetClassTypeName(CPlayer*)
123128
{
124129
return "player";
@@ -437,6 +442,24 @@ CPlayer* UserDataCast(CPlayer*, void* ptr, lua_State*)
437442
return (CPlayer*)pElement;
438443
}
439444

445+
// CClient from CConsoleClient or a CPlayer
446+
template <class T>
447+
CClient* UserDataCast(CClient*, void* ptr, lua_State*)
448+
{
449+
ElementID ID = TO_ELEMENTID(ptr);
450+
CElement* pElement = CElementIDs::GetElement(ID);
451+
if (!pElement || pElement->IsBeingDeleted())
452+
return nullptr;
453+
454+
CClient* pClient = nullptr;
455+
if (pElement->GetType() == CElement::PLAYER)
456+
pClient = reinterpret_cast<CPlayer*>(pElement);
457+
else if (pElement->GetType() == CElement::CONSOLE)
458+
pClient = reinterpret_cast<CConsoleClient*>(pElement);
459+
460+
return pClient;
461+
}
462+
440463
//
441464
// CElement ( something )
442465
//

0 commit comments

Comments
 (0)