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

(Key Values) Getting the name of the next section


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SomePanns
Senior Member
Join Date: Dec 2013
Old 09-14-2016 , 12:01   (Key Values) Getting the name of the next section
Reply With Quote #1

I'm trying to figure out how to get the name of the next section... but I'm out of ideas, sadly. Every user has X points stored in a database. What I want it to do is to add a tag in front of users names (which is working right now) depending on how many points they have.

Right now it works good if the users points is an exact match with the section names, so if you have 10 points, you get the novice tag... and so on. The reason to why I'm asking for a way to get the next sections name, is because if a user has 15 points but BELOW the next sections value, I want them to have the novice tag. Same goes if the user has 50, then they should have Elite until they reach the next tier.

apct.txt (10, 50, 75 are points)
PHP Code:
"APCT" 
{
    
"10"
    
{
        
"tag"        "[Novice]"
    
}
    
    
"50"
    
{
        
"tag"        "[Elite]"
    
}
    
    
"75"
    
{
        
"tag"        "[Master]"
    
}

SourcePawn:
PHP Code:
public int APCT_Run(int client) {
    
// Start searching the config file for APCT
    
KeyValues kv CreateKeyValues("APCT");
    
char kv_file[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMkv_filePLATFORM_MAX_PATHAPCT_File);
    
    if(!
FileToKeyValues(kvkv_file))
        
SetFailState("[APCT] Failed to load 'APCT'!");
        
    
KvRewind(kv);
        
    
BrowseKeyValues(kvclient);
    
    return 
Plugin_Continue;
}

stock void BrowseKeyValues(KeyValues kvint client)
{
    do
    {
        
// You can read the section/key name by using KvGetSectionName here.
        
char kv_section_name[32];
        
KvGetSectionName(kvkv_section_namesizeof(kv_section_name));
        
int kv_section_id StringToInt(kv_section_name);
        
        if (
kv.GotoFirstSubKey(false))
        {
            
// Current key is a section. Browse it recursively.
            
BrowseKeyValues(kvclient);
            
kv.GoBack();
        }
        else
        {
            
// Current key is a regular key, or an empty section.
            
if (kv.GetDataType(NULL_STRING) != KvData_None)
            {
                
// Read value of key here (use NULL_STRING as key name). You can
                // also get the key name by using kv.GetSectionName here.
                
KvGetString(kvNULL_STRINGkv_snames[kv_section_id], sizeof(kv_snames));
                
                
char Tag[32];
                
Format(Tagsizeof(Tag), "%s"kv_snames[kv_section_id]);
                
ClientTag[client] = Tag;
            }
            else
            {
                
// Found an empty sub section. It can be handled here if necessary.
            
}
        }

        if(
ClientPoints[client] == kv_section_id) {
            break;
        }
    } while (
kv.GotoNextKey(false));

Ideas?
SomePanns is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-14-2016 , 12:26   Re: (Key Values) Getting the name of the next section
Reply With Quote #2

sry, this code is now new syntax.
Change older type if you like...

PHP Code:
public void OnPluginStart()
{
    
char buffer[64];
    
char tag[64];
    
int points;
    
int player_points 60;


    
KeyValues apct CreateKeyValues("");
    
apct.ImportFromFile("apct.txt"); 

    if(
apct.GotoFirstSubKey(true))
    {
        do
        {
            
apct.GetSectionName(buffersizeof(buffer));
            
points StringToInt(buffer);

            if(
player_points >= points)
            {
                
apct.GetString("tag"tagsizeof(tag), NULL_STRING);
                
PrintToServer("-%s %s"tagbuffer);
            }

        }
        while(
apct.GotoNextKey(true))
    }
    
apct.Rewind();

    
PrintToServer("%s %i"tagplayer_points);


__________________
Do not Private Message @me
Bacardi 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 22:44.


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