How to edit Main Menu?

Helping Topics
Post Reply
User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1703
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 75 times
Age: 20
Contact:

How to edit Main Menu?

#1

Post by Raheem » 1 Year Ago

How to edit Main Menu?

1-First Open ze_main_menu.sma You will find it like:
    1. #include <zombie_escape>
    2.  
    3. // Keys
    4. const OFFSET_CSMENUCODE = 205
    5. const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0
    6.  
    7. public plugin_init()
    8. {
    9.     register_plugin("[ZE] Main Menu", ZE_VERSION, AUTHORS)
    10.    
    11.     // Commands
    12.     register_clcmd("chooseteam", "Cmd_ChooseTeam")
    13.     register_clcmd("say /ze", "Cmd_ChooseTeam")
    14.     register_clcmd("say_team /ze", "Cmd_ChooseTeam")
    15.    
    16.     // Register Menus
    17.     register_menu("Main Menu", KEYSMENU, "Main_Menu")
    18. }
    19.  
    20. public Cmd_ChooseTeam(id)
    21. {
    22.     Show_Menu_Main(id)
    23.     return PLUGIN_HANDLED // Kill the Choose Team Command
    24. }
    25.  
    26. // Main Menu
    27. public Show_Menu_Main(id)
    28. {
    29.     static szMenu[250]
    30.     new iLen
    31.    
    32.     // Title
    33.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%L^n^n", id, "MAIN_MENU_TITLE")
    34.    
    35.     // 1. Buy Weapons
    36.     if (is_user_alive(id))
    37.     {
    38.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w1.\r %L^n", id, "MENU_WEAPONBUY")
    39.     }
    40.     else
    41.     {
    42.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d1. %L^n", id, "MENU_WEAPONBUY")
    43.     }
    44.    
    45.     // 2. Extra Items
    46.     if (is_user_alive(id))
    47.     {
    48.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w2.\r %L^n", id, "MENU_EXTRABUY")
    49.     }
    50.     else
    51.     {
    52.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d2. %L^n", id, "MENU_EXTRABUY")
    53.     }
    54.    
    55.     // 0. Exit
    56.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\w0.\r %L", id, "EXIT")
    57.    
    58.     // Fix for AMXX custom menus
    59.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    60.     show_menu(id, KEYSMENU, szMenu, -1, "Main Menu")
    61. }
    62.  
    63. // Main Menu
    64. public Main_Menu(id, key)
    65. {
    66.     // Player disconnected?
    67.     if (!is_user_connected(id))
    68.         return PLUGIN_HANDLED
    69.    
    70.     switch (key)
    71.     {
    72.         case 0: // Buy Weapons
    73.         {
    74.             client_cmd(id, "guns")
    75.         }
    76.         case 1: // Extra Items
    77.         {
    78.             if (is_user_alive(id))
    79.             {
    80.                 ze_show_items_menu(id)
    81.             }
    82.             else
    83.             {
    84.                 ze_colored_print(id, "%L", id, "DEAD_CANT_BUY_WEAPON")
    85.             }
    86.         }
    87.     }
    88.     return PLUGIN_HANDLED
    89. }
2-To add new items to the list, First thing we need to format the new item like:
    1. #include <zombie_escape>
    2.  
    3. // Keys
    4. const OFFSET_CSMENUCODE = 205
    5. const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0
    6.  
    7. public plugin_init()
    8. {
    9.     register_plugin("[ZE] Main Menu", ZE_VERSION, AUTHORS)
    10.    
    11.     // Commands
    12.     register_clcmd("chooseteam", "Cmd_ChooseTeam")
    13.     register_clcmd("say /ze", "Cmd_ChooseTeam")
    14.     register_clcmd("say_team /ze", "Cmd_ChooseTeam")
    15.    
    16.     // Register Menus
    17.     register_menu("Main Menu", KEYSMENU, "Main_Menu")
    18. }
    19.  
    20. public Cmd_ChooseTeam(id)
    21. {
    22.     Show_Menu_Main(id)
    23.     return PLUGIN_HANDLED // Kill the Choose Team Command
    24. }
    25.  
    26. // Main Menu
    27. public Show_Menu_Main(id)
    28. {
    29.     static szMenu[250]
    30.     new iLen
    31.    
    32.     // Title
    33.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%L^n^n", id, "MAIN_MENU_TITLE")
    34.    
    35.     // 1. Buy Weapons
    36.     if (is_user_alive(id))
    37.     {
    38.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w1.\r %L^n", id, "MENU_WEAPONBUY")
    39.     }
    40.     else
    41.     {
    42.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d1. %L^n", id, "MENU_WEAPONBUY")
    43.     }
    44.    
    45.     // 2. Extra Items
    46.     if (is_user_alive(id))
    47.     {
    48.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w2.\r %L^n", id, "MENU_EXTRABUY")
    49.     }
    50.     else
    51.     {
    52.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d2. %L^n", id, "MENU_EXTRABUY")
    53.     }
    54.    
    55.     // 3. Your New Item
    56.     if (is_user_alive(id))
    57.     {
    58.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w2.\r My new item!^n")
    59.     }
    60.     else
    61.     {
    62.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d2. My new item!^n")
    63.     }
    64.    
    65.     // 0. Exit
    66.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\w0.\r %L", id, "EXIT")
    67.    
    68.     // Fix for AMXX custom menus
    69.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    70.     show_menu(id, KEYSMENU, szMenu, -1, "Main Menu")
    71. }
    72.  
    73. // Main Menu
    74. public Main_Menu(id, key)
    75. {
    76.     // Player disconnected?
    77.     if (!is_user_connected(id))
    78.         return PLUGIN_HANDLED
    79.    
    80.     switch (key)
    81.     {
    82.         case 0: // Buy Weapons
    83.         {
    84.             client_cmd(id, "guns")
    85.         }
    86.         case 1: // Extra Items
    87.         {
    88.             if (is_user_alive(id))
    89.             {
    90.                 ze_show_items_menu(id)
    91.             }
    92.             else
    93.             {
    94.                 ze_colored_print(id, "%L", id, "DEAD_CANT_BUY_WEAPON")
    95.             }
    96.         }
    97.     }
    98.     return PLUGIN_HANDLED
    99. }
  • Note that this item will appear white for alive players and gray for dead players. If you don't like that remove the is_user_alive(id) check.
