Raised This Month: $ Target: $400
 0% 

[menu]need help with custom menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
limeassist
Junior Member
Join Date: Dec 2008
Old 03-25-2009 , 08:02   [menu]need help with custom menu
Reply With Quote #1

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.
limeassist is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 03-25-2009 , 08:20   Re: [menu]need help with custom menu
Reply With Quote #2

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.
__________________


Last edited by SonicSonedit; 03-25-2009 at 08:31.
SonicSonedit is offline
limeassist
Junior Member
Join Date: Dec 2008
Old 03-25-2009 , 09:49   Re: [menu]need help with custom menu
Reply With Quote #3

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;
}

Last edited by limeassist; 03-25-2009 at 10:01.
limeassist is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 03-25-2009 , 10:08   Re: [menu]need help with custom menu
Reply With Quote #4

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
__________________


Last edited by SonicSonedit; 03-25-2009 at 10:12.
SonicSonedit is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 03-25-2009 , 10:38   Re: [menu]need help with custom menu
Reply With Quote #5

@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)
SnoW is offline
Send a message via MSN to SnoW
limeassist
Junior Member
Join Date: Dec 2008
Old 03-25-2009 , 10:39   Re: [menu]need help with custom menu
Reply With Quote #6

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?
limeassist is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 03-25-2009 , 10:52   Re: [menu]need help with custom menu
Reply With Quote #7

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);
SnoW is offline
Send a message via MSN to SnoW
limeassist
Junior Member
Join Date: Dec 2008
Old 03-25-2009 , 11:04   Re: [menu]need help with custom menu
Reply With Quote #8

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?
limeassist is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 03-25-2009 , 11:13   Re: [menu]need help with custom menu
Reply With Quote #9

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?

Edit:
Quote:
Originally Posted by limeassist View Post
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.

Last edited by SnoW; 03-25-2009 at 13:06.
SnoW is offline
Send a message via MSN to SnoW
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 03-25-2009 , 11:20   Re: [menu]need help with custom menu
Reply With Quote #10

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;

__________________


Last edited by SonicSonedit; 03-25-2009 at 11:28.
SonicSonedit 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 08:54.


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