AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [menu]need help with custom menu (https://forums.alliedmods.net/showthread.php?t=88468)

limeassist 03-25-2009 08:02

[menu]need help with custom menu
 
Greetings to all coders. I need help with some basic scripting.

I Have a plugin that has two console commands:

- record POV demo of a player

- makes a player take a snapshot.


I would like to integrate them into an admin menu

for example, if admin types in console :
Quote:

"pov_menu":


1-8 - player name (upon pressing it will perform the POVdemo onthat player)


9 -next page

0 - exit

Same for snapshot function : snap_menu.


Any help will be appreciated.

SonicSonedit 03-25-2009 08:20

Re: [menu]need help with custom menu
 
1) create new menu
PHP Code:

new playerlistmenu menu_create("Player list","playerlistmenu_handle"

2) add menu items (players)
PHP Code:

for (new 1i<g_maxplayersi++)
    if (
is_user_alive(i))
        
menu_additem(playerlistmenuget_user_name(i), num_to_str(i)); 

3) show menu
PHP Code:

menu_display(idplayerlistmenu0); 

Now, when player chooses any item (except for next/previous and exit) playerlistmenu_handle will be called. so:

PHP Code:

public playerlistmenu_handle(idmenuitem)
{
    
menu_destroy(playerlistmenu); //destroy old menu
    
new cmd[32]; 
    new 
accesscallback//tempvar, unused
    
menu_item_getinfo(menuitemaccesscmd,2,_,_callback); //put selected player id in cmd
    
new selectedplayerid str_to_num(cmd);
    
    if (!
is_user_alive(selectedplayerid)) return PLUGIN_HANDLED;
    
    
//do whatever now


Not tested, but should work.

limeassist 03-25-2009 09:49

Re: [menu]need help with custom menu
 
how do i call such menu from console?

And what functions should i declare :


Code:

new snapmenu = menu_create("Snapshot player:","snap_handle") 

for (new i = 1; i <= g_players; i++)
    if (is_user_alive(i))
        menu_additem(snapmenu, get_user_name(i), num_to_str(i)); 
        menu_display(id, snapmenu, 0); 
   
   

public snap_handle(id, menu, item, level, cid)
{
    menu_destroy(playerlistmenu); //destroy old menu
    new cmd[32];
    new access, callback; //tempvar, unused
    menu_item_getinfo(menu, item, access, cmd,2,_,_, callback); //put selected player id in cmd
    new selectedplayerid = str_to_num(cmd);
   
    if (!is_user_alive(selectedplayerid)) return PLUGIN_HANDLED;
   
    playerss(id, level, cid);
   
    return PLUGIN_HANDLED;
}


SonicSonedit 03-25-2009 10:08

Re: [menu]need help with custom menu
 
here is example
PHP Code:

new const ACCESS_FLAG ADMIN_BAN//level of access needed to use command
new g_players//amount of player slots on your server

public plugin_init() 
{
    
//blablalbla
    
    
g_players get_maxplayers()

    
register_clcmd("admin_snapshot_menu""clcmd_admin_snapshot_menu"ACCESS_FLAG//register client command
    
}

public 
clcmd_admin_snapshot_menu(id)
{
    new 
snapmenu menu_create("Snapshot player:","snap_handle")  

    for (new 
1<= g_playersi++)
        if (
is_user_alive(i))
            
menu_additem(snapmenuget_user_name(i), num_to_str(i));  
            
    
menu_display(idsnapmenu0);  

}

public 
snap_handle(idmenuitemlevelcid)
{
    
menu_destroy(playerlistmenu); //destroy old menu
    
new cmd[32]; 
    new 
accesscallback//tempvar, unused
    
menu_item_getinfo(menuitemaccesscmd,2,_,_callback); //put selected player id in cmd
    
new selectedplayerid str_to_num(cmd);
    
    if (!
is_user_alive(selectedplayerid)) return PLUGIN_HANDLED;
    
    
playerss(idlevelcid);
    
    return 
PLUGIN_HANDLED;


now, when "admin_snapshot_menu" typed in console, public clcmd_admin_snapshot_menu(id) is called.
btw, use [php] instead of [code] tag

SnoW 03-25-2009 10:38

Re: [menu]need help with custom menu
 
@SonicSonedit
- Use get_players instead(with alive flag)
- You don't need to set the infos and get them, just use the item parameter what's automatically passed to the function
- The admin acces isn't send, cause there isn't places for it in the first function, also you don't pass it to the second either(It's not even possible to, when displaying the menu)

limeassist 03-25-2009 10:39

Re: [menu]need help with custom menu
 
thnx for helping me out.

i got 1 error during compilation:

PHP Code:


public clcmd_admin_snapshot_menu(id)
{
   new 
snapmenu menu_create("Snapshot player:","snap_handle")  

   for (new 
1<= g_playersi++)
        if (
is_user_connected(i))
            
menu_additem(snapmenuget_user_name(i), num_to_str(i));  
            
    
menu_display(idsnapmenu0);  




This line:

PHP Code:

           menu_additem(snapmenuget_user_name(i), num_to_str(i)); 

It says :

Error: Number of arguments does not match definition

where the problemmight be?

SnoW 03-25-2009 10:52

Re: [menu]need help with custom menu
 
It's because num_to_str can't be used like that. Basically something like this:

Code:

new string[1];
num_to_str(i, string, 0);
menu_additem(snapmenu, get_user_name(i), string);


limeassist 03-25-2009 11:04

Re: [menu]need help with custom menu
 
PHP Code:

public clcmd_admin_snapshot_menu(id)
{
   new 
snapmenu menu_create("Snapshot player:","snap_handle")  
   new 
string[1];
   
   for (new 
1<= g_playersi++)
    
    if (
is_user_connected(i))
    {
 
            
num_to_str(istring0);
            
menu_additem(snapmenuget_user_name(i), string);  
          }
    
menu_display(idsnapmenu0);  
    
    return 
PLUGIN_HANDLED;



1. Same error on the same line...

2. Is return PLUGIN_HANDLED; required here?

SnoW 03-25-2009 11:13

Re: [menu]need help with custom menu
 
It's because get_user_name can't be used like that. Basically something like this:
Code:

new name[33];
get_user_name(id, name, 32);
menu_additem(snapmenu, name, string);

Déjá vu? :mrgreen:

Edit:
Quote:

Originally Posted by limeassist (Post 788739)
2. Is return PLUGIN_HANDLED; required here?

If it's not there, there can come some problems if exit item was taken, so better to leave it.

SonicSonedit 03-25-2009 11:20

Re: [menu]need help with custom menu
 
SnoW
That was just an example, i use everything you said in ZP_CS_Buymenu

limeassist
yeah, forgot num_to_str works different in c++ and pawn. this one tested.
PHP Code:

new const ACCESS_FLAG ADMIN_BAN//level of access needed to use command
new g_players//amount of player slots on your server

public plugin_init() 
{
    
//blablalbla
    
    
g_players get_maxplayers()

    
register_clcmd("admin_snapshot_menu""clcmd_admin_snapshot_menu"ACCESS_FLAG//register client command
    
}

public 
clcmd_admin_snapshot_menu(id,levelcid)
{
    if (!
cmd_access(idlevelcid2)) return PLUGIN_HANDLED;

    new 
strtemp1[32]
    new 
strtemp2[2]
    new 
snapmenu menu_create("Snapshot player:","snap_handle")  

    for (new 
1<= g_playersi++)
        if (
is_user_alive(i))
    {
        
get_user_name(i,strtemp1,32);
        
num_to_str(i,strtemp2,2);
             
menu_additem(snapmenustrtemp1,strtemp2);
    }
            
    
menu_display(idsnapmenu0);  

}

public 
snap_handle(idmenuitemlevelcid)
{
    new 
cmd[32]; 
    new 
accesscallback//tempvar, unused
    
menu_item_getinfo(menuitemaccesscmd,2,_,_callback); //put selected player id in cmd
    
new selectedplayerid str_to_num(cmd);
    
    if (!
is_user_alive(selectedplayerid)) return PLUGIN_HANDLED;
    
    
playerss(idlevelcid);
    
    return 
PLUGIN_HANDLED;




All times are GMT -4. The time now is 08:54.

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