Junior Member
|
04-05-2019
, 14:26
Displaying a menu on user's connect
|
#1
|
Hello there!
I require to display a menu when the user connects, I tried two methods, but sadly none of them worked so far
Method one:
Verifying if the user is a bot or not, Then I made a task, and after all of that I wrote menu name on task's public, This method will display the menu on the user's connect, but none of the menu options is functional unless I recall menu using it's clcmd
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>
public plugin_init()
{
register_plugin("Test menu", "1.0", "WHOOHOO");
register_clcmd("say /menu", "Menu", _, "Simple menu");
}
public client_putinserver(id)
{
if (is_user_bot(id))
return
set_task(0.0, "Entermenu", id)
}
public client_disconnect(id)
{
remove_task(id)
}
public Entermenu(id)
{
Menu(id);
}
public Menu(id)
{
new menu = menu_create("Simple menu", "Menu_Handler");
menu_additem(menu, "Option 1", "", 0); // case 0
menu_additem(menu, "Option 2", "", 0); // case 1
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_setprop(menu, MPROP_NOCOLORS, 1);
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public Menu_Handler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_cancel(id);
return PLUGIN_HANDLED;
}
new command[6], name[64], access, callback;
menu_item_getinfo(menu, item, access, command, sizeof command - 1, name, sizeof name - 1, callback);
switch(item)
{
case 0:
{
set_hudmessage(255, 0, 0, -1.0, 0.01)
show_hudmessage(id, "Option 1")
Menu(id);
}
case 1:
{
set_hudmessage(255, 0, 0, -1.0, 0.01)
show_hudmessage(id, "Option 2")
Menu(id);
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
Method two:
I made a Boolean (To keep count of user's first spawn), then I registered a Ham (Ham_Spawn) on the plugin_init, then I made a public and called that Ham and I wrote menu name on task's public, This method won't display menu at all.
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <colorchat>
new bool:firsttime[33]
public plugin_init()
{
register_plugin("Test menu", "1.0", "WHOOHOO");
register_clcmd("say /menu", "Menu", _, "Simple menu");
RegisterHam( Ham_Spawn, "player", "PlayerSpawn")
}
public PlayerSpawn( id )
{
if( !is_user_alive( id ) )
return;
if(firsttime[id])
{
Menu(id);
}
firstspawn[id] = false
}
public Menu(id)
{
new menu = menu_create("Simple menu", "Menu_Handler");
menu_additem(menu, "Option 1", "", 0); // case 0
menu_additem(menu, "Option 2", "", 0); // case 1
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_setprop(menu, MPROP_NOCOLORS, 1);
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public Menu_Handler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_cancel(id);
return PLUGIN_HANDLED;
}
new command[6], name[64], access, callback;
menu_item_getinfo(menu, item, access, command, sizeof command - 1, name, sizeof name - 1, callback);
switch(item)
{
case 0:
{
set_hudmessage(255, 0, 0, -1.0, 0.01)
show_hudmessage(id, "Option 1")
Menu(id);
}
case 1:
{
set_hudmessage(255, 0, 0, -1.0, 0.01)
show_hudmessage(id, "Option 2")
Menu(id);
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
Thanks in advance
Last edited by WHOOHOO; 04-06-2019 at 07:18.
Reason: ITS SOLVED
|
|