loading
Jump to content
Welcome to CSElites
CSElites known as [www.cselites.com], a virtual world from May 1, 2012, which continues to grow in the gaming world. CSELITES.COM has over 65k members in continuous expansion, coming from different parts of the world.

Popular Servers:

ZM.CSELITES.COM Click for more info! connect
TZM.CSELITES.COM Click for more info! connect
DZM.CSELITES.COM Click for more info! connect

[Tutorial] Creating a Simple Menu in AMXX Pawn Scripting


DadoDz

Recommended Posts

  • Administrators

[STEP - 1] Setting up Your AMXX Plugin

 

  • On your server, find the scripting folder inside the AMX Mod X directory.

Example:

cstrike/addons/amxmodx/scripting

 

  • Inside the scripting folder, create a new .sma file.

Example:

menu_command.sma

 

[STEP - 2] Write the Pawn Script

 

#include <amxmodx>

#define PLUGIN "Simple Menu Plugin"
#define VERSION "1.0"
#define AUTHOR "Your Name"

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR);

    // Register the command
    register_clcmd("say /menu", "cmd_open_menu");
}

// This function is called when a player types /menu in chat
public cmd_open_menu(id)
{
    // Make sure the player is valid and connected
    if (!is_user_connected(id))
        return PLUGIN_HANDLED;
    
    // Create the menu with title and options
    new menu = menu_create("Choose an Option:", "menu_handler");
    
    // Add options to the menu (id and label)
    menu_additem(menu, "Option 1", "0");
    menu_additem(menu, "Option 2", "1");
    menu_additem(menu, "Option 3", "2");
    
    // Display the menu to the player
    menu_display(id, menu);
    
    return PLUGIN_HANDLED;
}

// This function is called when a player selects an option from the menu
public menu_handler(id, menu, item)
{
    // Ensure the player is valid and the menu exists
    if (!is_user_connected(id) || !menu)
        return PLUGIN_HANDLED;

    // Handle each option using a switch statement
    switch (item)
    {
        case 0:
        {
            // Option 1 - Send a message to the player
            client_print(id, print_chat, "Hello! You chose Option 1.");
        }
        case 1:
        {
            // Option 2 - Send a message to the player
            client_print(id, print_chat, "Hello! You chose Option 2.");
        }
        case 2:
        {
            // Option 3 - Send a message to the player
            client_print(id, print_chat, "Hello! You chose Option 3.");
        }
    }

    return PLUGIN_HANDLED;
}

Explanation:

 

  • menu_create(name[], handler[])
  • Creates a new menu.

 

  • menu_additem(menu, name[], info[])
  • Adds options to the menu. Each option is linked to a number (1 = 0, 2 = 1, 3 = 2.....).

 

  • menu_display(id, menu)
  • Shows the menu to the player.

 

  • switch (item)
  • Checks the value of item (which corresponds to the player's selection from the menu).

 

  • menu_handler(id, menu, item)
  • This function handles the player's selection from the menu, and checks which option the player selected and executes a corresponding action, like sending a message.

 

[STEP - 3] Compile the Plugin

 

 

  • Upload your .sma file or use the compile button to generate .amxx file (the compiled plugin).

 

  • Upload the compiled .amxx file to the plugins folder of your AMX Mod X server.

Example:

cstrike/addons/amxmodx/plugins
 

 

  • Open the plugins.ini file located in addons/amxmodx/configs, add the name of your compiled plugin at the end of the file.

Example:

menu_command.amxx

 

[STEP - 4] Testing the Plugin

 

  • Restart Your Server, then connect to the server in the game, and in the chat box type /menu.

 

  • The menu will appear with options like:

 

  1.  Option 1
  2.  Option 2
  3.  Option 3

 

  • Depending on your selection, the server will respond with a message.

 

That's it! You’ve created a simple menu plugin in AMXX Pawn Scripting.

This tutorial covers the basics, but you can expand it by adding more features.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.