Hello guys,
I'm trying to do something like top10 players with highest points, storing points using KeyValues.
I have no idea how to loop through their steamid.
The script below is part of the actual long script, I didnt want to post it all, as its very long and I think its unnecessary
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
KeyValues g_KeyValue;
char g_sData_Path [PLATFORM_MAX_PATH];
public void OnPluginStart()
{
RegConsoleCmd("sm_top", Command_Top10, "Show Top 10");
BuildPath(Path_SM, g_sData_Path, PLATFORM_MAX_PATH, "data/l4d2_rank_system.cfg");
LoadConfig();
}
Action Command_Top10(int client, int args)
{
if(!g_KeyValue.JumpToKey("Players Information"))
{
delete g_KeyValue;
ThrowError("Corrupted file %s.", g_sData_Path);
}
for(int i = 0; i <= 10; i++)
{
//do the loop??
}
return Plugin_Handled;
}
bool LoadConfig()
{
g_KeyValue = new KeyValues("L4D2 Rank System");
if(!FileExists(g_sData_Path))
ThrowError("Missing file %s.", g_sData_Path);
if(!g_KeyValue.ImportFromFile(g_sData_Path))
{
delete g_KeyValue;
ThrowError("Couldn't open file %s.", g_sData_Path);
}
return true;
}
int ClientTotalPoints(int client)
{
char SteamID[32];
GetClientAuthId(client, AuthId_Steam2, SteamID, sizeof(SteamID));
g_KeyValue.Rewind();
if(!g_KeyValue.JumpToKey("Players Information"))
{
delete g_KeyValue;
ThrowError("Corrupted file %s.", g_sData_Path);
}
if(g_KeyValue.JumpToKey(SteamID, true))
{
char str[32];
g_KeyValue.GetString("Total Points", str, sizeof(str));
return StringToInt(str);
}
return 0;
}
The config data: test example
PHP Code:
"L4D2 Rank System"
{
"Players Information"
{
"STEAM_1:1:11111111"
{
"Player Name" "Test1"
"Total Points" "10"
}
"STEAM_1:1:22222222"
{
"Player Name" "Test2"
"Total Points" "20"
}
}
"STEAM_1:1:33333333"
{
"Player Name" "Test3"
"Total Points" "30"
}
}
}
Thanks
__________________