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_SM, file, sizeof(file), "configs/musics.txt");
}
public Action Command_Music(int client, int args)
{
musicsMenu().Display(client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
Menu musicsMenu()
{
Menu menu = new Menu(MusicHandle, MENU_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(kv, SongNumber, sizeof(SongNumber));
KvGetString(kv, "name", SongName, sizeof(SongName));
//Add all songs to the menu
menu.AddItem(SongNumber, SongName);
} while (KvGotoNextKey(kv));
delete kv;
menu.ExitButton = true;
menu.ExitBackButton = true;
return menu;
}
public int MusicHandle(Menu menu, MenuAction action, int client, int 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(item, choice, sizeof(choice));
do
{
KvGetSectionName(kv, buffer, sizeof(buffer));
if(StrEqual(choice, buffer))
{
char soundPath[512];
KvGetString(kv, "file", soundPath, sizeof(soundPath));
EmitSoundToClient(client, soundPath);
soundPath = clientSound;
g_isPlayerOn[client] = true;
}
} while (KvGotoNextKey(kv));
}
}
public Action Command_Stop(int client, int args)
{
if(!g_isPlayerOn[client])
{
PrintToChat(client, "[SpirT] Nenhuma música está a tocar!");
return Plugin_Handled;
}
StopSound(client, SNDCHAN_AUTO, clientSound);
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.
__________________