PDA

View Full Version : KeyValues, how I can get current KeyValue key name?


iGANGNAM
07-05-2016, 18:35
"root"
{
"cvars"
{
"status" "success"
"pre-warmup"
{
"sv_disable_show_team_select_menu" "0"
"mp_roundtime" "5.0"
"sv_talk_enemy_living" "1"
"sv_talk_enemy_dead " "1"
}
"post-warmup"
{
"sv_talk_enemy_living" "1"
"sv_talk_enemy_dead " "1"
}
}
}

.........................

kv.GotoFirstSubKey(false);
do {
kv.GetString(NULL_STRING, temp_string2, PLATFORM_MAX_PATH);
kv.GetSectionSymbol(temp_id);
kv.GetNameSymbol(temp_id, temp_string, PLATFORM_MAX_PATH);
#if defined DEBUG
#endif
FindConVar(temp_string);
if (hndl == null) {
LogError("Cvar not found. ID: %d, Cvar: %s", temp_string, temp_string2);
} else {
hndl.SetString(temp_string2, true);
#if defined DEBUG
LogMessage("CVAR: %s %s", temp_string, temp_string2);
#endif
}

} while (kv.GotoNextKey(false));

.............

L 07/05/2016 - 18:25:02: [plugin.smx] Cvar not found. Cvar: 0, Value: 0
L 07/05/2016 - 18:25:02: [plugin.smx] Cvar not found. Cvar: 0, Value: 5.0
L 07/05/2016 - 18:25:02: [plugin.smx] Cvar not found. Cvar: 0, Value: 1
L 07/05/2016 - 18:25:02: [plugin.smx] Cvar not found. Cvar: 0, Value: 1

Powerlord
07-05-2016, 18:41
kv.GetSectionName (https://sm.alliedmods.net/new-api/keyvalues/KeyValues/GetSectionName) should give you the key name.

I know that's confusing as you'd think it would give you the name of the section the current keyvalue is in.

iGANGNAM
07-05-2016, 18:43
kv.GetSectionName (https://sm.alliedmods.net/new-api/keyvalues/KeyValues/GetSectionName) should give you the key name.

I know that's confusing as you'd think it would give you the name of the section the current keyvalue is in.

I remember it came out with random numbers :D but I guess I can try it again.

iGANGNAM
07-05-2016, 18:47
Yeah It's like I said

L 07/05/2016 - 18:47:09: [plugin.smx] Cvar not found. Cvar Name: 1918857325, Cvar Value: 5.0
L 07/05/2016 - 18:47:09: [plugin.smx] Cvar not found. Cvar Name: 1952413299, Cvar Value: 1
L 07/05/2016 - 18:47:09: [plugin.smx] Cvar not found. Cvar Name: 1952413299, Cvar Value: 1
L 07/05/2016 - 18:47:09: [plugin.smx] Cvar not found. Cvar Name: 1683977843, Cvar Value: 0

Fyren
07-05-2016, 19:11
Yeah It's like I said

L 07/05/2016 - 18:47:09: [plugin.smx] Cvar not found. Cvar Name: 1918857325, Cvar Value: 5.0
L 07/05/2016 - 18:47:09: [plugin.smx] Cvar not found. Cvar Name: 1952413299, Cvar Value: 1
L 07/05/2016 - 18:47:09: [plugin.smx] Cvar not found. Cvar Name: 1952413299, Cvar Value: 1
L 07/05/2016 - 18:47:09: [plugin.smx] Cvar not found. Cvar Name: 1683977843, Cvar Value: 0


This is because you're doing:


LogError("Cvar not found. ID: %d, Cvar: %s", temp_string, temp_string2);


1918857325 == 0x725F706D

Reverse the bytes in the hex to get 0x6D705F72. As ASCII, "mp_r", or the first four bytes of your string. Because you're printing it as an integer.

iGANGNAM
07-05-2016, 19:15
This is because you're doing:


LogError("Cvar not found. ID: %d, Cvar: %s", temp_string, temp_string2);


1918857325 == 0x725F706D

Reverse the bytes in the hex to get 0x6D705F72. As ASCII, "mp_r", or the first four bytes of your string. Because you're printing it as an integer.

Thank you for noticing, now I fixed all issues :)