Raised This Month: $32 Target: $400
 8% 

I Need some help with Menus


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ItsWolfPT
Junior Member
Join Date: Jan 2017
Location: Portugal
Old 01-24-2017 , 14:57   I Need some help with Menus
Reply With Quote #1

Hello. I need help for a menu. And I know this following sites:
https://wiki.alliedmods.net/Menu_API_(SourceMod)
https://wiki.alliedmods.net/Menus_St...Mod_Scripting).
And Also Don't tell me to Study other plugins for see how it's done.

So, what I need is a Menu that I can select a option and goes to other page with more other option. Like the Admin Menu. But I don't know how to do it. And I can't really find the code that I need for that. Can Someone help me and tell me how it's done in a simple way to do it.

I am new in Sourcepawn scripting. So yha. I am learning slowly.
ItsWolfPT is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 01-24-2017 , 15:08   Re: I Need some help with Menus
Reply With Quote #2

Create 2 menus and populate them with the items you want and use the callback to open the other menu...?

You should study other plugins to see how it's done. (lol)
Drixevel is offline
ItsWolfPT
Junior Member
Join Date: Jan 2017
Location: Portugal
Old 01-24-2017 , 15:13   Re: I Need some help with Menus
Reply With Quote #3

Quote:
Originally Posted by redwerewolf View Post
Create 2 menus and populate them with the items you want and use the callback to open the other menu...?

You should study other plugins to see how it's done. (lol)
Thx Man. And "You should study other plugins to see how it's done." I already Tried but I can't understand yet what they do. Of Course in mine Test Plugin I understand but in others plugins Damn I can't. But Thx anyway

Last edited by ItsWolfPT; 01-25-2017 at 07:35.
ItsWolfPT is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 01-24-2017 , 15:21   Re: I Need some help with Menus
Reply With Quote #4

Quote:
Originally Posted by ItsWolfPT View Post
Thx Man. And "You should study other plugins to see how it's done." I already Tried but I can't understand yet what they do. Of Course in mine Test Plugin I understand but in other plugins Damn I can't. But Thx anyway
Learning to study other's work is going to benefit you greatly, but regardless here's an excerpt from a plugin I made a while back. If you are struggling to understand something, feel free to ask.

