Raised This Month: $12 Target: $400
 3% 

Help by example how to create a multi-stage menu?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hennesy
Member
Join Date: Nov 2018
Location: Czech Republic
Old 05-03-2019 , 15:54   Help by example how to create a multi-stage menu?
Reply With Quote #1

Help by example how to create a multi-stage menu?
1. Player selection
2. The choice of parameters
And get all that is selected in the public and work with the data you chose? (I haven't found examples anywhere)

Помогите примером как создать многоэтапное меню?
1. Выбор игрока
2. Выбор параметров
И получить все что выбрано в паблик и работать с данными которые выбрал? (нигде примеров не нашел)
Hennesy is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 05-03-2019 , 16:07   Re: Help by example how to create a multi-stage menu?
Reply With Quote #2

What do you mean "get all that is selected in the public"?

Что значит "получить всё, что выбрано в паблик"?
__________________

Last edited by impossible_cc; 05-03-2019 at 16:08.
impossible_cc is offline
Hennesy
Member
Join Date: Nov 2018
Location: Czech Republic
Old 05-03-2019 , 16:22   Re: Help by example how to create a multi-stage menu?
Reply With Quote #3

Quote:
Originally Posted by impossible_cc View Post
what do you mean "get all that is selected in the public"?

Что значит "получить всё, что выбрано в паблик"?
получить что выбрано в первом меню и отправить во второе и в обработчики второго меню работать с полученым результатом первого и второго
Hennesy is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 05-03-2019 , 16:25   Re: Help by example how to create a multi-stage menu?
Reply With Quote #4

Not tested, probably there is better way to do it

Может можно и по-другому, я вижу это так. Могу написать что-то подробнее если нужно.

PHP Code:
#include <sourcemod>

int g_iChoosenInMenu[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_menu"Cmd_menu);
}

public 
Action Cmd_menu(int clientint args)
{
    
FormMainMenu(client);
    
    return 
Plugin_Handled;
}

void FormMainMenu(int client)        //main menu
{
    if(
ValidPlayer(client))
    {
        
Menu menu = new Menu(gChooseMainMenu);
        
menu.SetTitle("Choose player:");
        
        for(
int i 1i<=MaxClients; ++i)
        {
            if(
ValidPlayer(i))
            {
                
char str_i[3];
                
IntToString(istr_isizeof(str_i));
                
                
char name[64];
                
GetClientName(inamesizeof(name));
                
                
menu.AddItem(str_inameITEMDRAW_DEFAULT);
            }
        }
        
        
menu.ExitButton true;
        
menu.Display(client0);
    }
}

public 
int gChooseMainMenu(Menu menuMenuAction actionint clientint param2//Main menu handler
{
    switch(
action)
    {
        case 
MenuAction_Select:
        {
            
char choosenClient[3];
            
menu.GetItem(param2choosenClientsizeof(choosenClient));
            
            
int target StringToInt(choosenClient);
            if(
ValidPlayer(target)) 
            {
//if target is valid -> go for second menu
                
FormParamMenu(clienttarget);
            }
            else
            {
//else back to the first menu
                
FormMainMenu(client);
            }
        }
        case 
MenuAction_End:
        {
            
delete menu;
        }
    }
}

void FormParamMenu(int clientint target)
{
//remember target index
    
g_iChoosenInMenu[client] = target;
    
    
    
Menu menu = new Menu(gChoosenParamMenu);
    
    
menu.SetTitle("Choose option:");
    
    
    
//Your own logic here
    //menu.AddItem(...);
    
    
menu.ExitButton true;
    
menu.Display(client0);    
    
}

public 
int gChoosenParamMenu(Menu menuMenuAction actionint clientint param2//second menu handler
{
    switch(
action)
    {
        case 
MenuAction_Select:
        {
            if(
ValidPlayer(client))
            {
                if(
ValidPlayer(g_iChoosenInMenu[client]))
                {
                    
char info[32];
                    
menu.GetItem(param2infosizeof(info));
                
                    if(
StrEqual(info/*your logic*/))
                    {
                        
                        
//do something
                        
int target g_iChoosenInMenu[client]; //target - результат выбора первого меню. info - результат выбора второго меню

                    
}
                    
//...
                
}
                else
                {
                    
//Choosen target is not valid anymore
                    
FormMainMenu(client);
                }
            }
        }
        case 
MenuAction_End:
        {
            
delete menu;
        }
    }
}

stock bool ValidPlayer(int clientbool check_alive false)
{
    return 
client>&& client<=MaxClients && IsClientConnected(client) && IsClientInGame(client) && (!check_alive || IsPlayerAlive(client));

__________________

Last edited by impossible_cc; 05-03-2019 at 16:29.
impossible_cc is offline
Hennesy
Member
Join Date: Nov 2018
Location: Czech Republic
Old 05-03-2019 , 16:32   Re: Help by example how to create a multi-stage menu?
Reply With Quote #5

Quote:
Originally Posted by impossible_cc View Post
Not tested, probably there is better way to do it

Может можно и по-другому, я вижу это так. Могу написать что-то подробнее если нужно.

PHP Code:
#include <sourcemod>

int g_iChoosenInMenu[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_menu"Cmd_menu);
}

public 
Action Cmd_menu(int clientint args)
{
    
FormMainMenu(client);
    
    return 
Plugin_Handled;
}

void FormMainMenu(int client)        //main menu
{
    if(
ValidPlayer(client))
    {
        
Menu menu = new Menu(gChooseMainMenu);
        
menu.SetTitle("Choose player:");
        
        for(
int i 1i<=MaxClients; ++i)
        {
            if(
ValidPlayer(i))
            {
                
char str_i[3];
                
IntToString(istr_isizeof(str_i));
                
                
char name[64];
                
GetClientName(inamesizeof(name));
                
                
menu.AddItem(str_inameITEMDRAW_DEFAULT);
            }
        }
        
        
menu.ExitButton true;
        
menu.Display(client0);
    }
}

public 
int gChooseMainMenu(Menu menuMenuAction actionint clientint param2)
{
    switch(
action)
    {
        case 
MenuAction_Select:
        {
            
char choosenClient[3];
            
menu.GetItem(param2choosenClientsizeof(choosenClient));
            
            
int target StringToInt(choosenClient);
            if(
ValidPlayer(target))
            {
                
FormParamMenu(clienttarget);
            }
            else
            {
                
FormMainMenu(client);
            }
        }
        case 
MenuAction_End:
        {
            
delete menu;
        }
    }
}

void FormParamMenu(int clientint target)
{
    
g_iChoosenInMenu[client] = target;
    
    
    
Menu menu = new Menu(gChoosenParamMenu);
    
    
menu.SetTitle("Choose option:");
    
    
    
//Your own logic here
    //menu.AddItem(...);
    
    
menu.ExitButton true;
    
menu.Display(client0);    
    
}

public 
int gChoosenParamMenu(Menu menuMenuAction actionint clientint param2)
{
    switch(
action)
    {
        case 
MenuAction_Select:
        {
            if(
ValidPlayer(client))
            {
                if(
ValidPlayer(g_iChoosenInMenu[client]))
                {
                    
char info[32];
                    
menu.GetItem(param2infosizeof(info));
                    
                    if(
StrEqual(info/*your logic*/))
                    {
                        
                        
//do something
                        
                    
}
                    
//...
                
}
                else
                {
                    
//Choosen target is not valid anymore
                    
FormMainMenu(client);
                }
            }
        }
        case 
MenuAction_End:
        {
            
delete menu;
        }
    }
}

stock bool ValidPlayer(int clientbool check_alive false)
{
    return 
client>&& client<=MaxClients && IsClientConnected(client) && IsClientInGame(client) && (!check_alive || IsPlayerAlive(client));


Thanks for the response!
I tried to sign now.
I write! Menu
I get a list of players.
The player chooses and opens the second menu.
menu.AddItem ("0", "Null");
menu.AddItem ("1", "One");
I want to get a userid and value two menu

Спасибо за отклик!
Я попробую сейчас расписать что именно мне нужно.
Я пишу !menu
Мне выдает список игроков.
Я выбираю игрока и открывает второе меню с моими параметрами допустим
menu.AddItem("0", "Null");
menu.AddItem("1", "One");
дальше я хочу получить userid игрока которого выбрал в первом меню и value из второго

Last edited by Hennesy; 05-03-2019 at 16:37.
Hennesy is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 05-03-2019 , 16:43   Re: Help by example how to create a multi-stage menu?
Reply With Quote #6

PHP Code:
#include <sourcemod>

int g_iChoosenInMenu[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_menu"Cmd_menu);
}

public 
Action Cmd_menu(int clientint args)
{
    
FormMainMenu(client);
    
    return 
Plugin_Handled;
}

void FormMainMenu(int client)        //main menu
{
    if(
ValidPlayer(client))
    {
        
Menu menu = new Menu(gChooseMainMenu);
        
menu.SetTitle("Choose player:");
        
        for(
int i 1i<=MaxClients; ++i)
        {
            if(
ValidPlayer(i))
            {
                
char str_i[3];
                
IntToString(istr_isizeof(str_i));
                
                
char name[64];
                
GetClientName(inamesizeof(name));
                
                
menu.AddItem(str_inameITEMDRAW_DEFAULT);
            }
        }
        
        
menu.ExitButton true;
        
menu.Display(client0);
    }
}

public 
int gChooseMainMenu(Menu menuMenuAction actionint clientint param2)
{
    switch(
action)
    {
        case 
MenuAction_Select:
        {
            
char choosenClient[3];
            
menu.GetItem(param2choosenClientsizeof(choosenClient));
            
            
int target StringToInt(choosenClient);
            if(
ValidPlayer(target))
            {
                
FormParamMenu(clienttarget);
            }
            else
            {
                
FormMainMenu(client);
            }
        }
        case 
MenuAction_End:
        {
            
delete menu;
        }
    }
}

void FormParamMenu(int clientint target)
{
    
g_iChoosenInMenu[client] = target;
    
    
    
Menu menu = new Menu(gChoosenParamMenu);
    
    
menu.SetTitle("Choose option:");
    
    
menu.AddItem("0""Null");
    
menu.AddItem("1""One");
    
    
menu.ExitButton true;
    
menu.Display(client0);    
    
}

public 
int gChoosenParamMenu(Menu menuMenuAction actionint clientint param2)
{
    switch(
action)
    {
        case 
MenuAction_Select:
        {
            if(
ValidPlayer(client))
            {
                
int target g_iChoosenInMenu[client];
                
                if(
ValidPlayer(target))
                {
                    
int userid GetClientUserId(target);
                    
                    
char info[32];
                    
menu.GetItem(param2infosizeof(info));
                    
                    if(
StrEqual(info"0"))
                    {
                        
// You choosed 0.
                        // В первом меню выбран игрок target, во втором меню выбран ноль
                        
                        
PrintToChat(client"You have choosen player (userid): %i, param: 0"userid);        
                        
//Просто для примера вывожу в чат игроку, который вызывал меню, userid выбранного игрока и параметр из второго меню
                    
}
                    
                    if(
StrEqual(info"1"))
                    {
                        
// You choosed 1
                        // В первом меню выбран игрок target, во втором меню выбрана единица
                        
                        
PrintToChat(client"You have choosen player (userid): %i, param: 1"userid);
                        
//Просто для примера вывожу в чат игроку, который вызывал меню, userid выбранного игрока и параметр из второго меню
                    
}
                }
                else
                {
                    
//Choosen target is not valid anymore
                    
FormMainMenu(client);
                }
            }
        }
        case 
MenuAction_End:
        {
            
delete menu;
        }
    }
}

stock bool ValidPlayer(int clientbool check_alive false)
{
    return 
client>&& client<=MaxClients && IsClientConnected(client) && IsClientInGame(client) && (!check_alive || IsPlayerAlive(client));

__________________
impossible_cc is offline
Reply


Thread Tools
Display Modes

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 04:21.


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