Raised This Month: $51 Target: $400
 12% 

Solved KeyValues - How to enter the keys to the menu?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fastmancz
Senior Member
Join Date: Jul 2013
Location: Czech Republic
Old 06-29-2018 , 17:57   KeyValues - How to enter the keys to the menu?
Reply With Quote #1

Hello,

Can you tell me, somebody, how do I enter "key" values into the menu?

KeyValues:
PHP Code:
"extra"
{
    
"STEAM_1:1:1234567"
    
{
        
"a"        "0"
        "b"        "1"
        "c"        "0"
        "d"        "1"
        
...
    }

Menu:
PHP Code:
public MenuCallBack(Handle menuhandleMenuAction actionClientPosition)
{
    if(
action == MenuAction_Select && IsPlayerAlive(Client))
    {
        
char Item[20];
        
GetMenuItem(menuhandlePositionItemsizeof(Item));

        if(
StrEqual(Item"extra"))
        {
            
Handle extra CreateMenu(MenuExtraCallBack);
            
SetMenuTitle(extra"Choose your key section");

            
KeyValues kv = new KeyValues("extra");
            
char sPath[PLATFORM_MAX_PATH];
            
BuildPath(Path_SMsPathsizeof(sPath), "configs/extra.txt");
            
kv.ImportFromFile(sPath);

            
char steamid[64];
            
GetClientAuthId(ClientAuthId_Enginesteamidsizeof(steamid));

            
kv.JumpToKey(steamid);
            
char buffer[2][255]; // 0 - key, 1 - value
            
do
            {
                
kv.GetString(NULL_STRINGbuffer[0], sizeof(buffer[])); // key name
                
kv.GetString(NULL_STRINGbuffer[1], sizeof(buffer[])); // value

                
if(StrEqual(buffer[1], "0"false)) continue; // skip "0" values and sub sections

                
PrintToServer("key %s value %s"buffer[0], buffer[1]);
                
AddMenuItem(extrabuffer[0], buffer[0]);   
            }
            while(
kv.GotoNextKey(false))
            
delete kv;  
        }
    }

Thank you all for the answer.
__________________


Main owner of the CMGPORTAL.CZ.
---------------------------------------
My plugins:
[CS:GO] Panorama - Timeleft
[CS:GO] JailBreak - Be quiet, please!

Last edited by Fastmancz; 06-30-2018 at 05:42.
Fastmancz is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 06-30-2018 , 03:21   Re: KeyValues - How to enter the keys to the menu?
Reply With Quote #2

I'm not sure what exactly you're asking for.

1. Are you asking how to enter the Key names into a menu?

2. Or are you asking how to enter the Values of keys into a menu?

If #2, this is how:

PHP Code:
char g_sGlobalString[32];

void vKeyValuesConfig()
{
    
// Create KeyValues here.
    
kv.GetString("Key"g_sGlobalStringsizeof(g_sGlobalString), "");
}

void vMenu(int client)
{
    
// Create menu here.
    
menu.AddItem(g_sGlobalStringg_sGlobalString);
    
menu.Display(clientMENU_TIME_FOREVER);
}

public 
int iMenuHandler(Menu menuMenuAction actionint param1int param2)
{
    
// Create menu handler here.
    
switch (action)
    {
        case 
MenuAction_Select:
        {
            
char sInfo[32];
            
menu.GetItem(param2sInfosizeof(sInfo));
            if (
strcmp(sInfog_sGlobalString) == 0)
            {
                
// Do stuff here.
            
}
        }
    }

__________________

Last edited by Psyk0tik; 06-30-2018 at 03:21.
Psyk0tik is offline
Fastmancz
Senior Member
Join Date: Jul 2013
Location: Czech Republic
Old 06-30-2018 , 05:41   Re: KeyValues - How to enter the keys to the menu?
Reply With Quote #3

Thanks for your help. I finally did it like this.

PHP Code:
char extra_bonus[][] =
{
    
"a",
    
"b",
    
"c",
    
"d"
};

if(
StrEqual(Item"extra"))
{
    
char string[128];

    
Handle extra CreateMenu(MenuExtraCallBack);
    
SetMenuTitle(extra"Choose your key section");

    
KeyValues kv = new KeyValues("extra");
    
char sPath[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMsPathsizeof(sPath), "configs/extra.txt");
    
kv.ImportFromFile(sPath);

    
char steamid[64];
    
GetClientAuthId(ClientAuthId_Enginesteamidsizeof(steamid));
    
kv.JumpToKey(steamid);
    
char buffer[1][255]; // 0 - key, 1 - value
    
    
int count 3;
    for (
int i 0<= counti++)
    {
        
strcopy(string127extra_bonus[i][0]);
        
kv.GetString(stringbuffer[0], sizeof(buffer[]));

        if(
StrEqual(buffer[0], "0"false)) continue; // skip empty values and sub sections

         
PrintToServer("key %s value %s"stringbuffer[0]);
        
AddMenuItem(extrastringstring);   
    }
    
delete kv;
    
SetMenuPagination(extra7);
    
SetMenuExitButton(extratrue);
    
DisplayMenu(extraClient250);

__________________


Main owner of the CMGPORTAL.CZ.
---------------------------------------
My plugins:
[CS:GO] Panorama - Timeleft
[CS:GO] JailBreak - Be quiet, please!

Last edited by Fastmancz; 06-30-2018 at 05:44.
Fastmancz is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:28.


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