Jump to content
Sign in to follow this  
SpaydCBR

How to check if unit is part of specific group?

Recommended Posts

This seems like it should be easy but there doesn't seem to be a way to do it.

 

Basically I was to set up a vehicle to be an infantry respawn position ONLY for members of a certain group, so each group gets their own assigned vehicle that only they can respawn at.

 

This seems to work:

[group player, _veh] call BIS_fnc_addRespawnPosition;

But how do I do it if I want it to be a specific group and not necessarily the players'?

 

If, for example, I have a group called B Alpha 1-1 (default group name for first group in editor). Then how do I check if some player is in group B Alpha 1-1, and how would I use B Alpha 1-1 as the first parameter in the addRespawnPosition function call?

 

Doing

if (group player == "B Alpha 1-1") then {...};

doesn't work because I guess you can't compare groups with strings, but removing the quotes also obviously doesn't work either.

 

I tried using groupID but that just returns a string and not a group.

 

So how do I simply check if a unit is in a specific group, so I can make a specific vehicle be a respawn position for a specific group?

Share this post


Link to post
Share on other sites

hmm, idk if i understand what u want but if u do

_grp_plyr = group player;

then u ve stored players group in that variable and u can compare it with other groups and u can use that variable in BIS_fnc_addRespawnPosition.

 

If thats not the info u need, then u have to be more specific what u want compare. the info from ur post let me think that u want compare the players group with itsself. idk

Share this post


Link to post
Share on other sites

Thanks for the response. I've edited my post to hopefully make it more clear.

 

Basically, if I have a known group name (B Alpha 1-1), how do I check if a player is in that group? (How do I check player is in group B Alpha 1-1)

Share this post


Link to post
Share on other sites
_name = groupId (group player);

if (_name== "B Alpha 1-1") then {...};

or

if ( groupId (group player) == "B Alpha 1-1") then {...};

Share this post


Link to post
Share on other sites

IIRC you can sync a group to a spawn position module changing how it works from the settings of the module itself so that only that group sees it.

 

But that won't work if you're spawning the group from a script. But if you're spawning a group from a script, you could use a switch/if to check if the person is part of that group by naming the group when you make it.

Share this post


Link to post
Share on other sites

I tried groupID before, but it won't work since I need to put a group type in the function call.

 

I also tried syncing the module to the group and that didn't seem to work either :(

 

There doesn't seem to be an "easy" way to do this. So I came up with an ugly workaround.

 

I added a "crewed" vehicle, grouped it to the respective group, and called the following in its init

//Get group of the vehicle
_vehGroup = group _this;

//Delete crew
{
	deleteVehicle _x;
} forEach crew _this;

//Set up infantry respawn for this group
[_vehGroup, _this] call BIS_fnc_addRespawnPosition;
[_this,5,0,-1,{},0,2,1,true,true,0,false] call BIS_fnc_moduleRespawnVehicle;

Seems to work just fine, but I don't like it. Is there a more "graceful" way to do this?

Share this post


Link to post
Share on other sites

I dont get the point. Your workaround creates a vehicle to have a group which u then add that respawn thing? createGroup should be easier.  Maybe u should show more of ur script but I try it again:

if ( groupId (group player) == "B Alpha 1-1") then 
{
 [group player, _veh] call BIS_fnc_addRespawnPosition;
};
I thought u look for that way.

Share this post


Link to post
Share on other sites

Thanks for your responses sarogahtyp.

 

The full idea is this: In my mission I have 2 teams (BLUFOR and OPFOR. All human players) with 4 squads of 8 (B Alpha 1-1, O Alpha 1-1, etc) on EACH team. I want each squad to get their own set of 2 transport vehicles that only members of that squad can use as a respawn position.

 

I'm not an expert in scripting, so correct me if I'm wrong. I think if I do it your way then every client would have to run the code locally to work correct, because only client knows what 'player' is? I was hoping I could run this only on server since it's supposedly better, and to do that I would need to get a reference to all the groups somehow. I know my code doesn't run on server yet, but I believe I can make it run on server and should still work I think.

 

