AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved How to loop steamid while using keyvalues (https://forums.alliedmods.net/showthread.php?t=341759)

alasfourom 02-10-2023 09:22

How to loop steamid while using keyvalues
 
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

3ipKa 02-10-2023 11:06

Re: How to loop steamid while using keyvalues
 
I think something like this )
Code:

char name[128];
int points;

if(g_KeyValue.GotoFirstSubKey())
{
        do
        {
                g_KeyValue.GetString("Player Name", name, sizeof(name));
                points = g_KeyValue.GetNum("Total Points");
                //do somthing with that information
        }
        while(g_KeyValue.GotoNextKey());
}


alasfourom 02-10-2023 14:34

Re: How to loop steamid while using keyvalues
 
Ahhh Got it, thanks :up: and it worked

Quote:

Originally Posted by 3ipKa (Post 2799230)
I think something like this )
Code:

char name[128];
int points;

if(g_KeyValue.GotoFirstSubKey())
{
        do
        {
                g_KeyValue.GetString("Player Name", name, sizeof(name));
                points = g_KeyValue.GetNum("Total Points");
                //do somthing with that information
        }
        while(g_KeyValue.GotoNextKey());
}




All times are GMT -4. The time now is 00:59.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.