Add player statistics to API (#5193)
* Fixed issue #5166 Co-authored-by: 12xx12 <44411062+12xx12@users.noreply.github.com> Co-authored-by: Tiger Wang <ziwei.tiger@outlook.com>
This commit is contained in:
co-authored by
12xx12
Tiger Wang
parent
626f8b2350
commit
8be1dd54bb
@@ -4348,6 +4348,69 @@ static int tolua_cEntity_GetSpeed(lua_State * tolua_S)
|
||||
|
||||
|
||||
|
||||
static int tolua_get_StatisticsManager_Custom(lua_State * tolua_S)
|
||||
{
|
||||
// Check the params:
|
||||
cLuaState L(tolua_S);
|
||||
if (!L.CheckParamNumber(2))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the params:
|
||||
lua_pushstring(tolua_S, ".self");
|
||||
lua_rawget(tolua_S, 1);
|
||||
StatisticsManager * Self = static_cast<StatisticsManager *>(lua_touserdata(tolua_S, -1));
|
||||
CustomStatistic Statistic;
|
||||
if (!L.GetStackValue(2, Statistic))
|
||||
{
|
||||
return L.ApiParamError("Expected a valid custom statistic ID");
|
||||
}
|
||||
|
||||
// Push result if statistic exists:
|
||||
if (const auto Result = Self->Custom.find(Statistic); Result != Self->Custom.end())
|
||||
{
|
||||
L.Push(Result->second);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_set_StatisticsManager_Custom(lua_State * tolua_S)
|
||||
{
|
||||
// Check the params:
|
||||
cLuaState L(tolua_S);
|
||||
if (!L.CheckParamNumber(2))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the params:
|
||||
lua_pushstring(tolua_S, ".self");
|
||||
lua_rawget(tolua_S, 1);
|
||||
StatisticsManager * Self = static_cast<StatisticsManager *>(lua_touserdata(tolua_S, -1));
|
||||
CustomStatistic Statistic;
|
||||
StatisticsManager::StatValue Value;
|
||||
if (!L.GetStackValues(2, Statistic, Value))
|
||||
{
|
||||
return L.ApiParamError("Expected a valid custom statistic ID and value");
|
||||
}
|
||||
|
||||
// Set the value:
|
||||
Self->Custom[Statistic] = Value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cManualBindings::Bind(lua_State * tolua_S)
|
||||
{
|
||||
tolua_beginmodule(tolua_S, nullptr);
|
||||
@@ -4357,10 +4420,12 @@ void cManualBindings::Bind(lua_State * tolua_S)
|
||||
tolua_usertype(tolua_S, "cLineBlockTracer");
|
||||
tolua_usertype(tolua_S, "cStringCompression");
|
||||
tolua_usertype(tolua_S, "cUrlParser");
|
||||
// StatisticsManager was already created by cPlayer::GetStatistics' autogenerated bindings.
|
||||
tolua_cclass(tolua_S, "cCryptoHash", "cCryptoHash", "", nullptr);
|
||||
tolua_cclass(tolua_S, "cLineBlockTracer", "cLineBlockTracer", "", nullptr);
|
||||
tolua_cclass(tolua_S, "cStringCompression", "cStringCompression", "", nullptr);
|
||||
tolua_cclass(tolua_S, "cUrlParser", "cUrlParser", "", nullptr);
|
||||
tolua_cclass(tolua_S, "StatisticsManager", "StatisticsManager", "", nullptr);
|
||||
|
||||
// Globals:
|
||||
tolua_function(tolua_S, "Clamp", tolua_Clamp);
|
||||
@@ -4592,6 +4657,10 @@ void cManualBindings::Bind(lua_State * tolua_S)
|
||||
tolua_variable(tolua_S, "PostParams", tolua_get_HTTPRequest_PostParams, nullptr);
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
tolua_beginmodule(tolua_S, "StatisticsManager");
|
||||
tolua_array(tolua_S, "Custom", tolua_get_StatisticsManager_Custom, tolua_set_StatisticsManager_Custom);
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
BindNetwork(tolua_S);
|
||||
BindRankManager(tolua_S);
|
||||
BindWorld(tolua_S);
|
||||
|
||||
Reference in New Issue
Block a user