Announcement

Collapse
No announcement yet.

Random Patrols - as is in the Insurgency Mission

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Random Patrols - as is in the Insurgency Mission

    I first create an object in the editor such as a pencil or something small and name it "eiSpawn". This is where the leader for each group will first spawn in and is then moved to the random position. The rest of the group will spawn on the leader once he is moved.

    In the description.ext:
    Code:
    class Params
    {
    	class DetRng
    	{
    		title = "Active Area Detection Range";
    		texts[] = {"300m","400m","500m","600m","750m","1000m","1250m","1500m"};
    		values[] = {300,400,500,600,750,1000,1250,1500};
    		default = 600; //600 meters seems to be the optimal range.
    	};
            class UnkPatrols
    	{
    		title = "Unks Additional Enemy Patrols";
    		texts[] = {"On","Off"};
    		values[] = {1,0};
    		default = 1;
    	};
    };
    Then in the init.sqf:
    Code:
    if (isServer) then {_handle4 = []execVM "Unk\Patrol\patrolMonitor.sqf";};
    In your mission folder in Unk\Patrols make the following two files:
    patrolMonitor.sqf
    Code:
    //patrolMonitor.sqf
    //started in initServer.sqf
    //purpose: to add more random patrols to the mission
    
    _run = true;
    _playerArray = [];
    _randomPlayer = 0;
    unk_patrolStatus = "notActive";
    publicVariable "unk_patrolStatus";
    
    _unk_patrolEnabled = "UnkPatrols" call BIS_fnc_getParamValue; //get if Unk Patrols is turned on or off from the parameters
    if (_unk_patrolEnabled == 0) exitWith {_run = false;}; //exit this script if turned off
    
    sleep 60;
    
    while {_run} do
    {
    	if (unk_patrolStatus == "notActive") then
    	{
    		//sleep a random amount of time before spawning in each random patrol
    		sleep ((random 300) + 300); //5 mins plus up to 5 mins
    		_doPatrol = round random 10;
    		if (_doPatrol > 3) then
    		{
    			if (count playableUnits >= 1) then
    			{
    				_handle = []execVM "Unk\Patrol\spawnPatrol.sqf";
    				unk_patrolStatus = "active";
    				publicVariable "unk_patrolStatus";
    			} else {
    				sleep 120; //sleep for 2 mins if no players on the server
    			};
    		};
    	};
    	sleep 30;
    };
    spawnPatrol.sqf
    Code:
    //spawnPatrol.sqf - to spawn an instance of a random patrol, set waypoints and behavior, monitor for deactivation and delete units when area clear of players
    
    //player groupChat "spawnPatrol.sqf is running...";
    
    private ["_arrayPlayers","_numberOfPlayers","_targetPlayer","_patrolNumberOfAdditionalUnits","_fNumber","_unit","_targetEIgroup","_patrolArray","_largestAllowableDistance","_checkInTime","_wpIncrement","_smallestDistance","_patrolAlive"];
    _patrolAlive = false;
    private "_spawnDist";
    _spawnDist = "DetRng" call BIS_fnc_getParamValue;
    private "_run";
    _run = true;
    private "_possibleUnits";
    _possibleUnits = ["I_G_Soldier_F","I_G_Soldier_lite_F","I_G_Soldier_SL_F","I_G_Soldier_TL_F","I_G_Soldier_AR_F","I_G_medic_F","I_G_engineer_F","I_G_Soldier_exp_F","I_G_Soldier_GL_F","I_G_Soldier_M_F","I_G_Soldier_LAT_F","I_G_Soldier_A_F"];
    _patrolGoals = ["SAD","MOVE"];
    _patrolSpeeds = ["LIMITED","NORMAL","FULL"];
    
    
    //choose a random player to be the target
    _arrayPlayers = playableUnits;
    _numberOfPlayers = count _arrayPlayers;
    _targetPlayer = _arrayPlayers select (floor random _numberOfPlayers);
    
    private "_groupDirection";
    _groupDirection = floor random 360;
    
    _targetEIgroup = createGroup resistance;
    _unitOne = _targetEIgroup createUnit ["I_G_Soldier_SL_F", position eiSpawn, [], 0, "FORM"]; //eiSpawn is an editable object placed on map out of the way
    sleep 2;
    _unitOne SetPos [(getPos _targetPlayer select 0)-(_spawnDist * 1.5)*sin(_groupDirection),(getPos _targetPlayer select 1)-(_spawnDist *1.5)*cos(_groupDirection),+0];
    sleep 2;
    
    //caclulate patrol strength
    _patrolNumberOfAdditionalUnits = 1;
    if (_numberOfPlayers > 4) then
    {
    	_fNumber = (floor random [1,5,10]) * .1;
    	_patrolNumberOfAdditionalUnits = round (_numberOfPlayers * _fNumber);
    	if (_patrolNumberOfAdditionalUnits > 7) then {_patrolNumberOfAdditionalUnits = 7;};
    };
    
    for "_i" from 1 to _patrolNumberOfAdditionalUnits do
    {
    	_unit = _targetEIgroup createUnit [(_possibleUnits select (floor random (count _possibleUnits))), (position (_unitOne)) , [], 0, "FORM"];
    };
    sleep 2;
    _patrolArray = units _targetEIgroup;
    patrolUnits = _patrolArray;
    publicVariable "patrolUnits"; //comment out after debugging
    
    wpp =_targetEIgroup addwaypoint [getPos _targetPlayer,250];
    wpp setWaypointType "SAD";
    wpp setWaypointSpeed "FULL";
    
    _largestAllowableDistance = _spawnDist * 2;
    _checkInTime = time; //to adjust patrol waypoints if they live long enough
    _wpIncrement = 0;
    
    
    while {_run} do
    {
    	//player groupChat "spawnPatrol.sqf is looping...";
    	// CHECK IF PATROL IS DEAD THEN DEACTIVATE THIS SCRIPT
    	_patrolAlive = false;
    	{
    		if (alive _x) then {_patrolAlive = true;};
    	}forEach patrolUnits;
    	
    	if !(_patrolAlive) then
    	{
    		unk_patrolStatus = "notActive";
    		publicVariable "unk_patrolStatus";
    		_run = false;
    		//player groupChat "patrol is dead - stopping spawnPatrol.sqf";
    	};
    	
    	//CHECK IF PATROL IS TOO FAR FROM ANY PLAYABLE UNITS DELETE THEM AND DEACTIVATE THIS SCRIPT
    	_smallestDistance = 25000;
    	{
    		_currentPlayer = _x;
    		{
    			_distanceChecked = _x distance _currentPlayer;
    			if (_distanceChecked < _smallestDistance) then {_smallestDistance = _distanceChecked;}; 
    		}forEach _patrolArray;
    	}forEach playableUnits;
    	
    	if (_smallestDistance > _largestAllowableDistance) then
    	{
    		{
    			deleteVehicle _x;
    		}forEach _patrolArray;
    		unk_patrolStatus = "notActive";
    		publicVariable "unk_patrolStatus";
    		_run = false;
    		//player groupChat "patrol is too far away - stopping spawnPatrol.sqf";
    	} else {
    		//player groupChat format ["patrol is %1m from players", _smallestDistance];
    	};
    	
    	//CHECK TO SEE IF PATROL IS IN DEEP WATER AND IF SO DELETE AND RESTART
    	if (getPosATL (patrolUnits select 0) select 2 > 5) then
    	{
    		if (round (getPosASL (patrolUnits select 0) select 2) == -2) then
    		{
    			{
    				deleteVehicle _x;
    			}forEach patrolUnits;
    			unk_patrolStatus = "notActive";
    			publicVariable "unk_patrolStatus";
    			_run = false;
    			//player groupChat "patrol is in deep water - stopping spawnPatrol.sqf";
    		};
    	};
    	
    	sleep 20;
    	//ADJUST PATROL WAYPOINT IF THEY HAVE LIVED LONG ENOUGH AND ARE STILL CLOSE TO PLAYERS
    	if (time > (_checkInTime + 300)) then
    	{
    		//wpp = format ["wpp%1", (_wpIncrement + 1)];
    		//wpp =_targetEIgroup addwaypoint [getPos ((leader _targetEIgroup) findNearestEnemy (leader _targetEIgroup)),50];
    		{
    			(leader _targetEIgroup) reveal _x;
    		}forEach playableUnits;
    		sleep 1;
    		wpp setWaypointPosition [getPos ((leader _targetEIgroup) findNearestEnemy (leader _targetEIgroup)),50];
    		_nextWppType = floor random (count _patrolGoals);
    		sleep 2;
    		wpp setWaypointType (str _nextWppType);
    		_nextWppSpeed = floor random (count _patrolSpeeds);
    		sleep 2;
    		wpp setWaypointSpeed (str _nextWppSpeed);
    		_checkInTime = time;
    		//player groupChat "patrol wpp reset";
    	};
    	sleep 10;
    };
    |TG-189th| Unkl
    ArmA 3 Game Officer
    Dean of Tactical Gamer University
    189th Infantry Brigade Member
    SUBMIT A RIBBON NOMINATION OR CONTACT AN ARMA ADMIN
    "We quickly advance in the opposite direction and take cover in a house on the SW side of town." - BadStache

  • #2
    Re: Random Patrols - as is in the Insurgency Mission

    I shall test this out on my third Joint OPS mission. I am using UPSMON at the moment but am happy to try inhouse scripting first.

    Current ARMA Development Project: No Current Project

    "An infantryman needs a leader to be the standard against which he can judge all soldiers."

    Friend of |TG| Chief

    Comment


    • #3
      Re: Random Patrols - as is in the Insurgency Mission

      Everytime I see UPSMON I can't help but think about package delivery in Montego.
      sigpic
      |TG-1st|Grunt
      ARMA Admin (retired)
      Pathfinder-Spartan 5

      Comment

      Connect

      Collapse

      TeamSpeak 3 Server

      Collapse

      Advertisement

      Collapse

      Twitter Feed

      Collapse

      Working...
      X