Jump to content
Sign in to follow this  
fatty86

Checking if any human players are in a group - even if the group doesn't exist?

Recommended Posts

Hi guys,

Let me first explain what I am trying to do. I want a multiplayer mission to scale difficulty based on what assets are occupied by human players.

I have a group of playables in Charlie team, each with the following code in their init fields:

c_grp = group this;
c_grp setGroupId ["Charlie"];

In init.sqf, I have this:

	if (({isPlayer _x} count units c_grp) = 0) then {
	{deleteVehicle _x} forEach units group infreinf1;
	{deleteVehicle _x} forEach units group infreinf2;
	{deleteVehicle _x} forEach units group infreinf3;
	{deleteVehicle _x} forEach units group infreinf4;
};

This works perfectly if the game is run with no players occupying those slots - the units are deleted as desired. It also works terrific if a player is in the group - the extra groups stay and the team encounters some extra resistance.

The problem I am encountering, is that if the admin DISABLES the AI in those slots, the script will error out as "c_grp" is not an existing group, and the reinforcing units are not deleted.

So, I tried a different approach: if any players are detected in the group, do nothing. Else, the default behaviour will be to delete the reinforcing units.

	if (({isPlayer _x} count units c_grp) >= 1) then {} else {
	{deleteVehicle _x} forEach units group infreinf1;
	{deleteVehicle _x} forEach units group infreinf2;
	{deleteVehicle _x} forEach units group infreinf3;
	{deleteVehicle _x} forEach units group infreinf4;
};

Same result with the error.

Any thoughts on how I can get this 'if' check to work even if the AI units are disabled and "c_grp" doesn't exist?

Share this post


Link to post
Share on other sites

Use an isnil if:

if (isnil "c_grp") then {
 // group doesnt exists

Or other way with !isnil

Share this post


Link to post
Share on other sites

Using your first post for code.

if (!isNil "c_grp") then {
   if (({isPlayer _x} count units c_grp) [color="Red"]=[/color]= 0) then {
       {deleteVehicle _x} forEach units group infreinf1;
       {deleteVehicle _x} forEach units group infreinf2;
       {deleteVehicle _x} forEach units group infreinf3;
       {deleteVehicle _x} forEach units group infreinf4;
   };  
};

Checks to make sure the group is not nil, then checks to see if anybody is in group c_grp.

Share this post


Link to post
Share on other sites

Hi,

Checking if variable c_grp exist:

!isNil { c_grp }

Checking if the group c_grp exists:

!isNull c_grp

_neo_

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  

×