3-Editing the menu handler (which mean what to do when player press this new item?):
    1. #include <zombie_escape>
    2.  
    3. // Keys
    4. const OFFSET_CSMENUCODE = 205
    5. const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0
    6.  
    7. public plugin_init()
    8. {
    9.     register_plugin("[ZE] Main Menu", ZE_VERSION, AUTHORS)
    10.    
    11.     // Commands
    12.     register_clcmd("chooseteam", "Cmd_ChooseTeam")
    13.     register_clcmd("say /ze", "Cmd_ChooseTeam")
    14.     register_clcmd("say_team /ze", "Cmd_ChooseTeam")
    15.    
    16.     // Register Menus
    17.     register_menu("Main Menu", KEYSMENU, "Main_Menu")
    18. }
    19.  
    20. public Cmd_ChooseTeam(id)
    21. {
    22.     Show_Menu_Main(id)
    23.     return PLUGIN_HANDLED // Kill the Choose Team Command
    24. }
    25.  
    26. // Main Menu
    27. public Show_Menu_Main(id)
    28. {
    29.     static szMenu[250]
    30.     new iLen
    31.    
    32.     // Title
    33.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%L^n^n", id, "MAIN_MENU_TITLE")
    34.    
    35.     // 1. Buy Weapons
    36.     if (is_user_alive(id))
    37.     {
    38.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w1.\r %L^n", id, "MENU_WEAPONBUY")
    39.     }
    40.     else
    41.     {
    42.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d1. %L^n", id, "MENU_WEAPONBUY")
    43.     }
    44.    
    45.     // 2. Extra Items
    46.     if (is_user_alive(id))
    47.     {
    48.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w2.\r %L^n", id, "MENU_EXTRABUY")
    49.     }
    50.     else
    51.     {
    52.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d2. %L^n", id, "MENU_EXTRABUY")
    53.     }
    54.    
    55.     // 3. Your New Item
    56.     if (is_user_alive(id))
    57.     {
    58.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w2.\r My new item!^n")
    59.     }
    60.     else
    61.     {
    62.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d2. My new item!^n")
    63.     }
    64.    
    65.     // 0. Exit
    66.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\w0.\r %L", id, "EXIT")
    67.    
    68.     // Fix for AMXX custom menus
    69.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    70.     show_menu(id, KEYSMENU, szMenu, -1, "Main Menu")
    71. }
    72.  
    73. // Main Menu
    74. public Main_Menu(id, key)
    75. {
    76.     // Player disconnected?
    77.     if (!is_user_connected(id))
    78.         return PLUGIN_HANDLED
    79.    
    80.     switch (key)
    81.     {
    82.         case 0: // Buy Weapons
    83.         {
    84.             client_cmd(id, "guns")
    85.         }
    86.         case 1: // Extra Items
    87.         {
    88.             if (is_user_alive(id))
    89.             {
    90.                 ze_show_items_menu(id)
    91.             }
    92.             else
    93.             {
    94.                 ze_colored_print(id, "%L", id, "DEAD_CANT_BUY_WEAPON")
    95.             }
    96.         }
    97.         case 2: // Your New Item
    98.         {
    99.             if (is_user_alive(id))
    100.             {
    101.                 // Use your Command or Native here
    102.             }
    103.             else
    104.             {
    105.                 ze_colored_print(id, "NOT available for DEAD players!")
    106.             }
    107.         }
    108.     }
    109.     return PLUGIN_HANDLED
    110. }
  • Same thing you can remove the check for user alive or not here also.

