This is continue of that KeyValue thing.
If your rank system is same as in previous topic
How to loop steamid while using keyvalues
PHP Code:
public Action top(int client, int args)
{
kv.Rewind();
// Go to first sub-entry in "Players Information"
if(kv.JumpToKey("Players Information") && kv.GotoFirstSubKey())
{
int count;
// Make first loop, count sub-entries
//char section[30];
do
{
//kv.GetSectionName(section, sizeof(section));
//PrintToServer("section %s", section);
count++;
}
while(kv.GotoNextKey(true))
// after loop, remember change position, GoBack()
kv.GoBack();
// we have sub-entries
if(count)
{
//PrintToServer("count %i", count);
// Dynamic size array, store points and "ID position" of KeyValue section
int[][] array = new int[count][2];
count = 0;
// Make second loop and collect points and Kv ID position
kv.GotoFirstSubKey();
do
{
array[count][0] = kv.GetNum("Total Points", 0);
kv.GetSectionSymbol(array[count][1]);
PrintToServer("points %i ID %i", array[count][0], array[count][1]);
count++;
}
while(kv.GotoNextKey())
kv.GoBack();
// Sort 2D array by points
SortCustom2D(array, count, sortfunc2d);
char name[MAX_NAME_LENGTH];
// Loop top-10 results from array
for(int x = 0; x < 10; x++)
{
kv.JumpToKeySymbol(array[x][1]);
name[0] = '\0'; // erase string
kv.GetString("Player Name", name, sizeof(name));
PrintToServer("name %s point %i", name, kv.GetNum("Total Points", 0));
kv.GoBack();
}
}
}
kv.Rewind();
return Plugin_Handled;
}
public int sortfunc2d(int[] elem1, int[] elem2, const int[][] array, Handle hndl)
{
//PrintToServer("elem1 %i elem2 %i", elem1[0], elem2[0]);
//if(elem1[0] < elem2[0])
//{
// return 1;
//}
return elem2[0] - elem1[0]; // I'm not sure is this good way
}
here output
And in
l4d2_rank_system.txt file have data of players scores in KeyValue.
But have to say this is like pain in ass using KeyValues.
One mistake in code can lead easily to data loss.
Another way is using SMC parse to look those KeyValue data from file.
But like @Silvers mentioned already, use SQL. SourceMod local sqlite.
You can expand more features with tables.
But make first simple rank system without Database or else storage save,
use global variable (array) to keep scores update.
- And then, you update scores every round_end into Database or else.
Main idea is handle scores in global variables, it is much faster.