Should I create the groups in a script instead of placing them in the editor, so I can save the groups in variables? Would they still be "joinable" if I do it that way?

Share this post


Link to post
Share on other sites
_unit = _this param [0,objnull,[objnull]];
if (isNull _unit) exitWith {grpNull;};

_playerGroup = grpNull;
_allGroups = allGroups;
{
  if (_unit in (units _x)) exitWith {
    _playerGroup = _x;
  };
} foreach _allGroups;

// return - can return a "null" value
_playerGroup;

(code not tested)

 

 

Regards,

Bull

Share this post


Link to post
Share on other sites

Hmm, I think u cant get the Group from the Group ID. But you can do another way I think.

You could Group your probably empty respawn vehicles with the related Group at editor and then you can do that stuff on Server:

 [group _veh, _veh] call BIS_fnc_addRespawnPosition; 

Share this post


Link to post
Share on other sites

@sarogahtyp

That's exactly what I did in post #6 :)

You can't actually group a squad with an empty vehicle (didn't work when I tried at least), so I used a crewed vehicle, grouped it, got the group name from it, then deleted the crew before calling the addRespawnPosition function on the vehicle.

 

@bull_a

Interesting. Not exactly what I'm looking for, but that's my bad. The question is more about how to call the addRespawnPosition for a specific group and not exactly how to check if a unit is part of a specific group. I just asked that because I thought if I knew how to check if a unit is in a specific group then I'd know how to call the function, and wanted to keep the question simple, but I think I just confused everybody haha. I think your code needs an actual unit, but that might not necessarily exist (maybe no players join one squad) so I don't think that code helps me. The allGroups command does sound like something I could use though so this code could be slightly modified for what I want (just call the function for all groups), so thank you! Sometimes it's hard to find what commands are out there in the wiki. I tried using 'group' and 'Group' as keywords in the search but 'allGroups' never showed up. Maybe I should be using Ctrl+F in the commands page instead :)

Share this post


Link to post
Share on other sites

@sarogahtyp

That's exactly what I did in post #6 :)

You can't actually group a squad with an empty vehicle (didn't work when I tried at least), so I used a crewed vehicle, grouped it, got the group name from it, then deleted the crew before calling the addRespawnPosition function on the vehicle.

May be addVehicle is your friend then :-)

edit: that was nonsense...

Edited by sarogahtyp

Share this post


Link to post
Share on other sites

name 1 player of each group e.g. man42 and do this for each of those named players on server:

[group man42, _veh] call BIS_fnc_addRespawnPosition;

i think that should solve it finally

Share this post


Link to post
Share on other sites

@sarogahtyp

That's exactly what I did in post #6 :)

You can't actually group a squad with an empty vehicle (didn't work when I tried at least), so I used a crewed vehicle, grouped it, got the group name from it, then deleted the crew before calling the addRespawnPosition function on the vehicle.

 

@bull_a

Interesting. Not exactly what I'm looking for, but that's my bad. The question is more about how to call the addRespawnPosition for a specific group and not exactly how to check if a unit is part of a specific group. I just asked that because I thought if I knew how to check if a unit is in a specific group then I'd know how to call the function, and wanted to keep the question simple, but I think I just confused everybody haha. I think your code needs an actual unit, but that might not necessarily exist (maybe no players join one squad) so I don't think that code helps me. The allGroups command does sound like something I could use though so this code could be slightly modified for what I want (just call the function for all groups), so thank you! Sometimes it's hard to find what commands are out there in the wiki. I tried using 'group' and 'Group' as keywords in the search but 'allGroups' never showed up. Maybe I should be using Ctrl+F in the commands page instead :)

 

Ctrl+F is very usefull: https://community.bistudio.com/wiki/allGroups

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  

×