View Single Post
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 05-02-2015 , 22:08   Re: Add two KeyValue files together
Reply With Quote #7

All right, so I've taken a little different approach than the one Exolent suggested.

I've created an enum with all the keys of the section including the section name itself and made it into two arrays:

Code:
enum _:KVKeys{     String:s_section[32],     i_score,     i_kills,     i_deaths, }; new array_a[16][KVKeys]; new array_b[16][KVKeys];

Then cached key values from two files I wanted to merge in them:

Code:
static String:KVPathA[PLATFORM_MAX_PATH]; static String:KVPathB[PLATFORM_MAX_PATH]; static String:KVPathC[PLATFORM_MAX_PATH]; public OnPluginStart(){     BuildPath(Path_SM, KVPathA, sizeof(KVPathA), "data/[FILENAME]_a.txt");     BuildPath(Path_SM, KVPathB, sizeof(KVPathB), "data/[FILENAME]_b.txt");     BuildPath(Path_SM, KVPathC, sizeof(KVPathC), "data/[FILENAME]_c.txt"); //'C' will be A and B merged     CacheFileA(); //Caching the A file     CacheFileB(); //Caching the B file     CreateFileC(); //Create the merged file }
CacheFileA()
CacheFileB()


And then created the final file using the two arrays:

CreateFileC()


NOTE: For some reason in the final file the root section is treated like a subsection. Meaning that at some point in the file there will something like:
I haven't looked into on how to fix it as the solution is to simply remove those lines and everything's good to go.

FINAL NOTE: Please don't hate on me for having player stats in a KV file, I'll port them to MySQL once I learn how everything works, I swear.. ;~;

Last edited by Phil25; 05-02-2015 at 22:12.
Phil25 is offline