Raised This Month: $51 Target: $400
 12% 

Solved How to loop steamid while using keyvalues


Post New Thread Reply   
 
Thread Tools Display Modes
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
3ipKa
Member
Join Date: Jul 2013
Old 02-10-2023 , 11:06   Re: How to loop steamid while using keyvalues
Reply With Quote #2

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());
}
3ipKa is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 02-10-2023 , 14:34   Re: How to loop steamid while using keyvalues
Reply With Quote #3

Ahhh Got it, thanks and it worked

Quote:
Originally Posted by 3ipKa View Post
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 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:35.


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