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

Creating a Donation Menu that executes commands, error related to a variable


Post New Thread Reply   
 
Thread Tools Display Modes
Doodil
Senior Member
Join Date: Mar 2012
Old 08-24-2013 , 11:20   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #11

Quote:
Toggles evil trail on me and closes the menu. I'd like it to stay open until you manually close it (by pressing 0).
After a selection was made you have to redisplay the menu:

HTML Code:
public MenuHandler(Handle:menu, MenuAction:action, client, param2)
{
    switch (action)
    {
    case MenuAction_Select:
        {
            switch (param2)    //You can also use ServerCommand to do it directly without the client typing the command themselves.
            {
            case 0:
                {
                    FakeClientCommandEx(client, "say /eviltrail");
                    //ServerCommand("sm_robot #%d", GetClientUserId(client));    <-- Example of server command instead of fake client command.
                }
            case 1:
                {
                    FakeClientCommandEx(client, "say /evilglow");
                }
            case 2:
                {
                    FakeClientCommandEx(client, "say /robot");
                }
            }
            DisplayMenu(menu, client, MENU_TIME_FOREVER);
        }
    case MenuAction_End:
        {
            CloseHandle(menu);
        }
    }
}
________________________________

Quote:
How do I make the text in the menu Toggle.
You should save somewhere which client has activated the trail and who hasn't (by defining a global array of MAXPLAYER size) and changing this value whenever he uses the menu (so right after you call the function for the trail). Once you've done that you just change your
HTML Code:
 AddMenuItem(menu, "sm_robot", "Evil Trail");
to something like:

HTML Code:
if (clientHasTrail[client] == true)
{
	AddMenuItem(menu, "sm_robot", "Evil Trail [ON]");
}
else
{
	AddMenuItem(menu, "sm_robot", "Evil Trail [OFF]");
}
where clientHasTrail[] is a global array of booleans, saving wether or not the trail is already active.


________________________________

Quote:
How can I display commands in the menu (adding commands to the menu) based on which flags the admin has?
try something like:
HTML Code:
if(GetUserFlagBits(client) & ADMFLAG_CHAT)
{
	AddMenuItem(menu, "sm_robot", "Evil Trail");
}
(yes only one &)
to check the AccessFlags of a client against a certain flag. If the client has the ADMFLAG_CHAT in this example, then the if-expression will resolve to a number>0, and therefore will be interpreted as if(true). If you do it this way you kinda work around the override system, so consider using CheckCommandAccess instead.

________________________________

Quote:
Can anyone link me to a tutorial describing how to use sub menus?
Well you basically just draw a second menu after the first one, saving the information about what was selected in the submenu-selection itself or in a global array for the client. Just check out some of the approved plugins that already do that.
Doodil is offline
keyboard1333
Senior Member
Join Date: Aug 2013
Old 08-24-2013 , 18:59   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #12

Thanks for your response!
I tried your first bit of code, it changed it but didn't fix it. Here's what happens.
*Open Menu*
*Choose an Option, command is run*
*Menu Reopens*
*Choose an Option, command isn't run, menu closes*
Suggestions?


I'll look into the rest of your response now, thanks!
keyboard1333 is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 08-24-2013 , 19:29   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #13

I'm taking a guess here... but I think it is because of the

HTML Code:
CloseHandle(menu);
in the MenuAction_End part of the code. It might be possible that this part gets called even when you select a command option. If you reopen the menu and then close the handle immediately afterwards you pretty much kill the menu right there.

I suggest you remove the CloseHandle call there and try a debug-print to see what value param2 has when you select the exit button in the menu and then only call CloseHandle when someone actually selected the exit option.

E: You also gotta make sure to not reopen the menu when someone selected exit.

E²: If you try the whole [ON][OFF] toggling you might have to call ShowMenu(client); instead of DisplayMenu(), because you want the menu-item-strings to repaint. E³: In which case you do have to call CloseHandle after every selection. So basically: just replace DisplayMenu() with ShowMenu(client); and you should be set(and leave the CloseHandle() where it is)

Last edited by Doodil; 08-24-2013 at 19:57.
Doodil is offline
keyboard1333
Senior Member
Join Date: Aug 2013
Old 08-24-2013 , 21:50   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #14

