Jump to content

Recommended Posts

I recently found a code snippet here on the forums that allows the player to recruit individual AI via the addAction menu and the HoldAction function.  Here's the code (sorry, I forgot who initially posted this) that's being fired in the initPlayerLocal file:

 

[player, "Recruit Unit",
    "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",
    "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",
    "side cursorTarget == side _this && cursorTarget distance _this < 3 && group cursorTarget != group _this", "alive cursorTarget",{},{},{
    params ["_target", "_caller", "_actionId", "_arguments"];
    [cursorTarget] join _target;
},{},[],2,0,false,true] call BIS_fnc_holdActionAdd;

 

The issue I'm having is that it's giving me an error stating there's an invalid number, Line 7.  The script then continues to work fine in the mission (other than it also giving me the option to recruit unmanned vehicles/objects).  I'm just trying to clean it up so I don't get the initial error at the start of the mission.

 

Other than the params, it seems like everything is formatted correctly per the Biki.  Any help?

Share this post


Link to post
Share on other sites

Hi. You had a invisible character at the end of the script. To check it, you have to use either some editor that supports showing invisible characters or you can paste it here in the code window and the place where such character is located is usually marked with red dot 🔴 . That sometimes happens when you copy paste code from elsewhere.
So if you want to use the original code, just delete the invisible character at the end. (...call BIS_fnc_holdActionAdd;🔴)

To make it more useful, I added some stuff to the code. Depends entirely on you if you want to use them or not.
I further optimized the condition and added lazy evaluation. That means that condition doesn't have to be evaluated further when the condition would return FALSE at some point and thus could not return TRUE at the end. If you wish to know more about lazy evaluation, read Code Optimization page.
To further solve the problem with recruiting unmanned vehicles I also added the condition that should check if vehicle has some alive friendly units inside.
Then ,because vehicles are also possible to recruit, I changed activation code, so instead of single unit you will recruit whole group. That's because previous code only recruited the commander of the vehicle and I think that's not intended behaviour. If you want to change that to previous behaviour, because you need only single units to be recruited instead, simply replace what I did.
Also I changed the activation distance, if the unit is a man then action will be showed at 3 meters from him, if it's a vehicle, then the action will be showed at 7 meters, because vehicles are usually bigger and at 3 meters the action would not be shown. Priority has also been changed, so the action is now visible immediately after you approach the unit.
When i tested it I also noticed that if you recruit friendly UAV vehicle, you can totally break its behaviour when you order the AI to dismount 😂, so I added another check and forbid recruiting UAVs as well.

[player, "Recruit Unit",       
    "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",       
    "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",       
    "side cursorTarget isEqualTo side _this && {cursorTarget distance _this < ([7,3] select (cursorTarget isKindOf 'Man')) && {group cursorTarget isNotEqualTo group _this && {(cursorTarget isKindOf 'Man' OR {({alive _x} count (crew cursorTarget)) > 0}) AND {!unitIsUAV cursorTarget}}}}", "alive cursorTarget",{},{},{       
    params ["_target", "_caller", "_actionId", "_arguments"];       
    units group cursorTarget join _target;       
},{},[],2,12,false,true] call BIS_fnc_holdActionAdd;

 

  • Thanks 1

Share this post


Link to post
Share on other sites

8p369a.jpg

 

Thank you @soldierXXXX .  I swear I looked for hidden characters, but I apparently missed it.  Works great now.  I removed the "units group" addition because I was trying to specifically just recruit one unit at a time.  Obviously that's problematic for a vehicle, but that's not the focus of the mission.

 

Also, thanks for adjusting the priority.  I hadn't had a chance to play with it to see where the sweet spot lies, but your fix works great.

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

×