AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Help by example how to create a multi-stage menu? (https://forums.alliedmods.net/showthread.php?t=316006)

Hennesy 05-03-2019 15:54

Help by example how to create a multi-stage menu?
 
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. Выбор параметров
И получить все что выбрано в паблик и работать с данными которые выбрал? (нигде примеров не нашел)

impossible_cc 05-03-2019 16:07

Re: Help by example how to create a multi-stage menu?
 
What do you mean "get all that is selected in the public"?

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

Hennesy 05-03-2019 16:22

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

Originally Posted by impossible_cc (Post 2650063)
what do you mean "get all that is selected in the public"?

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

получить что выбрано в первом меню и отправить во второе и в обработчики второго меню работать с полученым результатом первого и второго

impossible_cc 05-03-2019 16:25

Re: Help by example how to create a multi-stage menu?
 
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));



Hennesy 05-03-2019 16:32

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

Originally Posted by impossible_cc (Post 2650066)
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 из второго

impossible_cc 05-03-2019 16:43

Re: Help by example how to create a multi-stage menu?
 
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));




All times are GMT -4. The time now is 05:34.

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