View Single Post
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 03-16-2019 , 15:10   Re: HELP Show and Hide Options in Menu
Reply With Quote #5

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

    


Last edited by Mathias.; 03-16-2019 at 15:12.
Mathias. is offline