AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   HELP Show and Hide Options in Menu (https://forums.alliedmods.net/showthread.php?t=314948)

SpirT 03-14-2019 15:47

HELP Show and Hide Options in Menu
 
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_SMcfgfilesizeof(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 clientint args)
{
    if(
client == 1)
    {
        
RegrasMenu().Display(clientMENU_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_handlerMENU_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 rmMenuAction actionint clientint item)
{
    
char choice[32];
    
rm.GetItem(itemchoicesizeof(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!

Mathias. 03-15-2019 22:01

Re: HELP Show and Hide Options in Menu
 
replace GetConVarInt to
https://sm.alliedmods.net/new-api/co...etConVarString

if (strlen(value) > 0) -> show option

SpirT 03-16-2019 06:38

Re: HELP Show and Hide Options in Menu
 
Quote:

Originally Posted by Mathias. (Post 2643529)
replace GetConVarInt to
https://sm.alliedmods.net/new-api/co...etConVarString

if (strlen(value) > 0) -> show option

Hey! Thanks for your reply. So I've got a lot of errors and if I change the char's that I used to value it says that value is a undefined symbol... And if I try to use for example char value[64]; it shows more errors.

So can you help me?

There is the part with the errors:

PHP Code:

public Menu RegrasMenu()
{
    
char custom_mt[64];
    
char o1c[64];
    
char o2c[64];
    
char o3c[64];
    
char o4c[64];
    
char o5c[64];
    
char o6c[64];
    
char o7c[64];
    
char o8c[64];
    
char o9c[64];
    
char o10c[64];
    
int o1_title GetConVarString(o1o1csizeof(o1c));
    
int o2_title GetConVarString(o2o2csizeof(o2c));
    
int o3_title GetConVarString(o3o3csizeof(o3c));
    
int o4_title GetConVarString(o4o4csizeof(o4c));
    
int o5_title GetConVarString(o5o5csizeof(o5c));
    
int o6_title GetConVarString(o6o6csizeof(o6c));
    
int o7_title GetConVarString(o7o7csizeof(o7c));
    
int o8_title GetConVarString(o8o8csizeof(o8c));
    
int o9_title GetConVarString(o9o9csizeof(oc9));
    
int o10_title GetConVarString(o10o10csizeof(o10c));
    
int menu_title GetConVarString(mtitlecustom_mtsizeof(custom_mt));
    
    
// MENU DEFINING OPTIONS
    
    
Menu rm = new Menu(rm_handlerMENU_ACTIONS_ALL);
    if(
strlen(custom_mt) > 0)
    {
        
rm.SetTitle("%i"menu_title);
    }
    else if(
strlen(custom_mt) < 0)
    {
        
rm.SetTitle("Regras Do Servidor");
    }
    if(
strlen(o1c) > 0)
    {
        
rm.AddItem("1""%i"o1_title);
    }
    if(
strlen(o2c) > 0)
    {
        
rm.AddItem("2""%i"o2_title);
    }
    if(
strlen(o3c) > 0)
    {
        
rm.AddItem("3""%i"o3_title);
    }
    if(
strlen(o4c) > 0)
    {
        
rm.AddItem("4""%i"o4_title);
    }
    if(
strlen(o5c) > 0)
    {
        
rm.AddItem("5""%i"o5_title);
    }
    if(
strlen(o6c) > 0)
    {
        
rm.AddItem("6""%i"o6_title);
    }
    if(
strlen(o7c) > 0)
    {
        
rm.AddItem("7""%i"o7_title);
    }
    if(
strlen(o8c) > 0)
    {
        
rm.AddItem("8""%i"o8_title);
    }
    if(
strlen(o9c) > 0)
    {    
        
rm.AddItem("9""%i"o9_title);
    }
    if(
strlen(o10c) > 0)
    {
        
rm.AddItem("10""%i"o10_title);
    }
    
rm.ExitButton true;
    
rm.ExitBackButton false;
    
    return 
rm;


There are the errors:

Code:

Line 102 - Warning 213 - tag mismatch
Line 103 - Warning 213 - tag mismatch
Line 104 - Warning 213 - tag mismatch
Line 105 - Warning 213 - tag mismatch
Line 106 - Warning 213 - tag mismatch
Line 107 - Warning 213 - tag mismatch
Line 108 - Warning 213 - tag mismatch
Line 109 - Warning 213 - tag mismatch
Line 110 - Warning 213 - tag mismatch
Line 111 - Warning 213 - tag mismatch
Line 112 - Warning 213 - tag mismatch

How can I fix this?

Best Regards for u,

SpirT.

Mathias. 03-16-2019 14:55

Re: HELP Show and Hide Options in Menu
 
GetConVarString is a void function it doesn't return anything, you value is now in your oXc variables.

PHP Code:

public Menu RegrasMenu() 

    
char custom_mt[64]; 
    
char o1c[64]; 
    
GetConVarString(o1o1csizeof(o1c));
    ...

    
GetConVarString(mtitlecustom_mtsizeof(custom_mt));

     
    
// MENU DEFINING OPTIONS 
     
    
Menu rm = new Menu(rm_handlerMENU_ACTIONS_ALL); 
    if(
strlen(custom_mt) > 0
    { 
        
rm.SetTitle("%i"menu_title); 
    } 
    else if(
strlen(custom_mt) < 0
    { 
        
rm.SetTitle("Regras Do Servidor"); 
    } 
    if(
strlen(o1c) > 0
    { 
        
rm.AddItem("1""%i"o1c); 
    }
    ...
    
rm.ExitButton true
    
rm.ExitBackButton false
     
    return 
rm



Mathias. 03-16-2019 15:10

Re: HELP Show and Hide Options in Menu
 
While I was cleaning your code to give you a good example I've notice you misuse the function rm.AddItem, AddItem doesn't support string formatting you have to use the function Format
References:
https://sm.alliedmods.net/new-api/menus/Menu/AddItem
https://sm.alliedmods.net/new-api/string/Format

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" 
}; 

ConVar menuOptions[10]; 

public 
void OnPluginStart() 

    
char title[128];
    
char description[128];
    
char convarName[128];
    for (
int i 0sizeof(menuOptions); i++) {
        
Format(convarNamesizeof(convarName), "sm_title_option%d"i+1);
        
Format(titlesizeof(title), "Title %d"i+1);
        
Format(descriptionsizeof(description), "Title of the option %d"i+1);
        
menuOptions[i] = CreateConVar(convarNametitledescription); 
    }


public 
Menu RegrasMenu() 

    
char optionNum[2];
    
char optionText[128];
    
Menu rm = new Menu(rm_handlerMENU_ACTIONS_ALL); 
    for (
int i 0sizeof(menuOptions); i++) {
        
GetConVarString(menuOptions[i], optionTextsizeof(optionText));
        
// \0 is a empty character, if the first charater is empty strlen = 0
        
if (optionText[0] == '\0') continue;
        
IntToString(ioptionNumsizeof(optionNum));
        
rm.AddItem(optionNumoptionText);
    }
    
rm.ExitButton true
    
rm.ExitBackButton false
     
    return 
rm


public 
int rm_handler(Menu rmMenuAction actionint clientint item

    




All times are GMT -4. The time now is 16:24.

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