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

Menu functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jakub1411
Member
Join Date: Jul 2012
Old 10-22-2017 , 06:27   Menu functions
Reply With Quote #1

Hello guys,
I want add to my menu function, that players can take only one item per round from menu and if player want take again in same round, game will say something like "You have taken item already, wait to next round..."
And second thing that i need is, after Game Commencing - 1st round will menu deactived and automatically will say to all players something like "In 1st round you cant use menu". After 1st round at start of 2nd round and every round menu will actived and shows to all. Can someone help, please?
Thanks!!

PHP Code:
#include <amxmodx>

public plugin_init()
{
    
register_plugin("Awesome menu""1.0""me");
    
register_clcmd("say /menu""AwesomeMenu"_"");
}

public 
AwesomeMenu(id)
{
    new 
menu menu_create("Look at this awesome Menu!:""my_awesome_menu");

    
menu_additem(menu"I'm Selection #1"""0);
    
menu_additem(menu"I'm Selection #2"""0);

    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
}

public 
my_awesome_menu(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(id);
        return 
PLUGIN_HANDLED;
    }

    new 
command[6], name[64], accesscallback;
    
menu_item_getinfo(menuitemaccesscommandsizeof command 1namesizeof name 1callback);

    switch(
item)
    {
        case 
0client_print(idprint_chat"Hooray! You selected the Awesome 1st Selection");
        case 
1client_print(idprint_chat"OH NO! You selected the Awesome 2nd Selection! BEWARE!");
    }
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;

jakub1411 is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 10-22-2017 , 06:57   Re: Menu functions
Reply With Quote #2

You can use bool data type checking whether the menu option is choosed or not.
For the first round blocker, hook ct and t win sounds and increase a value of an int. The value works as a round counter, which reset itself on Game Commencing event and on restart. If the value of the int. is 1, means that it's the first round, then block the menu.
__________________

Last edited by Relaxing; 10-22-2017 at 06:58. Reason: Using phone, so no examples.
Relaxing is offline
jakub1411
Member
Join Date: Jul 2012
Old 10-22-2017 , 08:37   Re: Menu functions
Reply With Quote #3

Can you show some example later please? I dont understand this well, Im newbie, sorry
jakub1411 is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 10-22-2017 , 09:48   Re: Menu functions
Reply With Quote #4

Code:
#include <amxmodx> #define int new int iRound = 1; int item_choosed[33]; public plugin_init(){     register_clcmd("say /menu", "menu");     register_event("SendAudio", "evWin", "a", "2&%!MRAD_terwin");     register_event("SendAudio", "evWin", "a", "2&%!MRAD_ctwin");     register_event("TextMsg", "evReset", "a", "2=#Game_Commencing");     register_event("TextMsg", "evReset", "a", "2=#Game_will_restart_in"); } public evWin(){     iRound++;     for (int i = 0; i < get_maxplayers(); i++){         item_choosed[i] = 0;     } } public evReset(){     iRound = 1;     for (int i = 0; i < get_maxplayers(); i++){         item_choosed[i] = 0;     } } public menu(id){     if(iRound == 1){         client_print(id, print_chat, "You can't use the menu on the first round");         return 1;     }     int menu = menu_create("Custom Menu", "handler");     int szOption[32];     if(item_choosed[id]){         formatex(szOption, charsmax(szOption), "\dRespawn");     }     else {         formatex(szOption, charsmax(szOption), "Respawn");     }     menu_additem(menu, szOption);     menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);     menu_display(id, menu);     return 0; } public handler(id, menu, item){     if(item == MENU_EXIT){         menu_destroy(id);         return 1;     }     switch(item){         case 0: {             if(item_choosed[id]){                 client_print(id, print_chat, "Try again next round.");             }             else {                  client_print(id, print_chat, "Executing respawn function");                  item_choosed[id] = 1;             }         }     }     menu_destroy(menu);     return 1; }
__________________

Last edited by Relaxing; 10-24-2017 at 09:14.
Relaxing is offline
jakub1411
Member
Join Date: Jul 2012
Old 10-22-2017 , 12:24   Re: Menu functions
Reply With Quote #5

Thank you!
jakub1411 is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 10-22-2017 , 13:16   Re: Menu functions
Reply With Quote #6

Quote:
Originally Posted by jakub1411 View Post
Thank you!
Did the code even work?
__________________
Relaxing is offline
jakub1411
Member
Join Date: Jul 2012
Old 10-22-2017 , 18:14   Re: Menu functions
Reply With Quote #7

Tested work perfect, but plugin compilator wrote undefined "id" in this code part:
PHP Code:
public evWin(){
    
iRound++;
    
item_choosed[id] = false;
}

public 
evReset(){
    
iRound 1;
    
item_choosed[id] = false;

then i replaced it to this,
PHP Code:
public evWin(id){
    
iRound++;
    
item_choosed[id] = false;
}

public 
evReset(id){
    
iRound 1;
    
item_choosed[id] = false;

it works, but i dont know if its good replace.
And here's something wrong, if i take item from menu first time in one round it works, next time in same round i cant take. Thats good, but in next new round i cant take nothing. Can fix it please? I want take item only once at spawn in every new round. Thank you!
jakub1411 is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 10-23-2017 , 07:59   Re: Menu functions
Reply With Quote #8

Confusing...
The bool resets on both events.
Change the map and try it on the first round. If the menu doesn't open at all, try adding some bots so you get the Game Commencing event. If the menu doesn't open try passing through first round and open the menu again. If it opens successfully, choose the Respawn option. Open the menu again, if the Respawn has got grey color it means that if you choose it again it would print that one time only message. Pass through second round. I can't see a mistake made at the code so the bool on the end of the round will become false, so every round you can choose Respawn one time only.
__________________
Relaxing is offline
jakub1411
Member
Join Date: Jul 2012
Old 10-23-2017 , 09:17   Re: Menu functions
Reply With Quote #9

I tried change map and add some bots. At start of game commencing event i cant open menu. Then I pass through first round i can open menu and can choose respawn. If i open menu again, respawn has got grey color. Passing throung second round, menu is open successfully again and respawn still has got grey color. Whats goin wrong, when at passing throung second round respawn still has grey color? Thank you
jakub1411 is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 10-23-2017 , 09:57   Re: Menu functions
Reply With Quote #10

For some unknown reasons bool won't reset on evWin(). I don't know why.
__________________
Relaxing 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 09:34.


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