i dont think this is how this is supposed to work but
writing stuff to keyvalues file
kv is global variable
.importedfromfile every time it needs to be accessed
making command to rewrite some values
how it should look
Code:
"Data"
{
"Trail Indices"
{
"1" "Generic Laser"
}
"Trail"
{
"Generic Laser"
{
"Material" "materials/sprites/laser.vmt"
}
}
"Hat Indices"
{
"1" "Watermelon"
"2" "TV"
"3" "Cone"
}
"Hats"
{
"Watermelon"
{
"Model" "models/props_junk/watermelon01.mdl"
"Offset" "eyes"
"Scale" "1.0"
}
"TV"
{
"Model" "models/props_c17/tv_monitor01.mdl"
"Offset" "0 0 0"
"Scale" "1.0"
}
"Cone"
{
"Model" "models/props_junk/trafficcone001a.mdl"
"Offset" "0 0 8"
"Scale" "1.0"
}
}
}
what this snippet should be doing is editing a value in the cone section of hats, from 0 0 8 to 0 0 20 (or any string inside hats/trails section)
PHP Code:
public Action Command_EditHatProperty(int client, int args)
{
if(args < 3)
{
CReplyToCommand(client, "{dodgerblue}[RP]{default} Invalid Syntax: sm_edithatproperty <hat> <property> <value>");
return Plugin_Handled;
}
char arg[32]; GetCmdArg(1, arg, sizeof(arg));
g_ConfigKV.ImportFromFile(g_ConfigPath);
g_ConfigKV.JumpToKey("Hats");
//If it failed, the hat doesn't likely exist:
if(!g_ConfigKV.JumpToKey(arg))
{
CReplyToCommand(client, "{dodgerblue}[RP]{default} Invalid Hat: {dodgerblue}%s{default}.", arg);
return Plugin_Handled;
}
char prop[32]; GetCmdArg(2, prop, sizeof(prop));
char nullCheck[16]; g_ConfigKV.GetString(prop, nullCheck, sizeof(nullCheck), "NULL");
//Check if our attribute exists:
if(StrEqual(nullCheck, "NULL", false))
{
CReplyToCommand(client, "{dodgerblue}[RP]{default} Invalid Attribute: {dodgerblue}%s{default}.", prop);
return Plugin_Handled;
}
char val[64]; GetCmdArg(3, val, sizeof(val));
g_ConfigKV.SetString(prop, val);
CReplyToCommand(client, "{dodgerblue}[RP]{default} Set Attribute {dodgerblue}%s{default} of {dodgerblue}%s{default} to: {dodgerblue}%s{default}.", prop, arg, val);
//Save:
g_ConfigKV.Rewind();
g_ConfigKV.ExportToFile(g_ConfigPath);
return Plugin_Handled;
}
what it is doing:
Code:
"data"
{
"Trail Indices"
{
"1" "Generic Laser"
}
"Trail"
{
"Generic Laser"
{
"material" "materials/sprites/laser.vmt"
}
}
"Hat Indices"
{
"1" "Watermelon"
"2" "TV"
"3" "Cone"
}
"Hats"
{
"Watermelon"
{
"model" "models/props_junk/watermelon01.mdl"
"offset" "eyes"
"scale" "1.000000"
}
"TV"
{
"model" "models/props_c17/tv_monitor01.mdl"
"offset" "0 0 0"
"scale" "1.000000"
}
"data"
{
"model" "models/props_junk/trafficcone001a.mdl"
"offset" "0 0 8"
"scale" "1.000000"
"Trail Indices"
{
"1" "Generic Laser"
}
"Trail"
{
"Generic Laser"
{
"material" "materials/sprites/laser.vmt"
}
}
"Hat Indices"
{
"1" "Watermelon"
"2" "TV"
"3" "Cone"
}
"Hats"
{
"Watermelon"
{
"model" "models/props_junk/watermelon01.mdl"
"offset" "eyes"
"scale" "1.000000"
}
"TV"
{
"model" "models/props_c17/tv_monitor01.mdl"
"offset" "0 0 0"
"scale" "1.000000"
}
"Cone"
{
"model" "models/props_junk/trafficcone001a.mdl"
"offset" "0 0 20"
"scale" "1.000000"
}
}
}
}
}
im not going crazy, right? is this just inherently going to happen with a globally created KeyValues object being edited and something not lining up or...?