AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   KeyValues, how I can get current KeyValue key name? (https://forums.alliedmods.net/showthread.php?t=284863)

iGANGNAM 07-05-2016 18:35

KeyValues, how I can get current KeyValue key name?
 
Code:

"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"
                }
        }
}

.........................
Code:

        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));

.............
Code:

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

Re: KeyValues, how I can get current KeyValue key name?
 
kv.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

Re: KeyValues, how I can get current KeyValue key name?
 
Quote:

Originally Posted by Powerlord (Post 2433958)
kv.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

Re: KeyValues, how I can get current KeyValue key name?
 
Yeah It's like I said
Code:

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

Re: KeyValues, how I can get current KeyValue key name?
 
Quote:

Originally Posted by iGANGNAM (Post 2433961)
Yeah It's like I said
Code:

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:

PHP Code:

LogError("Cvar not found. ID: %d, Cvar: %s"temp_stringtemp_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

Re: KeyValues, how I can get current KeyValue key name?
 
Quote:

Originally Posted by Fyren (Post 2433968)
This is because you're doing:

PHP Code:

LogError("Cvar not found. ID: %d, Cvar: %s"temp_stringtemp_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 :)


All times are GMT -4. The time now is 21:55.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.