Hey guys. Today I decided to improve my skills in menus and I have a question.
I added ConVars for options in the Menu and I want to check if ConVar value is empty "" do hide option in the Menu, else show the option in the menu with the convar title.
The code is already like that. Can someone help me how to do it?
PHP Code:
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "SpirT"
#define PLUGIN_VERSION "1.0.0"
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#pragma newdecls required
public Plugin myinfo =
{
name = "Rules",
author = PLUGIN_AUTHOR,
description = "Description of 'sm_rules'",
version = PLUGIN_VERSION,
url = "https://sm.blcm.pt"
};
char cfgfile[512];
ConVar o1;
ConVar o2;
ConVar o3;
ConVar o4;
ConVar o5;
ConVar o6;
ConVar o7;
ConVar o8;
ConVar o9;
ConVar o10;
ConVar mtitle;
public void OnPluginStart()
{
RegConsoleCmd("sm_rules", CommandRulesMenu);
BuildPath(Path_SM, cfgfile, sizeof(cfgfile), "configs/rules.cfg");
o1 = CreateConVar("sm_title_option1", "Title 1", "Title of the option 1");
o2 = CreateConVar("sm_title_option2", "Title 2", "Title of the option 2");
o3 = CreateConVar("sm_title_option3", "Title 3", "Title of the option 3");
o4 = CreateConVar("sm_title_option4", "Title 4", "Title of the option 4");
o5 = CreateConVar("sm_title_option5", "Title 5", "Title of the option 5");
o6 = CreateConVar("sm_title_option6", "Title 6", "Title of the option 6");
o2 = CreateConVar("sm_title_option7", "Title 7", "Title of the option 7");
o2 = CreateConVar("sm_title_option8", "Title 8", "Title of the option 8");
o2 = CreateConVar("sm_title_option9", "Title 9", "Title of the option 9");
o2 = CreateConVar("sm_title_option10", "Title 10", "Title of the option 10");
mtitle = CreateConVar("sm_menu_title", "Menu Title", "Change the menu title, use \"\" for default");
}
public Action CommandRegrasMenu(int client, int args)
{
if(client == 1)
{
RegrasMenu().Display(client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
else
{
PrintToServer("Could not display menu to client because Client index is invalid");
return Plugin_Handled
}
return Plugin_Handled;
}
public Menu RegrasMenu()
{
int o1_title = GetConVarInt(o1);
int o2_title = GetConVarInt(o2);
int o3_title = GetConVarInt(o3);
int o4_title = GetConVarInt(o4);
int o5_title = GetConVarInt(o5);
int o6_title = GetConVarInt(o6);
int o7_title = GetConVarInt(o7);
int o8_title = GetConVarInt(o8);
int o9_title = GetConVarInt(o9);
int o10_title = GetConVarInt(o10);
int menu_title = GetConVarInt(mtitle);
Menu rm = new Menu(rm_handler, MENU_ACTIONS_ALL);
rm.SetTitle("%i", menu_title);
rm.AddItem("1", "%i", o1_title);
rm.AddItem("2", "%i", o2_title);
rm.AddItem("3", "%i", o3_title);
rm.AddItem("5", "%i", o4_title);
rm.AddItem("4", "%i", o5_title);
rm.AddItem("6", "%i", o6_title);
rm.AddItem("7", "%i", o7_title);
rm.AddItem("8", "%i", o8_title);
rm.AddItem("9", "%i", o9_title);
rm.AddItem("10", "%i", o10_title);
rm.ExitButton = true;
rm.ExitBackButton = false;
return rm;
}
public int rm_handler(Menu rm, MenuAction action, int client, int item)
{
char choice[32];
rm.GetItem(item, choice, sizeof(choice));
if(action == MenuAction_Select)
{
if(StrEqual(choice, "1"))
{
if(o1_title == '') // check if option has "" or "Title of option"
{
// Do not show this option on Menu
}
else
{
// Show option on the Menu
}
}
// ....
}
}
Thanks and best regards!
__________________