Skip to content

Commit

Permalink
Add CClient* support to Lua argument parser
Browse files Browse the repository at this point in the history
  • Loading branch information
qaisjp committed May 7, 2020
1 parent 9653039 commit cd55542
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*****************************************************************************/
#pragma once
#include "CElementIDs.h"
#include "CConsoleClient.h"

// Forward declare enum reflection stuff
enum eLuaType
Expand Down Expand Up @@ -119,6 +120,10 @@ inline SString GetClassTypeName(CElement*)
{
return "element";
}
inline SString GetClassTypeName(CClient*)
{
return "client";
}
inline SString GetClassTypeName(CPlayer*)
{
return "player";
Expand Down Expand Up @@ -437,6 +442,24 @@ CPlayer* UserDataCast(CPlayer*, void* ptr, lua_State*)
return (CPlayer*)pElement;
}

// CClient from CConsoleClient or a CPlayer
template <class T>
CClient* UserDataCast(CClient*, void* ptr, lua_State*)
{
ElementID ID = TO_ELEMENTID(ptr);
CElement* pElement = CElementIDs::GetElement(ID);
if (!pElement || pElement->IsBeingDeleted())
return nullptr;

CClient* pClient = nullptr;
if (pElement->GetType() == CElement::PLAYER)
pClient = reinterpret_cast<CPlayer*>(pElement);
else if (pElement->GetType() == CElement::CONSOLE)
pClient = reinterpret_cast<CConsoleClient*>(pElement);

return pClient;
}

//
// CElement ( something )
//
Expand Down

0 comments on commit cd55542

Please sign in to comment.