Jump to content
Sign in to follow this  
1para{god-father}

Count number of players at a location and distance

Recommended Posts

I would like to have my Base come under attack now and again but only if say 5 players are at base and say 50meters near marker "respawn_west" and have been there for say 10 min then spawn inf in then sleep for a random numer amount of time.

Any help would be most welcome !


while {true} do
{
waituntil {count playableUnits >= 5};  /// not sure hot to have distance to marker and make sure they been @ base for 10 min

			_distances = [90,120,150] call BIS_fnc_selectRandom;
			_ang = random 360;  	
			_dis = _distances; 
			_dx = sin(_ang)*_dis; 
			_dy = cos(_ang)*_dis; 
			_loc = [((getmarkerpos "respawn_west") select 0) + _dx, ((getmarkerpos "respawn_west") select 1) + _dy, 0];
                                 //////spawn in inf
			_grp1 = [_loc, EAST, (configFile >> "CfgGroups" >> "EAST" >> "INS" >> "Infantry" >> "INS_InfSquad")] call BIS_fnc_spawnGroup;

                              //////make them attack Base////
                              [_grp1,getmarkerpos "Respawn_west",70,"SAD", "AWARE", "RED","Normal","LINE", "_grp1 spawn CBA_fnc_searchNearby"] call CBA_fnc_addWaypoint;

			////wait 1 hour before espawn
  				sleep 3600;  
};

Share this post


Link to post
Share on other sites

You are not actually sleeping a random amount of time.

You cannot use local var names (_something) in waypoints like that. They need a global name. This could also be done very cleanly with a trigger however, here how a script that does the same could be made. This is untested by the way, however, it the syntax checks out according to squint.


private ["_timeArrivedInBase","_dist","_dir","_spawnPos","_group","_groupId","_groupVarName","_playersInBase","_baseRadius","_timeoutForAttack","_numPlayersNeeded"];

_timeArrivedInBase = time;
_baseRadius = 50;
_timeoutForAttack = 10*60;
_numPlayersNeeded = 5;
_groupId = 0;

while {true} do {
   sleep 5;
   _playersInBase = {isPlayer _x && _x distance (getMarkerPos "respawn_west") < _baseRadius} count playableUnits >= _numPlayersNeeded;
   //If players elsewhere reset timer.
   if (!_playersInBase) then {
       _timeArrivedInBase = time max _timeArrivedInBase;
   };
   //Time to attack?
   if ( (time - _timeArrivedInBase) > _timeoutForAttack ) then {
       _dist = 90 + random 60;
       _dir = random 360;
       _spawnPos = [getMarkerPos "respawn_west", _dist, _dir] call BIS_fnc_relPos;
       _group = [_spawnPos, east, (configFile >> "CfgGroups" >> "EAST" >> "INS" >> "Infantry" >> "INS_InfSquad")] call BIS_fnc_spawnGroup;
       _groupId = _groupId + 1;
       _groupVarName = format ["BaseAttackSqd_%1", _groupId];
       missionNameSpace setVariable [_groupVarName, _group];
       [_group, getMarkerPos "respawn_west", 70, "SAD", "AWARE", "RED", "Normal", "LINE", format ["%1 spawn CBA_fnc_searchNearby", _groupVarName]] call CBA_fnc_addWaypoint;
       //Don't allow another attack for at least 30 minutes - max 60
       _timeArrivedInBase = time + 30*60 + random (30 * 60);
   };
};

Share this post


Link to post
Share on other sites

Just saying: This can be done very easily with a trigger.

Set it to multiple activation by west presence and use this as condition:

{isPlayer _x} count thisList >= 5

Share this post


Link to post
Share on other sites
You are not actually sleeping a random amount of time.

You cannot use local var names (_something) in waypoints like that. They need a global name. This could also be done very cleanly with a trigger however, here how a script that does the same could be made. This is untested by the way, however, it the syntax checks out according to squint.


private ["_timeArrivedInBase","_dist","_dir","_spawnPos","_group","_groupId","_groupVarName","_playersInBase","_baseRadius","_timeoutForAttack","_numPlayersNeeded"];

_timeArrivedInBase = time;
_baseRadius = 50;
_timeoutForAttack = 10*60;
_numPlayersNeeded = 5;
_groupId = 0;

while {true} do {
   sleep 5;
   _playersInBase = {isPlayer _x && _x distance (getMarkerPos "respawn_west") < _baseRadius} count playableUnits >= _numPlayersNeeded;
   //If players elsewhere reset timer.
   if (!_playersInBase) then {
       _timeArrivedInBase = time max _timeArrivedInBase;
   };
   //Time to attack?
   if ( (time - _timeArrivedInBase) > _timeoutForAttack ) then {
       _dist = 90 + random 60;
       _dir = random 360;
       _spawnPos = [getMarkerPos "respawn_west", _dist, _dir] call BIS_fnc_relPos;
       _group = [_spawnPos, east, (configFile >> "CfgGroups" >> "EAST" >> "INS" >> "Infantry" >> "INS_InfSquad")] call BIS_fnc_spawnGroup;
       _groupId = _groupId + 1;
       _groupVarName = format ["BaseAttackSqd_%1", _groupId];
       missionNameSpace setVariable [_groupVarName, _group];
       [_group, getMarkerPos "respawn_west", 70, "SAD", "AWARE", "RED", "Normal", "LINE", format ["%1 spawn CBA_fnc_searchNearby", _groupVarName]] call CBA_fnc_addWaypoint;
       //Don't allow another attack for at least 30 minutes - max 60
       _timeArrivedInBase = time + 30*60 + random (30 * 60);
   };
};

That works great, still learning to code as you can see :)

The reason I did not use a trigger was because the Respawn point can move so I thought it would be easier to try via script!

Again many thanks !

Share this post


Link to post
Share on other sites

attachTo works with triggers, :D so moving them around is no problem at all.

Anyway... doesn't really matter. As long as it works as intended :)

Share this post


Link to post
Share on other sites

As I also said you could use a trigger. Just remember that you also has to implement it so that the enemy would not just attack 10 minutes constantly while at base. Meaning you had to include some kind of "&& attackAllowedAgain" and remember to switch this variable to false when creating a new attack and then setting it to true when enough time has passed. You have to create a second trigger to assist or set the attackAllowedAgain variable in init.sqf or something. It would still be a bit shorter than what I posted, but I like having each thing in a single place.

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  

×