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_SM, kv_file, PLATFORM_MAX_PATH, APCT_File);
if(!FileToKeyValues(kv, kv_file))
SetFailState("[APCT] Failed to load 'APCT'!");
KvRewind(kv);
BrowseKeyValues(kv, client);
return Plugin_Continue;
}
stock void BrowseKeyValues(KeyValues kv, int client)
{
do
{
// You can read the section/key name by using KvGetSectionName here.
char kv_section_name[32];
KvGetSectionName(kv, kv_section_name, sizeof(kv_section_name));
int kv_section_id = StringToInt(kv_section_name);
if (kv.GotoFirstSubKey(false))
{
// Current key is a section. Browse it recursively.
BrowseKeyValues(kv, client);
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(kv, NULL_STRING, kv_snames[kv_section_id], sizeof(kv_snames));
char Tag[32];
Format(Tag, sizeof(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?