-Full example, To add Manual Unstuck to the main menu:
    1. #include <zombie_escape>
    2.  
    3. // Keys
    4. const OFFSET_CSMENUCODE = 205
    5. const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0
    6.  
    7. public plugin_init()
    8. {
    9.     register_plugin("[ZE] Main Menu", ZE_VERSION, AUTHORS)
    10.    
    11.     // Commands
    12.     register_clcmd("chooseteam", "Cmd_ChooseTeam")
    13.     register_clcmd("say /ze", "Cmd_ChooseTeam")
    14.     register_clcmd("say_team /ze", "Cmd_ChooseTeam")
    15.    
    16.     // Register Menus
    17.     register_menu("Main Menu", KEYSMENU, "Main_Menu")
    18. }
    19.  
    20. public Cmd_ChooseTeam(id)
    21. {
    22.     Show_Menu_Main(id)
    23.     return PLUGIN_HANDLED // Kill the Choose Team Command
    24. }
    25.  
    26. // Main Menu
    27. public Show_Menu_Main(id)
    28. {
    29.     static szMenu[250]
    30.     new iLen
    31.    
    32.     // Title
    33.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w%L^n^n", id, "MAIN_MENU_TITLE")
    34.    
    35.     // 1. Buy Weapons
    36.     if (is_user_alive(id))
    37.     {
    38.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w1.\r %L^n", id, "MENU_WEAPONBUY")
    39.     }
    40.     else
    41.     {
    42.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d1. %L^n", id, "MENU_WEAPONBUY")
    43.     }
    44.    
    45.     // 2. Extra Items
    46.     if (is_user_alive(id))
    47.     {
    48.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w2.\r %L^n", id, "MENU_EXTRABUY")
    49.     }
    50.     else
    51.     {
    52.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d2. %L^n", id, "MENU_EXTRABUY")
    53.     }
    54.    
    55.     // 3. Unstuck
    56.     if (is_user_alive(id))
    57.     {
    58.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w2.\r Unstuck^n")
    59.     }
    60.     else
    61.     {
    62.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d2. Unstuck^n")
    63.     }
    64.    
    65.     // 0. Exit
    66.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\w0.\r %L", id, "EXIT")
    67.    
    68.     // Fix for AMXX custom menus
    69.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    70.     show_menu(id, KEYSMENU, szMenu, -1, "Main Menu")
    71. }
    72.  
    73. // Main Menu
    74. public Main_Menu(id, key)
    75. {
    76.     // Player disconnected?
    77.     if (!is_user_connected(id))
    78.         return PLUGIN_HANDLED
    79.    
    80.     switch (key)
    81.     {
    82.         case 0: // Buy Weapons
    83.         {
    84.             client_cmd(id, "guns")
    85.         }
    86.         case 1: // Extra Items
    87.         {
    88.             if (is_user_alive(id))
    89.             {
    90.                 ze_show_items_menu(id)
    91.             }
    92.             else
    93.             {
    94.                 ze_colored_print(id, "%L", id, "DEAD_CANT_BUY_WEAPON")
    95.             }
    96.         }
    97.         case 2: // Your New Item
    98.         {
    99.             if (is_user_alive(id))
    100.             {
    101.                 ze_unstuck_player(id)
    102.             }
    103.             else
    104.             {
    105.                 ze_colored_print(id, "!tYou can't use Unstuck while you are dead!y!")
    106.             }
    107.         }
    108.     }
    109.     return PLUGIN_HANDLED
    110. }
You don't know? Learn and you will know.

johnnysins2000
Veteran Member
Veteran Member
Pakistan
Posts: 672
Joined: 1 Year Ago
Location: Lahore
Has thanked: 11 times
Been thanked: 10 times
Age: 21
Contact:

#2

Post by johnnysins2000 » 1 Year Ago

Good Tutorial :)

Don't forget to post that reapi tutorial :lol:
Nobody Is That Busy If They Make Time :roll:

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1703
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 75 times
Age: 20
Contact:

#3

Post by Raheem » 1 Year Ago

Will do when get time.
You don't know? Learn and you will know.

User avatar
DarkZombie
Member
Member
Hungary
Posts: 56
Joined: 3 Months Ago
Donation: 1x donated in total €6.00
Has thanked: 15 times
Been thanked: 0
Contact:

#4

Post by DarkZombie » 1 Week Ago

This link is dead: "-Full example, To add Manual Unstuck to the main menu:" http://escapers-zone.xyz/viewtopic.php?f=15&t=1969

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest