Jump to content
avibird 1

Need help with cursorObject command to get a AI unit to join player group.

Recommended Posts

Can't get this to work using cursorObject command.

this addAction ["join us",{["cursorObject"isKindOf "Man,bob2"] join player;},nil,1.5,true,true,"","alive bob2",10];    

this addAction ["Dismiss",{["cursorObject","bob2"]join grpNull;},nil,1.5,true,true,"","alive bob2",10];

 

this code works fine without cursorObject command

this addAction ["join us",{[bob]join player;},nil,1.5,true,true,"","alive bob",2];    

this addAction ["Dismiss",{[bob]join grpNull;},nil,1.5,true,true,"","alive bob",2];

 

I am not getting errors but not working bob2 will not join lol.

 

 

The issues is with a undefined variable ie bob2

 

 

Share this post


Link to post
Share on other sites

Follow the syntax: addAction

If this is assumed to be for player unit, that can work in SP. For MP, the init field is not the best place to script and it's more work.

 

Quick and dirty:

this addAction ["join us",{[cursorObject] join player}, nil,1.5, TRUE,TRUE, "", "alive cursorObject && cursorObject isKindOf 'CAManBase' ",3,FALSE];
this addAction ["Dismiss",{[cursorObject] join grpNull}, nil,1.5, TRUE,TRUE, "", "alive cursorObject && cursorObject isKindOf 'CAManBase' ",3,FALSE];

 

Better:
 

player addAction ["<t color='#11ff11'>Join us</t>", {
  params ["","_caller","_id"];
  private _menu = (_caller actionParams _id) #0;
  if (_menu isEqualTo "<t color='#11ff11'>Join us</t>") then {
    _menu = "<t color='#ff1111'>Dismiss</t>";
    if (isNil {cursorObject getVariable "oldGrp"}) then {cursorObject setVariable ["oldGrp",group cursorObject]};
    [cursorObject] join _caller;
  } else {
    _menu = "<t color='#11ff11'>Join us</t>";
    [cursorObject] join (cursorObject getVariable ["oldGrp",grpNull]);
  };
  _caller setUserActionText [_id,_menu];
},nil,1.5,true,true,""," cursorObject isKindOf 'CAManBase' && {_this distanceSqr cursorObject < 4} && {alive cursorObject}"];

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Hey thanks for all the help and feed back on scripting. Question what to you mean player unit. This mission is for coop mission not really join in progress. It has 20 playable units with team switch enabled. Divided up into two squads of 10 they can be subdivided into six groups or into one large size group of 20 playable units this is all done through radio commands. So in theory best played alone two players or six players. 

 

This code is for two alien hostages that are in prison cells in the research facility you can rescue them and have them assist you in the mission.

 

The ultimate goal is to get a working script that  you can recruit any bluefor unit into a player group by using cursorobject command when anyone see a downed pilot during the mission from CAS vehicles that you can call in during the mission. I hope you understand what I'm trying to do.

Share this post


Link to post
Share on other sites

@pierremgi thank you both work well.  What is the best way to add to my mission the better player addaction code you provided.  Mission init.sqf  initserver.sqf or initplayerlocal .sqf. 

 

Is there a way to increase the number of units the player can have join using this code like 5 or 6 different units avibird 

Share this post


Link to post
Share on other sites

@pierremgi I think I am going to use both ways in this my mission the quick and dirty way will be used for the POW and the two alien captives works well for rescue the Code right in the unit init. While your more elaborate way will be used in a radio trigger to call the code. Only the two squad leaders and four team leaders can use it to recruit downed air units that were called in for CAS or transport. This works out well and almost meets all of my scenario needs. I really do appreciate it. Come stop by and see some of your work in action.Thanks Avibird. 

Share this post


Link to post
Share on other sites

OK I am very satisfield with the outcome of this. If anyone is following  this post. there are three options for this to work and I am using all three.

 

 option 1

*addAction to unit init
 this addAction ["join us",{[VIP]join player;},nil,1.5,true,true,"", "alive VIP",2]; this addAction ["Dismiss",{[VIP]join grpNull;} ,nil,1.5,true,true,"","alive VIP",2]; - this is used for a scientist you need to rescue and evac out of the area.

 

option 2

*addAction to unit init

this addAction ["HELP US",{[cursorObject] join group player}, nil,1.5,TRUE,TRUE,"","alive cursorObject && cursorObject isKindOf 'CAManBase'",3,FALSE];
 this addAction ["LEAVE US",{[cursorObject] join grpNull}, nil,1.5, TRUE,TRUE,"","alive cursorObject && cursorObject isKindOf 'CAManBase' ",3,FALSE]; - this is used for  alien hostages that you have the option to free them, leave them in the prison cell or have the join your side but if you just free them there is a chance of them killing you lol.

 

option 3

*Radio trigger - Battlefield Recruitment-  this is used for any air units that are shoot down in the OA. You could have them join and fight with your group or just leave them on their own to fight.  
Condition
call{player == TC || player == P4 || player == P8 || player == P11 || player == P14 || player == P18}

On activation
player addAction ["<t color='#11ff11'>Join us</t>", {params ["","_caller","_id"];private _menu = (_caller actionParams _id) #0; if (_menu isEqualTo "<t color='#11ff11'>Join us</t>") then { _menu = "<t color='#ff1111'>Dismiss</t>";
if (isNil {cursorObject getVariable "oldGrp"}) then {cursorObject setVariable ["oldGrp",group cursorObject]};[cursorObject] join _caller;} else { _menu = "<t color='#11ff11'>Join us</t>";
[cursorObject] join (cursorObject getVariable ["oldGrp",grpNull]);};
_caller setUserActionText [_id,_menu];},nil,1.5,true,true,""," cursorObject isKindOf 'CAManBase' && {_this distanceSqr cursorObject < 100} && {alive cursorObject}"];

 

*For some reason I can't get the cursorObject distance more then 15 meters regardless of how much distance parameters into the code. I don't know if it has a hard limit of distance -  {_this distanceSqr cursorObject < 100}

Share this post


Link to post
Share on other sites

First of all, it's always better to addAction from an object or a specific AI (target) instead of the player himself (target and caller in fact, as above), because the condition is always checked on the player and depends on the distance (engine hard coded) on an object or AI.

So, if you have to free / recruit  specific units, addAction on them. If you want the player(s) able to recruit any (some) units, addAction on player(s) as an extra menu for this behavior but choose carefully your condition (as said always checked).

 

Well, in MP, you often need some extra lines.

And think about : locality (run the addAction for player(s) and run its code where needed for (all) the commands you are using inside).

Here, using join command only, as join is GA GE, it's OK. But setUserActionText is GA GE, so effect (menu text) will stay local if you don't  remoteExec this command! (intended or not?)

 

So, for recruit on specific units, add this code in init field of the two units, like you did:

this addAction ["<t color='#11ff11'>Join us</t>", {
  params ["_tgt","_plyr","_id"];
  private _menu = (_tgt actionParams _id) #0;
  if (_menu isEqualTo "<t color='#11ff11'>Join us</t>") then {
    _menu = "<t color='#ff1111'>Dismiss</t>";
    if (isNil {_tgt getVariable "oldGrp"}) then {_tgt setVariable ["oldGrp",group _tgt,TRUE]};
    [_tgt] join _plyr;
  } else {
    _menu = "<t color='#11ff11'>Join us</t>";
    [_tgt] join (_tgt getVariable ["oldGrp",grpNull]);
  };
  [_tgt,[_id,_menu]] remoteExec ["setUserActionText",0,_tgt];
},nil,1.5,true,true,"","alive _target",2];

 

With this code, any player can recruit or dismiss the AI. It's an example for sharing an action menu. If you don't need to dismiss it, make it simpler.

 

 

For recruiting any unit by... any player in MP? it's a little bit more tricky. Just a point, I guess you don't want another player recruit an AI (or another player!) if already in a player's group...

and recruit only units on your side...

and why not an action dismissing units already in your group at start...

and think about respawning player....

 

The final condition is on your side.

Spoiler

As you can see below, I wrote an "each framed" code (like onEachFrame EH) inside the condition (so updated each frame), but the condition MUST end by a boolean. This way, the action menu depends on and is set for the target, belonging or not to the player's group.

 

In initPlayerLocal.sqf:

 

AVI_recruitAction = ["Join us",
  {   
    params ["_player", "_caller", "_id"];   
    _ActMenu = (_player actionParams _id) #0;   
    if (_ActMenu isEqualTo "Join us") then {
      if (isNil {cursorTarget getVariable "oldGrp"}) then {   
        cursorTarget setVariable ["oldGrp",group cursorTarget,TRUE];
      };
      [cursorTarget] join _player;   
    } else {   
      [cursorTarget] join (cursorTarget getVariable ["oldGrp", grpNull]);   
    };   
  }, nil, 1.5, true, true, "", "_this setUserActionText [_actionId,['Dismiss','Join us'] select (group cursorTarget != group _this)]; side cursorTarget == playerSide && {cursorTarget distanceSqr _this < 4} && {(_this actionParams _actionId)#0 == 'Dismiss' or units cursorTarget findIf {isPlayer _x} ==-1}"
];
 
player addAction AVI_recruitAction;
player addEventHandler ["respawn", {
  params ["_plyr", "_corpse"];
  _plyr addAction AVI_recruitAction;
  removeAllActions _corpse
}];

 

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

@pierremgi I am taking the family on vacation when I get back will check out the new code suggestions you posted. Thank you for the assist. I test played this mission it took me over 2 hours but I completed the mission and all work will the other codes. The scientist and the aliens are not playable units. I have a few questions to ask you about addaction on object vs unit vs radio/area trigger. Talk soon thanks avibird

 

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

×