Jump to content
Sign in to follow this  
sproyd

Help creating Custom Communication menu

Recommended Posts

So I want to add a custom communication menu item, which I have managed to do using the wiki pages here and here.

However, I'm confused as to how I get this communication item to execute a custom script. Whenever I put any code in the expression field I get CTD and error messages. How do I get the comm menu to execute regular code?

Thanks

class CfgCommunicationMenu
{
   class myRadio1
   {
       text = "Radio Alexandros"; // Text displayed in the menu and in a notification
       submenu = ""; // Submenu opened upon activation (expression is ignored when submenu is not empty.)
       expression = "[b][color="#FF0000"]THIS IS THE BIT THAT THROWS UP ERRORS, HOW THE HECK DO I GET IT TO BEHAVE[/color][/b]"; // Code executed upon activation
       icon = "\a3\Ui_f\data\GUI\Cfg\CommunicationMenu\call_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 = 0; // 1 to remove the item after calling
   };
};

Share this post


Link to post
Share on other sites

Maybe you could show us the code that throws the errors?

Here's one i use in a mission and it works flawless:

class CfgCommunicationMenu
{
   class moveTemplar
   {
       text = "Move Templar"; // Text displayed in the menu and in a notification
       expression = "nul = [player, (group gomez), 'mMoveTemplar'] spawn IP_MOVEGROUP;"; // Code executed upon activation
       icon = "\a3\ui_f\data\map\markers\nato\b_inf.paa"; // Icon displayed permanently next to the command menu
       removeAfterExpressionCall = 0; // 1 to remove the item after calling
   };
};

---------- Post added at 02:13 PM ---------- Previous post was at 02:11 PM ----------

Oh, and for example i had CTDs when i tried to pass strings in the expression field like this: "mMoveTemplar". Changing it to 'mMoveTemplar' worked for me.

Share this post


Link to post
Share on other sites

It won't bloody work, even passing strings with single apostrophes instead of quotations. Here is the full code

class CfgCommunicationMenu
{
   class myRadio1
   {
       text = "Radio Alexandros"; // Text displayed in the menu and in a notification
       expression = "howfaraway = charles distance alexandros; howfaraway = howfaraway / 50; howfaraway = ceil howfaraway; howfaraway = howfaraway * 50; charles sideChat 'Radio: Alex, I'm at the RV, where are you?'; alexandros sideChat format ['Radio: I'm on the way - about %1 metres from your position. Hold tight.', str(howfaraway)];"; // Code executed upon activation
       icon = "\a3\Ui_f\data\GUI\Cfg\CommunicationMenu\call_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 = 0; // 1 to remove the item after calling
   };
};     

and to add to the player's init line or init.sqf

[player,"myRadio1"] call BIS_fnc_addCommMenuItem;

Edit: however using hint str(howfaraway) instead of using sideChat works fine. It won't let me pass strings within a string anyone got a fix?

Edited by sproyd

Share this post


Link to post
Share on other sites

I'd suggest you put your code into a separate script and just have

expression = "nul = [] execVM 'myScript.sqf'";

there.

Share this post


Link to post
Share on other sites

what ^ he said... or at the least enclose your statements inside a "nul = [] spawn {}" construct... some expressions expect code and some expect strings.. and some of them expect a filename. So I think your inline code is the problem.

Share this post


Link to post
Share on other sites

You have single apostrophes in your text (I'm) which will end the text line causing the script line to fail.

It also does not seem to like the format text in that expression line.

WORKING : -

expression = "charles sideChat ""Radio: Alex, I'm at the RV, where are you?""; alexandros sideChat ""Radio: I'm on the way - about "" + str((ceil((charles distance alexandros)/50))*50) + "" metres from your position. Hold tight."";";

As the other say place all that in a separate script and just call it from the expression line.

Edited by Larrow

Share this post


Link to post
Share on other sites

Cheers guys calling in the script worked. However, I'm having issues removing the comm menu item. I mean once I leave the area it throws up an error even using BIS's example from here.

I use this to add the radio

_supportRadio = [player,"myRadio1"] call BIS_fnc_addCommMenuItem; 

and this to remove it

[player,_supportRadio] call  BIS_fnc_removeCommMenuItem;

It throws up "Item -1 not found in the comm menu. "

however this works... once. but not when the radio is subsequently added again (the next time I have to use 2 and so on)

[player,1] call  BIS_fnc_removeCommMenuItem

Any ideas how I can have it so that the radio will reliably add and remove upon entering and exiting an area? At the moment the radio will not remove and when re-entering the area new radio menu items just stack up.

Share this post


Link to post
Share on other sites

Works fine here! :/.

If you are receiving -1 in _supportRadio back from the addCommMenuItem then you have a problem somewhere as -1 means that it failed (either cfg class not found, already have max 10 items in your comms menu, or an internal error in the script - trying to add a menu at an already take slot)

________________

Where are you calling the remove from ?

Is the local variable _supportRadio still in scope?

I just tried calling

[player,nil] call BIS_fnc_removeCommMenuItem;

and it fails with the -1 message.

Nil in this call is what would be happening if your _supportRadio is unknown/out of scope.

Edited by Larrow

Share this post


Link to post
Share on other sites

________________

Where are you calling the remove from ?

Is the local variable _supportRadio still in scope?

I have a simple trigger zone (that can be repeatedly triggered), whereby when the grouped vehicle (the player) is present the comm item gets added and in the deactivation field for the trigger it gets removed. The same applies though if I try it in the Local Exec field.

The idea is - the player in zone - he can use radio, the player out of zone - no radio.

Share this post


Link to post
Share on other sites

The OnAct and DeAct fields of a trigger are two different scopes, a local variable in the OnAct will be undefined in the DeAct.

I do not even understand how your able to run code with a local variable from the OnAct or DeAct as it should just complain in the editor of 'local variable in global scope' and not allow you to add it.

Anyway heres a quick example mission of a trigger that is grouped to the player, enter the hanger and you will be given your commMenu item, leave the hanger and the commMenu item will be removed.

Hope that helps. If not maybe put up an example of what you actually have so we can work out whats happening.

Share this post


Link to post
Share on other sites

@Larrow thanks mate you are a champion, I was calling scripts from the onAct and DeAct fields but when I actually put the code in the trigger box its now workign (thanks for your example mission).

Case closed - mission (Chain Reaction) shortly to be updated.

THANKS EVERYONE!!

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
Sign in to follow this  

×