Raised This Month: $32 Target: $400
 8% 

KeyValues to menu writing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 01-18-2020 , 10:54   KeyValues to menu writing
Reply With Quote #1

Hey!

I tried to get values from the kv file and add them as item in menu but didn't work!

I have this code:
PHP Code:
bool g_isPlayerOn[MAXPLAYERS 1];

char clientSound[512];

char file[512];

...

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_music"Command_Music);
    
RegConsoleCmd("sm_stop"Command_Stop);
    
    
BuildPath(Path_SMfilesizeof(file), "configs/musics.txt");
}

public 
Action Command_Music(int clientint args)
{
    
musicsMenu().Display(clientMENU_TIME_FOREVER);
    return 
Plugin_Handled;
}

Menu musicsMenu()
{
    
Menu menu = new Menu(MusicHandleMENU_ACTIONS_ALL);
    
menu.SetTitle("Choose a type of song:");
    
    
KeyValues kv = new KeyValues("Musics");
    
kv.ImportFromFile(file);
    
    
char SongNumber[32];
    
char SongName[128];
    
    do
    {
        
KvGetSectionName(kvSongNumbersizeof(SongNumber));
        
KvGetString(kv"name"SongNamesizeof(SongName));
        
        
//Add all songs to the menu
        
menu.AddItem(SongNumberSongName);
    } while (
KvGotoNextKey(kv));
    
    
delete kv;
    
menu.ExitButton true;
    
menu.ExitBackButton true;
    
    return 
menu;
}

public 
int MusicHandle(Menu menuMenuAction actionint clientint item)
{
    if(
action == MenuAction_Select)
    {
        if(
g_isPlayerOn[client])
        {
            
PrintToChat(client"[SpirT] Tens de parar a música primeiro usando o !stop");
        }
        
        
char choice[32];
        
char buffer[32];
        
        
KeyValues kv = new KeyValues("Musics");
        
kv.ImportFromFile(file);
        
        if(!
KvGotoFirstSubKey(kv))
        {
            
delete menu;
        }
        
        
menu.GetItem(itemchoicesizeof(choice));
        
        do
        {
            
KvGetSectionName(kvbuffersizeof(buffer));
            
            if(
StrEqual(choicebuffer))    
            {    
                
char soundPath[512];
                
KvGetString(kv"file"soundPathsizeof(soundPath));
                
EmitSoundToClient(clientsoundPath);
                
soundPath clientSound;
                
g_isPlayerOn[client] = true;
            }    
        } while (
KvGotoNextKey(kv));
    }
}

public 
Action Command_Stop(int clientint args)
{
    if(!
g_isPlayerOn[client])
    {
        
PrintToChat(client"[SpirT] Nenhuma música está a tocar!");
        return 
Plugin_Handled;
    }
    
    
StopSound(clientSNDCHAN_AUTOclientSound);
    
g_isPlayerOn[client] = false;
    return 
Plugin_Handled;

Now the data on the file (musics.txt):
Code:
"Musics"
{
	"1"
	{
		"name" "PRIMEIRA"
	}
	"2"
	{
		"name" "SEGUNDA"
	}
}
What can I do to solve my problem?

Best Regards,

SpirT.
__________________

Last edited by SpirT; 01-18-2020 at 14:11. Reason: Keep going...
SpirT is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 01-18-2020 , 11:03   Re: KeyValues to menu writing
Reply With Quote #2

In "musicsMenu" missing "KvGotoFirstSubKey" before "do".
__________________
Silvers is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 01-18-2020 , 13:55   Re: KeyValues to menu writing
Reply With Quote #3

Quote:
Originally Posted by Silvers View Post
In "musicsMenu" missing "KvGotoFirstSubKey" before "do".
Thanks man. Apreciate that! It worked
__________________
SpirT is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 01-18-2020 , 14:14   Re: KeyValues to menu writing
Reply With Quote #4

Quote:
Originally Posted by Silvers View Post
In "musicsMenu" missing "KvGotoFirstSubKey" before "do".
What about if I click on the item of the menu and it will create another menu with the items on the other key?

Can you show me?

Example of the file (musics.txt):
Code:
"Musics"
{
	"Item1" //By clicking here I want to create a menu with items of the keys inside this key (sorry for my english :D)
	{
		"Item1.1"
		{
			"path"	"the/path/of/the/file.mp3"
		}
	}
}
__________________
SpirT is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 06-06-2020 , 10:47   Re: KeyValues to menu writing
Reply With Quote #5

Quote:
Originally Posted by willdean View Post
You've seen some answers in this thread. Do you still need help with your code?
Hey! Yes, I still need help. Didn't figure out any fix for this. Do you have any solution?
__________________
SpirT 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 02:19.


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