I've managed to completely confuse myself so I'll just post my current code and tell you the issues:
PHP Code:
public OnPluginStart()
{
 
LoadTranslations("common.phrases");
 
RegAdminCmd("sm_donator"DonorMenuADMFLAG_RESERVATION);
}
public 
Action:DonorMenu(clientargs)
{
 if (!
client)
 {
  
ReplyToCommand(client"%t","Command is in-game only");
  return 
Plugin_Handled;
 }
 
ShowMenu(client);
 return 
Plugin_Handled;
}
ShowMenu(client)
{
 new 
Handle:menu CreateMenu(MenuHandler);
 
SetMenuExitBackButton(menufalse);
 
SetMenuTitle(menu"Donor Menu");
 if (
CheckCommandAccess(client"generic_admin"ADMFLAG_CUSTOM6 true)) 
 {
  
AddMenuItem(menu"1""Noclip");
  
AddMenuItem(menu"2""Evil Trail");
  
AddMenuItem(menu"3""Evil Glow");
  
AddMenuItem(menu"4""Evil Rocket");
  
AddMenuItem(menu"5""Robot");
  
AddMenuItem(menu"6""Resize / Resize Head");
  
AddMenuItem(menu"7""Freeze"); 
 }
 
DisplayMenu(menuclientMENU_TIME_FOREVER);
 
}
ShowMenu2(client)
{
 new 
Handle:menu2 CreateMenu(MenuHandler);
 
SetMenuExitBackButton(menu2true);
 
SetMenuTitle(menu2"Donor Menu");
 if (
CheckCommandAccess(client"generic_admin"ADMFLAG_CUSTOM6 true)) 
 {
  
AddMenuItem(menu2"1""Resize");
 }
 
DisplayMenu(menu2clientMENU_TIME_FOREVER);
 
}
public 
MenuHandler(Handle:menuMenuAction:actionclientparam2)
{
 switch (
action)
 {
  case 
MenuAction_Select:
  {
   switch (
param2)
   {
    case 
0:
    {
     
ServerCommand("sm_noclip #%d"GetClientUserId(client));
     
//FakeClientCommandEx(client, "say /eviltrail");
    
}
    case 
1:
    {
     
ServerCommand("sm_eviltrail #%d"GetClientUserId(client));
    }
    case 
2:
    {
     
ServerCommand("sm_evilglow #%d"GetClientUserId(client));
    }
    case 
3:
    {
     
ServerCommand("sm_evilrocket #%d"GetClientUserId(client));
    }
    case 
4:
    {
     
ServerCommand("sm_robot #%d"GetClientUserId(client));
    }
    case 
5:
    {
     
ShowMenu2(client);
     
CloseHandle(menu);
    }
    case 
6:
    {
     
ServerCommand("sm_freeze #%d 999"GetClientUserId(client));
    } 
   }
   
DisplayMenu(menuclientMENU_TIME_FOREVER);
  }
  case 
MenuAction_Cancel:
  {
   if(
param2 == -3
   {
    
CloseHandle(menu);
   }
   
PrintToChat(client"TEST %i"param2);
  }
 }
}
public 
MenuHandler2(Handle:menu2MenuAction:actionclientparam2)
{
 switch (
action)
 {
  case 
MenuAction_Select:
  {
   switch (
param2)
   {
    case 
0:
    {
     
ServerCommand("sm_resize #%d 1.0"GetClientUserId(client));
     
//FakeClientCommandEx(client, "say /eviltrail");
    
}
   }
   
DisplayMenu(menu2clientMENU_TIME_FOREVER);
  }
  case 
MenuAction_Cancel:
  {
   
ShowMenu(client);
   
//CloseHandle(menu);
  
}
 }

When you choose the Resize / Resize Head option, it does switch to the menu, but when you choose the Resize option it noclips you instead. When you exit from that menu, it prints -6 and closes the menu. When you exit from the main menu, it prints -3.
keyboard1333 is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 08-25-2013 , 05:16   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #15

HTML Code:
ShowMenu2(client)
{
 new Handle:menu2 = CreateMenu(MenuHandler);
 SetMenuExitBackButton(menu2, true);
 SetMenuTitle(menu2, "Donor Menu");
 if (CheckCommandAccess(client, "generic_admin", ADMFLAG_CUSTOM6 , true)) 
 {
  AddMenuItem(menu2, "1", "Resize");
 }
 DisplayMenu(menu2, client, MENU_TIME_FOREVER);
 
}
In the line
HTML Code:
new Handle:menu2 = CreateMenu(MenuHandler);
You told the second menu to use the MenuHandler function of the first menu. Change that to MenuHandler2 and the resize part should work
Doodil is offline
keyboard1333
Senior Member
Join Date: Aug 2013
Old 08-25-2013 , 07:11   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #16

Ok, I kind of got it working then broke it again.

Now when you click on either of the sub menus, they don't open. The server also started crashing sometimes while running these commands.

PHP Code:
public OnPluginStart()
{
 
LoadTranslations("common.phrases");
 
RegAdminCmd("sm_donator"DonorMenuADMFLAG_RESERVATION);
}
public 
Action:DonorMenu(clientargs)
{
 if (!
client)
 {
  
ReplyToCommand(client"%t","Command is in-game only");
  return 
Plugin_Handled;
 }
 
ShowMenu(client);
 return 
Plugin_Handled;
}
ShowMenu(client)
{
 new 
Handle:menu CreateMenu(MenuHandler);
 
SetMenuExitBackButton(menufalse);
 
SetMenuTitle(menu"Donor Menu");
 if (
CheckCommandAccess(client"generic_admin"ADMFLAG_CUSTOM6 true)) 
 {
  
AddMenuItem(menu"1""Noclip");
  
AddMenuItem(menu"2""Evil Rocket");
  
AddMenuItem(menu"3""Pretty Things");
  
AddMenuItem(menu"4""Resize / ResizeHead");  
 }
 
DisplayMenu(menuclientMENU_TIME_FOREVER);
 
}
ShowMenu2(client)
{
 new 
Handle:menu2 CreateMenu(MenuHandler2);
 
SetMenuExitBackButton(menu2true);
 
SetMenuTitle(menu2"Donor Menu -> Resize");
 if (
CheckCommandAccess(client"generic_admin"ADMFLAG_CUSTOM6 true)) 
 {
  
AddMenuItem(menu2"1""Resize (Small)");
  
AddMenuItem(menu2"2""Resize (Normal)");
  
AddMenuItem(menu2"3""Resize (Large)");
  
AddMenuItem(menu2"4""Resize Head (Super Small)");
  
AddMenuItem(menu2"5""Resize Head (Small)");
  
AddMenuItem(menu2"6""Resize Head (Normal)");
  
AddMenuItem(menu2"7""Resize Head (Large)");
  
AddMenuItem(menu2"8""Resize Head (Massive)");
 }
 
DisplayMenu(menu2clientMENU_TIME_FOREVER);
}
ShowMenu3(client)
{
 new 
Handle:menu3 CreateMenu(MenuHandler3);
 
SetMenuExitBackButton(menu3true);
 
SetMenuTitle(menu3"Donor Menu -> Pretty Things");
 if (
CheckCommandAccess(client"generic_admin"ADMFLAG_CUSTOM6 true)) 
 {
  
AddMenuItem(menu3"1""Unusual Weapon Effects");
  
AddMenuItem(menu3"2""Evil Trail");
  
AddMenuItem(menu3"3""Evil Glow");
  
AddMenuItem(menu3"4""Robot");
 }
 
DisplayMenu(menu3clientMENU_TIME_FOREVER);
}
public 
MenuHandler(Handle:menuMenuAction:actionclientparam2)
{
 switch (
action)
 {
  case 
MenuAction_Select:
  {
   switch (
param2)
   {
    case 
0:
    {
     
ServerCommand("sm_noclip #%d"GetClientUserId(client));
     
ServerCommand("sm_friendly #%d"GetClientUserId(client));
     
//FakeClientCommandEx(client, "say /eviltrail");
    
}
    case 
1:
    {
     
ServerCommand("sm_evilrocket #%d"GetClientUserId(client));
    }
    case 
2:
    {
     
ShowMenu3(client);
     
CloseHandle(menu);
    }
    case 
3:
    {
     
ShowMenu2(client);
     
CloseHandle(menu);
    }
   }
   
ShowMenu(client);
  }
  case 
MenuAction_End:
  {
   if(
param2 == -3
   {
    
CloseHandle(menu);
   }
  }
 }
}
public 
MenuHandler2(Handle:menu2MenuAction:actionclientparam2)
{
 switch (
action)
 {
  case 
MenuAction_Select:
  {
   switch (
param2)
   {
    case 
0:
    {
     
ServerCommand("sm_resize #%d 0.7"GetClientUserId(client));
    }
    case 
1:
    {
     
ServerCommand("sm_resize #%d 1.0"GetClientUserId(client));
    }
    case 
2:
    {
     
ServerCommand("sm_resize #%d 1.8"GetClientUserId(client));
    }
    case 
3:
    {
     
ServerCommand("sm_resizehead #%d 0.1"GetClientUserId(client));
    }
    case 
4:
    {
     
ServerCommand("sm_resizehead #%d 0.6"GetClientUserId(client));
    }
    case 
5:
    {
     
ServerCommand("sm_resizehead #%d 1.0"GetClientUserId(client));
    }
    case 
6:
    {
     
ServerCommand("sm_resizehead #%d 1.8"GetClientUserId(client));
    }
    case 
7:
    {
     
ServerCommand("sm_resizehead #%d 3.5"GetClientUserId(client));
    }
   }
   
ShowMenu2(client);
  }
  case 
MenuAction_Cancel:
  {
   if(
param2 == -3
   {
    
CloseHandle(menu2);
   } else {
    
ShowMenu(client);
    
CloseHandle(menu2);
   }
  }
 }
}  
public 
MenuHandler3(Handle:menu3MenuAction:actionclientparam2)
{
 switch (
action)
 {
  case 
MenuAction_Select:
  {
   switch (
param2)
   {
    case 
0:
    {
     
FakeClientCommandEx(client"say /unusual");
    }
    case 
1:
    {
     
ServerCommand("sm_eviltrail #%d"GetClientUserId(client));
    }    
    case 
2:
    {
     
ServerCommand("sm_evilglow #%d"GetClientUserId(client));
    }
    case 
3:
    {
     
ServerCommand("sm_robot #%d"GetClientUserId(client));
    }
   }
   
ShowMenu3(client);
  }
  case 
MenuAction_End:
  {
   if(
param2 == -3
   {
    
CloseHandle(menu3);
   } else {
    
ShowMenu(client);
    
CloseHandle(menu3);
   }
  }
 }

keyboard1333 is offline
Reply


Thread Tools
Display Modes

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 11:32.


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