PHP Code:
public void OpenMainMenu(int client

    
Menu MainMenu = new Menu(MainMenu_CallBackMenuAction_Select MenuAction_End);  
    
MainMenu.SetTitle("Main Menu :"); 

    
MainMenu.AddItem("bring""Bring Player(s)"); 
    
MainMenu.AddItem("goto""Go To Player"); 

    
DisplayMenu(MainMenuclientMENU_TIME_FOREVER);  


public 
int MainMenu_CallBack(Menu MainMenuMenuAction actionint param1int param2)  

    switch (
action
    { 
        case 
MenuAction_Select
        { 
            
char item[64]; 
            
GetMenuItem(MainMenuparam2itemsizeof(item)); 

            if (
StrEqual(item"bring")) 
            { 
                
OpenBringMenu(param1); 
            } 
            else if (
StrEqual(item"goto")) 
            { 
                
OpenGoToMenu(param1); 
            } 
        } 
        case 
MenuAction_End
        { 
            
delete MainMenu
        } 
    } 


Last edited by headline; 01-24-2017 at 15:39.
headline is offline
ItsWolfPT
Junior Member
Join Date: Jan 2017
Location: Portugal
Old 01-24-2017 , 15:58   Re: I Need some help with Menus
Reply With Quote #5

Quote:
Originally Posted by Headline View Post
Learning to study other's work is going to benefit you greatly, but regardless here's an excerpt from a plugin I made a while back. If you are struggling to understand something, feel free to ask.

PHP Code:
public void OpenMainMenu(int client

    
Menu MainMenu = new Menu(MainMenu_CallBackMenuAction_Select MenuAction_End);  
    
MainMenu.SetTitle("Main Menu :"); 

    
MainMenu.AddItem("bring""Bring Player(s)"); 
    
MainMenu.AddItem("goto""Go To Player"); 

    
DisplayMenu(MainMenuclientMENU_TIME_FOREVER);  


public 
int MainMenu_CallBack(Menu MainMenuMenuAction actionint param1int param2)  

    switch (
action
    { 
        case 
MenuAction_Select
        { 
            
char item[64]; 
            
GetMenuItem(MainMenuparam2itemsizeof(item)); 

            if (
StrEqual(item"bring")) 
            { 
                
OpenBringMenu(param1); 
            } 
            else if (
StrEqual(item"goto")) 
            { 
                
OpenGoToMenu(param1); 
            } 
        } 
        case 
MenuAction_End
        { 
            
delete MainMenu
        } 
    } 


Okay, Let's see if got it. So it open 1 menu with 2 options(Right?), Then for open those options, I must select Bring or Goto(Right?, Correct me if I am wrong.) And Close When I finish the operation, or Go Back to the main menu. But can you explain what this do? GetMenuItem(MainMenu, param2, item, sizeof(item));
ItsWolfPT is offline
ItsWolfPT
Junior Member
Join Date: Jan 2017
Location: Portugal
Old 01-24-2017 , 16:41   Re: I Need some help with Menus
Reply With Quote #6

@Headline , I am studying your plugin and I am now understanding how you make the menu, It's a sequence of Functions and commands (I guess).

Now I need to know How do I execute a command through the Menu, for example:

Title: Test
1. Command name.
2. Command name.
[...]
8. Back
9. Exit

Like this. But I don't know how to do it. But if anyone can tell me how, it could help. Thx for all the support guys

Last edited by ItsWolfPT; 01-24-2017 at 17:01.
ItsWolfPT is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 01-24-2017 , 17:16   Re: I Need some help with Menus
Reply With Quote #7

Quote:
Originally Posted by ItsWolfPT View Post
@Headline , I am studying your plugin and I am now understanding how you make the menu, It's a sequence of Functions and commands (I guess).

Now I need to know How do I execute a command through the Menu, for example:

Title: Test
1. Command name.
2. Command name.
[...]
8. Back
9. Exit

Like this. But I don't know how to do it. But if anyone can tell me how, it could help. Thx for all the support guys
https://sm.alliedmods.net/new-api/co...eClientCommand
or
https://sm.alliedmods.net/new-api/console/ServerCommand
__________________
coding & free software
shanapu is offline
ItsWolfPT
Junior Member
Join Date: Jan 2017
Location: Portugal
Old 01-24-2017 , 17:30   Re: I Need some help with Menus
Reply With Quote #8

Okay. But let me rebuild my question. Server Command I know and is the one that I use Frequently. the FakeClientCommand I didn't know, But it's nice to know.

But I have any specific command already define. Like This one:

PHP Code:
public Action RestartRound (clientargs)
{
    
ServerCommand("mp_restartgame 1");
    
ServerCommand("say [:: Restart Round ! Good Luck, Have Fun ! ::]");
    
ServerCommand("say [:: Restart Round ! Good Luck, Have Fun ! ::]");

So, How Do I Use this already define Command in the menu in that specific category on the menu?

PS: That's what I meant. Sorry, if I misunderstood.

PSS: If I only Reply Some hours later. Don't Worry. This Post Don't Die until I say so!

Last edited by ItsWolfPT; 01-25-2017 at 07:38.
ItsWolfPT is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 01-24-2017 , 18:14   Re: I Need some help with Menus
Reply With Quote #9

Quote:
Originally Posted by ItsWolfPT View Post
-snip-
Use functions to your advantage. Don't be afraid to create new functions so you can reuse code

PHP Code:
public Action RestartRound(clientargs)
{
    
RestartGame(1"[:: Restart Round ! Good Luck, Have Fun ! ::]"2);
}


void RestartGame(int delay, const char[] phraseint repeatAmmount)
{
    
ServerCommand("mp_restartgame %i"delay);
    for (
int i 0repeatAmmounti++)
    {
        
PrintToChatAll(phrase);
    }

Now you can use the new restart round function in the menu callback

Last edited by headline; 01-24-2017 at 18:31.
headline is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 01-24-2017 , 18:15   Re: I Need some help with Menus
Reply With Quote #10

PHP Code:
    if (StrEqual(item"Command1"))
    {
        
ServerCommand("mp_restartgame 1");  // Execute a servercommand
    
}

    if (
StrEqual(item"Command2"))
    {
        
RestartRound(client0);  // Execute a function of your plugin 0 = the args of your function
    
}

    if (
StrEqual(item"Command3"))
    {
        
FakeClientCommand(clientsm_rockthevote);  // Execute a player command for a client
    
}

...

public 
Action RestartRound (int clientint args)
{
    
ServerCommand("mp_restartgame 1");
    
PrintToChatAll("[:: Restart Round ! Good Luck, Have Fun ! ::]");  // use PrintToChat / PrintToChatAll insead of servercommand say
    
PrintToChatAll("[:: Restart Round ! Good Luck, Have Fun ! ::]");

__________________
coding & free software

Last edited by shanapu; 01-24-2017 at 18:16.
shanapu 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 06:05.


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