Here is what I have to do:
I have a files full of skills like this:
Code:
"Skills"
{
"1"
{
"name" "Sprint"
"type" "Passive"
"skill" "sprint"
"levels" "7"
"level1" "5"
"level2" "10"
"level3" "10"
"level4" "15"
"level5" "20"
"level6" "20"
"level7" "30"
}
"2"
{
"name" "HealthRegeneration"
"type" "Active"
"skill" "hregen"
"levels" "7"
"level1" "1"
"level2" "2"
"level3" "3"
"level4" "3"
"level5" "4"
"level6" "4"
"level7" "5"
}
"...id..."
{
"name" "...name..."
"type" "...type..."
"skill" "...skill..."
"levels" "...levels..."
"level1" "..."
"level..." "..."
}
}
I want to read all skills from the file above, sort them (A->Z) and save to another file like this:
Code:
"Skill_Data"
{
"HealthRegeneration"
{
"id" "2"
}
"Sprint"
{
"id" "1"
}
"...name..."
{
"id" "...id..."
}
}
Then I will read this file again and make menus. To prevent duplicate entries I always have to delete contents of the "Skill_Data" before writing to it.
I made this, but I can't compile it:
Code:
stock ScanSkills()
{
//
kv= CreateKeyValues("Skills");
//
BuildPath(Path_SM, kv_file, PLATFORM_MAX_PATH, "configs/plugin.heroessource.skills.txt");
//Get KV's
if(!FileToKeyValues(kv,kv_file))
SetFailState("[Heroes: Source]Failed to load 'Skills'!");
//Rewind to top
KvRewind(kv);
//
if(!KvGotoFirstSubKey(kv))
return -1;
//
new skillcount=0;
new skillid;
decl String:s_skillid[32];
//
do
{
//
KvGetSectionName(kv, s_skillid, sizeof(s_skillid));
skillid=StringToInt(s_skillid);
//
KvGetString(kv, "name", skillnames[skillid], sizeof(skillnames));
//
skillcount++;
}
while(KvGotoNextKey(kv))
//
CloseHandle(kv);
//
kv= CreateKeyValues("Skill_Data");
//
BuildPath(Path_SM, kv_file, PLATFORM_MAX_PATH, "data/plugin.heroessource.skilldata.txt");
//Get KV's
if(!FileToKeyValues(kv,kv_file))
SetFailState("[Heroes: Source]Failed to load 'Skill_Data'!");
//Rewind to top
KvRewind(kv);
//
if(!KvGotoFirstSubKey(kv))
return -2;
//Delete all sections
for(;;)
{
decl String:name[4];
KvGetString(kv, name, sizeof(name));
if(name[0]=='\0')
{
if(KvDeleteThis(kv)<1)
{
break;
}
}
else if(!KvGotoNextKey(kv))
{
break;
}
}
//Rewind to top
KvRewind(kv);
//
for(new i=1; i<=skillcount; i++)
{
KvJumpToKey(kv, skillnames[i], true);
KvSetNum(kv, "id", i);
KvGoBack(kv);
}
//
KeyValuesToFile(kv, kv_file);
//
CloseHandle(kv);
return true;
}
I got the "Full Deletion" and "Iterative Lookup" codes from "KeyValues (SourceMod Scripting)" article in the wiki.
Thank you for your posts.
__________________