View Single Post
Author Message
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 02-10-2023 , 09:22   How to loop steamid while using keyvalues
Reply With Quote #1

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_SMg_sData_PathPLATFORM_MAX_PATH"data/l4d2_rank_system.cfg");
    
LoadConfig();
}

Action Command_Top10(int clientint args)
{
    if(!
g_KeyValue.JumpToKey("Players Information"))
    {
        
delete g_KeyValue;
        
ThrowError("Corrupted file %s."g_sData_Path);
    }
    
    for(
int i 0<= 10i++)
    {
        
//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(clientAuthId_Steam2SteamIDsizeof(SteamID));
    
g_KeyValue.Rewind();
    
    if(!
g_KeyValue.JumpToKey("Players Information"))
    {
        
delete g_KeyValue;
        
ThrowError("Corrupted file %s."g_sData_Path);
    }
    
    if(
g_KeyValue.JumpToKey(SteamIDtrue))
    {
        
char str[32];
        
g_KeyValue.GetString("Total Points"strsizeof(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
__________________

Last edited by alasfourom; 02-10-2023 at 14:34.
alasfourom is offline