Jump to content
JR Nova

[SOLVED] Displaying Variable Number on CfgCommunicationMenu text

Recommended Posts

Hello I'm trying to get a variable number (artilleryPrice) to show on the CfgCommunicationMenu 

 

class CfgCommunicationMenu
{
    class artillery
    {
        text = "format ['Artillery Strike <t color='#00ff00'>$%1</t>', artilleryPrice]"; // Text displayed in the menu and in a notification
        submenu = ""; // Submenu opened upon activation
        expression = "[] execVM 'support\arty.sqf'"; // Code executed upon activation (ignored when the submenu is not empty)
        icon = "\a3\Ui_f\data\GUI\Cfg\CommunicationMenu\artillery_ca.paa"; // Icon displayed permanently next to the command menu
        cursor = "\a3\Ui_f\data\IGUI\Cfg\Cursors\iconCursorSupport_ca.paa"; // Custom cursor displayed when the item is selected
        enable = "1"; // Simple expression condition for enabling the item
        removeAfterExpressionCall = 1; // 1 to remove the item after calling
    };
};

It just literally prints format ['Artillery Strike <t color='#00ff00'>$%1</t>', artilleryPrice].

 

Is this even possible? I've searched the forums and can't really find another example of something like this other than in GUIs, but I'm pretty sure I have to use a different format lol. I checked the PreProcessor Commands but I'm not exactly sure if what I'm looking for is in there or not.

Share this post


Link to post
Share on other sites

You can always change it at run time after menu has been initialised (BIS_fnc_addComMenuItem).

The menu is held in a missionNamespace variable called "BIS_fnc_addCommMenuItem_menu"

I'm not sure the comMenu supports structuredText?

 

  • Like 1

Share this post


Link to post
Share on other sites
11 hours ago, Larrow said:

You can always change it at run time after menu has been initialised (BIS_fnc_addComMenuItem).

The menu is held in a missionNamespace variable called "BIS_fnc_addCommMenuItem_menu"

I'm not sure the comMenu supports structuredText?

 

 

Ahh okay I can do without the structuredText.

But as for the missionNamespace variable, I'm not exactly sure how to go about changing that as I searched BIS_fnc_addCommMenuItem_menu and can't find anything.

 

I tried this code and the name didn't change.

_arty = [player,"artillery"] remoteExec ["BIS_fnc_addCommMenuItem"];
missionNamespace setVariable ["BIS_fnc_addCommMenuItem_menu",["artillery", format ['Artillery Strike $%1', artilleryPrice]]];

 

Share this post


Link to post
Share on other sites

@JR Nova,

Quote

But as for the missionNamespace variable, I'm not exactly sure how to go about changing that as I searched BIS_fnc_addCommMenuItem_menu and can't find anything.


Here's a couple examples,

Spoiler

missionNameSpace setVariable ["theVariable", theValue];
missionNameSpace setVariable ["scriptWriter", Jr_nova];

_thisValue=missionNameSpace getVariable ["theVariable", defaultValue];
missionNameSpace setVariable ["theVariable", _thisValue+1];

 

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

 

Thanks that helps, but does that work for arrays too? For my example (I think) I need to define what menu to look at and what to change the text to.

 

 How I'm assuming is 

Spoiler

// initializes the artillery support & price

artilleryPrice = 100;

_arty = [player,"artillery"] remoteExec ["BIS_fnc_addCommMenuItem"];

 

// defines what comm menu item to edit & text for the name

missionNameSpace setVariable ["artyText", ["artillery", format ['Artillery Strike $%1', artilleryPrice]]];

_text4arty = missionNameSpace getVariable ["artyText", ["artillery", "Artillery Strike - XXX"]];

 

// changes text for menu "artillery" to "Artillery Strike $100"

missionNameSpace setVariable ["BIS_fnc_addCommMenuItem_menu", _text4arty ];

 

In theory this would change my support menu to say Artillery Strike $100 or worst case Artillery Strike - XXX, but neither one of them show up.

Share this post


Link to post
Share on other sites
On 11/13/2019 at 7:39 PM, JR Nova said:

_arty = [player,"artillery"] remoteExec ["BIS_fnc_addCommMenuItem"];

Where is this happening? There is no sense to send the player argument.

If its a server remoteExec'ing to clients then the argument should be the clients local player, not the player from where the remote exec happens.

If its a dedicated server then player will be null.

If its meant to be added locally, then player will be correct, but there is no need to remoteExec.

 

On 11/13/2019 at 7:39 PM, JR Nova said:

but neither one of them show up

You really ought to add a comm menu item and look at the data structure for BIS_fnc_addCommMenuItem_menu, rather than blindly setting nonsensical data.

Spoiler

//description.ext

class CfgCommunicationMenu
{
	class artillery
	{
		text = "Artillery Strike";
		submenu = "";
		expression = "[] execVM 'support\arty.sqf'";
		icon = "\a3\Ui_f\data\GUI\Cfg\CommunicationMenu\artillery_ca.paa";
		cursor = "\a3\Ui_f\data\IGUI\Cfg\Cursors\iconCursorSupport_ca.paa";
		enable = "1";
		removeAfterExpressionCall = 1;
	};
};

//initPlayerLocal.sqf

//Custom function to add commMenu item
TAG_fnc_addCommMenuItem = {
	params[ "_item", "_args" ];

	//Add commMenu item and get its id
	_menuID = [ player, _item ] call BIS_fnc_addCommMenuItem;

	//Store a reference to the item and ID
	//so it can be updated with out adding a commMenu item
	_commMenuItems = missionNamespace getVariable[ "TAG_commMenuItems", [] ];
	_commMenuItems set[ count _commMenuItems, [ _item, _menuID ] ];
	missionNamespace setVariable[ "TAG_commMenuItems", _commMenuItems ];

	//If we have custom args
	if !( isNil "_args" ) then {
		[ _item, _args, _menuID ] call TAG_fnc_updateCommMenuItem;
	};
};

//Function to apply any arguments to a commMenu item
TAG_fnc_updateCommMenuItem = {
	params[ "_item", "_args", [ "_menuID", -1 ] ];

	//Find the menu item index
	_menuIndex = if ( _menuID > -1 ) then {
		player getVariable "BIS_fnc_addCommMenuItem_menu" findIf{ _x select 0 isEqualTo _menuID };
	}else{
		missionNamespace getVariable[ "TAG_commMenuItems", [] ] findIf{ _x select 0 == _item };
	};

	//If found
	if ( _menuIndex > -1 ) then {

		//Custom for what menu item?
		switch ( toLower _item ) do {

			case ( "artillery" ) : {
				//Update artillery menu title
				player getVariable "BIS_fnc_addCommMenuItem_menu" select _menuIndex set[ 1, format[ "Artillery Strike $%1", _args ] ];
			};
		};

		//Update commMenu ( sets missionNamespace menu reference )
		[] call BIS_fnc_refreshCommMenu;
	};
};

//Where ever you want to add the comm menu item from

artilleryPrice = 200;
//If remote
[ "artillery", artilleryPrice ] remoteExec[ "TAG_fnc_addCommMenuItem", 0 ];
//If local
//[ "artillery", artilleryPrice ] call TAG_fnc_addCommMenuItem;


//When ever you want to update a comm menu item

artilleryPrice = 300;
//If remote
[ "artillery", artilleryPrice ] remoteExec[ "TAG_fnc_updateCommMenuItem", 0 ];
//If local
//[ "artillery", artilleryPrice ] call TAG_fnc_updateCommMenuItem;

 

Can be expanded upon, currently if you add a second commMenu item that is the same config name "artillery" as one already added, then only the first one would get updated by TAG_fnc_updateCommMenuItem if updating only. Unless you know and send its menu ID.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

@Larrow

Thanks for simplifying and explaining each step, this helps so much! I'm just starting to get my feet wet with some more advanced stuff and little things like this blow my mind lol. 

You're the best! 😁

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×