AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Menus + Cvars (https://forums.alliedmods.net/showthread.php?t=129005)

GXLZPGX 06-07-2010 20:03

Menus + Cvars
 
Is it possible to add the info from a cvar into a menu item? Such as:

PHP Code:

menu_additemmenu"%d HP""1"

%d = get_pcvar_num(pcvar)

fysiks 06-07-2010 20:10

Re: Menus + Cvars
 
You have to format the cvar into a string and then pass the string to the menu_additem() function.

Alucard^ 06-07-2010 20:18

Re: Menus + Cvars
 
PHP Code:

%get_pcvar_num(pcvar

-->

PHP Code:

%get_pcvar_string(pcvarstring[], len


GXLZPGX 06-07-2010 20:29

Re: Menus + Cvars
 
Quote:

Originally Posted by Alucard^ (Post 1202781)
PHP Code:

%get_pcvar_num(pcvar

-->

PHP Code:

%get_pcvar_string(pcvarstring[], len


Fuck me, I don't have much experience with this. Example of a simple menu?

PHP Code:

public shopid )
{
    if( 
is_user_aliveid ) && cs_get_user_teamid ) == CS_TEAM_T )
    {
        new 
menu menu_create"Main Menu""menu_handler" )
        
menu_additemmenu"%d HP""1"

There, started it for you if you're willing to give an example of using a string with it.

fysiks 06-07-2010 20:32

Re: Menus + Cvars
 
PHP Code:

new szString[32]
formatex(szStringcharsmax(szString), "%d HP"get_cvar_num("your_cvar_here"))
menu_additem(menuszString, ...) 

But, remember to use pcvars.

Alucard^ 06-07-2010 20:39

Re: Menus + Cvars
 
Oh, is a number... not a string, sry... my mistake.

Here an example:

Code:
#include <amxmodx> #define PLUGIN  "New Plugin" #define AUTHOR  "Alucard" #define VERSION "0.0.1" new p_CvarSomething; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);         p_CvarSomething = register_cvar("cvar_something", "1");         register_clcmd("say /menu", "HookCmdMenu"); } public HookCmdMenu(id) {     new menu = menu_create("I am a menu", "FuckingMenuHandler");         new szItem[32];     formatex(szItem, 31, "%d HP", get_pcvar_num(p_CvarSomething) );         menu_additem(menu, szItem, "1");         menu_display(id, menu);     return PLUGIN_HANDLED; }

But if is an string, see the fysik's example.

fysiks 06-07-2010 21:12

Re: Menus + Cvars
 
Quote:

Originally Posted by Alucard^ (Post 1202797)
But if is an string, see the fysik's example.

No, my example is the same as yours (essentially). You just did the whole thing is all that is different (and you used pcvars).

Alucard^ 06-07-2010 23:22

Re: Menus + Cvars
 
Ohhh, i saw bad, thought that you did it an example with a string (get_cvar_string), but no... sry.


All times are GMT -4. The time now is 05:28.

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