I'm trying to create a menu that is displayed when the client connects to the server, he will choose one of the classes that will release things to him.
But I can't in any way pass the "client" to the Menu_callback.
I need it to be done with "OnPlayerSpawn" because the client will only be able to access the menu when entering the server, or after respawning, etc.
(Left 4 dead server)
PHP Code:
public void OnPluginStart()
{
HookEvent("player_spawn", OnPlayerSpawn, EventHookMode_Post);
}
void OnPlayerSpawn(Event e, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(e.GetInt("userid"));
if (client < 1 || !IsClientInGame(client))
{
return;
}
CreateTimer(1.0, ClassMenu, client);
}
public Action ClassMenu(Handle:timer, int client)
{
Menu menu = new Menu(Menu_Callbackbr, client);
menu.SetTitle("select a class");
menu.AddItem("option1", "team red");
menu.AddItem("option2", "team blue");
menu.Display(client, 60);
return Plugin_Handled;
}
public int Menu_Callbackbr(Menu menu, MenuAction action, int param1, int param2)
{
switch (action)
{
case MenuAction_Select:
{
char item[32];
menu.GetItem(param2, item, sizeof(item));
if (StrEqual(item, "option1"))
{
PrintHintText(client, "team red");
SetEntityRenderColor(client, 255, 0, 0, 255);
}
if (StrEqual(item, "option2"))
{
PrintHintText(client, "team blue");
SetEntityRenderColor(client, 0, 0, 255, 255);
}
}
case MenuAction_End:
{
delete menu;
}
}
}