Jump to content
Sign in to follow this  
sabot10.5mm

[solved] script syntax help

Recommended Posts

generic error in expression

|#|sleep 2;

error missing ;

if (!(count _nearLoc ==0)) then {hint "Array contains things"}; else |#|{hint "array is empty";};

 

what I'm trying to do is, if the player is 100 from nearest location - spawn ai 10% chance ever 5 second.

 

_myGroup = group player;
_RanNum = "";
_position = getPos player;
_nearLoc = nearestLocations [position player, ["NameCity","FlatAreaCity"], 100];

hint format ["city %1",_nearloc];
sleep 2;
while {true} do 
{
_RanNum = floor random 10;
if (!(count _nearLoc ==0)) then {hint "Array contains things"}; else {hint "array is empty";};
if (_RanNum = 0) then {_tempSoldier = _myGroup createUnit [ "B_Protagonist_VR_F", _position, [], 0, "NONE" ];};
sleep 5;	
};

may of answered one of my questions if (!(count _nearLoc ==0)) then {hint "Array contains things"}; else |#|{hint "array is empty";};  ";"is ending the statement too soon?

another question though. if i generate a random number and i want a condition to be true if the randomly gen number is 0 - would if (_ranNum = 0) work for that purpose?

 

finished script

script to randomly spawn infantry or motorized units around the player if atleast 500 meters away from cities or airports 

Spoiler

// first a variable to make the loop breakable
_loopvar = true;
// loop
sleep 5;
systemChat "loop start";
while {true} do
{    // not near any Locations
     if (count (nearestLocations [position player, ["NameCity","NameLocal"/*https://community.bistudio.com/wiki/Location*/], 500]) == 0 && random 6 < 1) then
    {    // chance 10%
            // spawn random teams/squads on a 150m circle in random direction
            _mot = "Motorized_MTP";
            _rnFr = selectRandomWeighted ["Infantry",0.9,"Motorized_MTP",0.1];
            _rnSq = if (_rndFr == _Mot) then [ {"OIA_MotInf_Team"} , {selectRandomWeighted ["OIA_InfSquad",0.1,"OIA_InfAssault",0.1,"OI_reconTeam",0.2,"OIA_InfTeam",0.4,"OIA_InfTeam_AT",0.4]} ]; 
            _grp = [player getPos [300,random (60)-30],EAST,(configfile >> "CfgGroups" >> "East" >> "OPF_F" >> _rnFr >> _rnSq)] call BIS_fnc_spawnGroup;
            _grp1 = leader _grp;
               _grpPos = getpos _grp1;
            systemChat format ["UAV: Enemy Sighted at %1 Degrees",floor(player getDir _grp1)];
            [_grp,_grpPos,150] call bis_fnc_taskPatrol; 
            waitUntil {sleep 50;((_grp1 distance player) > 600)};
            {deleteVehicle _x} forEach units _grp;
            sleep 1;
            {deleteGroup _x} forEach allGroups;
    };
    // player killed = break the loop
    //if !(alive player) then {_loopvar = false};
    // wait 1 second for main loop
  sleep 50;
};

 

Share this post


Link to post
Share on other sites

You need to start with sqf syntax. Have a look here.

As you can see:

if (cond) then {code} else {other code};

and for a numeral comparison : if (a == b) // not a = b which order the variable a to take the b value.

 

If you generate a random number, say : random 5, this number can take an outstanding range of values (real number). So there is few (say no) chance to reach 0 or 5 (statistically speaking). On the other end, you can randomize integer number:

0,1,2,3,4, with : floor random 5

(or 1,2,3,4,5 with :  ceil random 5)

So, be cautious with equality:

if (floor random 5 == 0) means 20% chance, same as:  if (random 5 < 1).

Share this post


Link to post
Share on other sites

_myGroup = group player;
//_RanNum = "";
_position = getPos player;
_nearLoc = nearestLocations [position player, ["NameCity","FlatAreaCity"], 100];
_enyTnk = [getPos _position, side EAST] (configFile >> "CfgGroups" >> "East" >> "OPF_F" >> "Armored" >> "OIA_TankSection")
_enyTrp = [getPos _position, EAST, 5] call BIS_fnc_spawnGroup


hint format ["city %1",_nearloc];
sleep 2;
while {true} 
{
//_RanNum = floor random 10;
if (!(count _nearLoc == 0)) then {if (floor random 5 == 0) then {selectrandom [_enRanTr,_enRanTk]};};
sleep 5;	
};

 then {if (floor random 5 == 0) then {selectrandom [_enRanTr,_enRanTk]};};

^will this code be the same as just writing the code  then {if (floor random 5 == 0) then {[getPos _position, EAST, 5] call BIS_fnc_spawnGroup]};}; 

or is select random just selecting the variable and doing nothing with it?

Share this post


Link to post
Share on other sites

You're messing around a lot ...

 

_nearloc is defined before the loop and not updating in the loop.

line "_enyTnk =..." breaks the script and missing semicolon

line "enyTrp =..." spawns a group with 5 East-Soldiers, missing semicolon, and "getPos _position"

line "while {true}..." missing "do" and neverending loop

line "if (!(count..." _enRanTr and _enRanTk are not defined


Anyway:

Spoiler

// first a variable to make the loop breakable
tag_myEnemyVar = true;

// loop
systemChat "loop start";
while {tag_myEnemyVar} do
{	// nearest Locations ?
	if (count (nearestLocations [position player, ["NameCity","FlatAreaCity"], 100]) > 0) then
	{	// chance 10%
		if ((random 10) < 1) then
		{	// spawn 5 east soldiers on a 100m circle in random direction
			_grp = [player getPos [100,random (360)],EAST,5] call BIS_fnc_spawnGroup;
			systemChat format ["Enemy at %1",getPos leader _grp];
		};
		// wait 5 seconds for next chance
		sleep 5;
	};
	// player killed = break the loop
	if !(alive player) then {tag_myEnemyVar = false};
	// wait 1 second for main loop
	sleep 1;
};

 

This script does what you want. It's only a beginning.

 

Take a closer look here: https://community.bistudio.com/wiki/Category:Scripting_Topics

 

Many want to help, but some basics must already be there, especially a little bit of syntax.
Do not get discouraged!

Share this post


Link to post
Share on other sites

It's also worth mentioning that you should run with scriptingErrors enabled (it's a launcher option) when writing SQF. That way you get immediate feedback on syntactical mistakes. You can also review the scripting error log in your AppData folder. In fact I have a shortcut of it to my desktop.

Share this post


Link to post
Share on other sites

how can i make _grp accessible outside the scope of the IF statement? since i would like to make a function that finds the range between the group and the player. is global variable the only way?

Share this post


Link to post
Share on other sites

You can...

private _grp = grpNull;

...in same script at begin.

 

You can also pass _grp to another function with

[_grp] call tag_yourFunction;
// or
[_grp] spawn tag_yourFunction;

or give it a global name.

Share this post


Link to post
Share on other sites
// first a variable to make the loop breakable
tag_myEnemyVar = true;
//_grp = _this select 0;
// loop
systemChat "loop start";
while {tag_myEnemyVar} do
{	// not near any Locations
	if (count (nearestLocations [position player, ["Airport","NameCity","NameLocal"], 500]) == 0) then
	{	// chance 10%
		if (floor random 1 == 0) then
		{	// spawn random teams/squads on a 150m circle in random direction
			_mot = "Motorized_MTP";
			_rndFr = selectrandom ["Infantry","Motorized_MTP"];
			_rndSq = if (_rndFr == _Mot) then [ {"OIA_MotInf_Team"} , {selectRandom ["OIA_InfSquad","OIA_InfAssault","OI_reconTeam","OIA_InfTeam","OIA_InfTeam_AT"]} ]; 
			_grp = [player getPos [150,random (360)],EAST,(configfile >> "CfgGroups" >> "East" >> "OPF_F" >> _rndFr >> _rndSq)] call BIS_fnc_spawnGroup;
			_grp1 = leader _grp;
			systemChat format ["Enemy at %1",getPos leader _grp];
			(units _grp) doMove (getPos player);
			waitUntil {sleep 10;((player distance _grp1) > 500)};
			{deleteVehicle _x} forEach units _grp;
			{deleteGroup _x} forEach allGroups;


		};
		// wait 5 seconds for next chance
		
		sleep 50;
	};

edited your script a bit. using it to engage the player a bit on the way to objectives

Share this post


Link to post
Share on other sites

tried to private a var but it doesn't stay the same outside the scope. how can I do this?

 

_rndFr = selectRandom ["Motorized_MTP","Infantry"]; 
_rndSq = selectRandom ["OIA_InfSquad","OIA_InfAssault","OI_reconTeam","OIA_InfTeam","OIA_InfTeam_AT"]; 
_rndGr = if (_rndFr == '"Motorized_MTP"') then {_rndSq = "OIA_MotInf_Team";};
_grp = [player getPos [150,random (360)],EAST,(configfile >> "CfgGroups" >> "East" >> "OPF_F" >> _rndFr >> _rndSq)] call BIS_fnc_spawnGroup;

 

Share this post


Link to post
Share on other sites

You need to pass the local variable as argument, outside the scope or the script (file).

 

_grp ExecVM "yourFile.sqf"

is same as:

_grp spawn {<your code>};

 

then, the sqf or code should start with:

_grp = _this;

(or params ["_grp"]; )

 

NB: people usually put single argument into an array, like [_grp] execVM "gnagna.sqf" . It's useless for single argument, and you need to change the code for:

_grp = _this select 0;

 

I can see an error in your script:

You should write:

if (_rndFr == "Motorized_MTP" ) then {_rndSq = "OIA_MotInf_Team"};  // no triple quote for the condition

 

Share this post


Link to post
Share on other sites
_Mot = "Motorized_MTP";
_rndFr = selectrandom ["Infantry","Motorized_MTP"];
_rndSq = selectRandom ["OIA_InfSquad","OIA_InfAssault","OI_reconTeam","OIA_InfTeam","OIA_InfTeam_AT"];
if (_rndFr == _Mot) then {_rndSq = "OIA_MotInf_Team"};
_grp = [player getPos [150,random (360)],EAST,(configfile >> "CfgGroups" >> "East" >> "OPF_F" >> _rndFr >> _rndSq)] call BIS_fnc_spawnGroup;  

apparently you cant check to see if a _var is equal to string (_var == "string") has to be (_var ==_var2). only in IF statements?

because it throws an error generic error in expression _rndGr|#| = if (_rndFr == "Motorized_MTP") then {_rndSq = "OIA_MotInf_Team"}; 

Share this post


Link to post
Share on other sites

_rndSq = if (_rndFr == _Mot) then [ {"OIA_MotInf_Team"} , {selectRandom ["OIA_InfSquad","OIA_InfAssault","OI_reconTeam","OIA_InfTeam","OIA_InfTeam_AT"]} ];

 

Be curious. Have a look here.

 

  • Thanks 1

Share this post


Link to post
Share on other sites

thanks to pierremgi and Lucullus

script to randomly spawn infantry or motorized units around the player if atleast 500 meters away from cities or airports 

// first a variable to make the loop breakable
_loopvar = true;
params ["_grp"];
// loop
sleep 5;
systemChat "loop start";
while {_loopvar} do
{	// not near any Locations
	 if (count (nearestLocations [position player, ["NameCity","FlatAreaCity"/*https://community.bistudio.com/wiki/Location*/], 500]) == 0 && random 6 < 1) then
	{	// chance 10%
			// spawn random teams/squads on a 150m circle in random direction
			_mot = "Motorized_MTP";
			_rnFr = selectRandomWeighted ["Infantry",0.9,"Motorized_MTP",0.1];
			_rnSq = if (_rndFr == _Mot) then [ {"OIA_MotInf_Team"} , {selectRandomWeighted ["OIA_InfSquad",0.1,"OIA_InfAssault",0.1,"OI_reconTeam",0.2,"OIA_InfTeam",0.4,"OIA_InfTeam_AT",0.4]} ]; 
			_grp = [player getPos [300,random (60)-30],EAST,(configfile >> "CfgGroups" >> "East" >> "OPF_F" >> _rnFr >> _rnSq)] call BIS_fnc_spawnGroup;
			_grp1 = leader _grp;
       		_grpPos = getpos _grp1;
			//_plyPos = player getPos [300,random (60)];
			systemChat format ["UAV: Enemy Sighted at %1 Degrees",floor(player getDir _grp1)];
			[_grp,_grpPos,150] call bis_fnc_taskPatrol; 
			waitUntil {sleep 50;((_grp1 distance player) > 600)};
			{deleteVehicle _x} forEach units _grp;
			sleep 1;
			{deleteGroup _x} forEach allGroups;
	};
	// player killed = break the loop
	//if !(alive player) then {_loopvar = false};
	// wait 1 second for main loop
	//sleep 1;
  sleep 50;
};

 

Share this post


Link to post
Share on other sites
7 hours ago, pierremgi said:

use 2 waitUntil in your loop. (wait until something ocurs, wait until something else).

 

i got away with one

waitUntil {sleep 50;((player distance _grp1) > 500)};

Share this post


Link to post
Share on other sites
		while {true} do
	{	
	
		 if (count (nearestLocations [position player, ["NameCity","NameLocal"], 601]) == 0) then
		{	// chance 10%
			systemChat "loop start";
			_locPos = player getPos [300,random (60)-30];
				
			if (count (nearestLocations [position player, ["Hill","NameVillage"], 301]) >= 1) then 
			{
			_loc = nearestLocations [position player, ["Hill","NameVillage"], 301];
			_loc1 = _loc select 0;
			_locPos = locationPosition _loc1;
			};
				_location1 = _locPos getPos [100,random (360)];
				_mot = "Motorized_MTP";
				_rnFr = selectRandomWeighted ["Infantry",0.9,"Mechanized",0.1];
				_rnSq = if (_rnFr == _Mot) then [ {"OIA_MechInfSquad"} , {selectRandomWeighted ["OIA_InfSquad",0.3,"OIA_InfAssault",0.3,"OIA_ReconSquad",0.2,"OIA_InfTeam",0.1,"OIA_InfTeam_AT",0.1]} ]; 
				_grp = [_location1 ,EAST,(configfile >> "CfgGroups" >> "East" >> "OPF_F" >> _rnFr >> _rnSq)] call BIS_fnc_spawnGroup;


				_grp1 = leader _grp;
	       		_grpPos = getpos _grp1;
				systemChat format ["UAV: Enemy Sighted at %1 Degrees",floor(player getDir _grp1)];
				//systemChat format ["%1", _loc1];
				[_grp,_locPos,80] call bis_fnc_taskPatrol; 

				waitUntil {sleep 50;((_grp1 distance player) > 600)};
				{if (side _x == east) then {deleteVehicle _x};} foreach allunits;
				sleep 1;
				{deleteGroup _x} forEach allGroups;
           
           };
		

		//sleep 1;
	  sleep 50;
	};

how can I spawn 2 groups at a time and still reference their group? using "for loop" to spawn groups I cant reference any spawned groups and so finding the leaders' pos is not possible

 

  • Like 1

Share this post


Link to post
Share on other sites

@battlecarrysabot, add spawned groups into an array:

_groups = [];

for "_i" from 1 to 10 do {
	// Group spawning code

	_groups pushBack _group;
};

_group1 = _groups select 0;
_group1Leader = leader _group1;
...

 

Share this post


Link to post
Share on other sites

this script will wait for player to be 601 meters away from cities befor checking to see if any hills near player, then spawn a base and delete the base once player is 700 meter away. alternatively if no hills nearby, it will spawn troops 300 meters in a 30 degree spread infront of the player. I will try to add to it later

 

private ["_cargo","_grpBol","_grpSpwn","_tower","_marker"];
	// loop
	sleep 5;
	systemChat "loop start";
	_grps =[];
	_grpBul = false;
			while {true} do
{	
		_pPos = getPos player;
		 if (count (nearestLocations [_pPos, ["NameCity","NameLocal"], 500]) == 0 && random 4 < 1) then
		{	
			
			systemChat "loop start";
			_locPos = player getPos [300,random (120)-60];
			_fndLoc = nearestLocations [_pPos, ["Hill","NameVillage"], 600];
			//***************************************************************************	
			if (count (_fndLoc) > 0) then 
			{
			
			_loc1 = _fndLoc select 0;
			_locPos = locationPosition _loc1;
			_randPos = [_locPos , 0, 200, 12, 0, 0.4, 0] call BIS_fnc_findSafePos;
			_cargo = "Land_Cargo_HQ_V1_F" createVehicle _randPos;
			_randPos14 = _cargo getRelPos [9, 12];
			_mg13 = createVehicle ["O_GMG_01_high_F", _randPos14, [], 0, "CAN_COLLIDE"];
			_mgguy13 = [_randPos14, EAST, ["O_Soldier_F"],[],[],[],[],[],232] call BIS_fnc_spawnGroup;
			((units _mgguy13) select 0) moveInGunner _mg13;
			_mg13 setPosATL (_cargo buildingPos 4);
			_randPos15 = _cargo getRelPos [9, 180];
			_mg14 = createVehicle ["O_GMG_01_high_F", _randPos15, [], 0, "CAN_COLLIDE"];
			_mgguy14 = [_randPos15, EAST, ["O_Soldier_F"],[],[],[],[],[],232] call BIS_fnc_spawnGroup;
			((units _mgguy14) select 0) moveInGunner _mg14;
			_mg14 setPosATL (_cargo buildingPos 7);
			_mg14 setDir 180;
			_randPos2 = [_cargo , 15, 200, 10, 0, 0.6, 0] call BIS_fnc_findSafePos;
			_tower = "Land_TTowerBig_1_F" createVehicle _randPos2; 
			_tower setVectorUp [0,0,1]; // Make sure the tower is not leaning.
			_tower addEventHandler ["Killed", {player addRating 2000; task1 setTaskState "Succeeded"; systemChat format ["good job."];}];
			_towerbox = "Land_spp_Transformer_F" createVehicle _randPos2;
			_towerbox setVectorUp [0,0,1];
			_towerbox2 = "Land_TTowerSmall_1_F" createVehicle _randPos2;
			_towerbox2 setVectorUp [0,0,1];
			_tower setVehicleVarName "tower1"; tower1 = _tower;
			_genny = _tower getRelPos [7, 9];
			//*** create HQ Marker
			_marker = createMarkerLocal ["opfor_hq.", position player ];
			_marker setMarkerPos _randPos;
			_marker setMarkerShape "ICON";
			_marker setMarkerColor "Default";
			_marker setMarkerType "loc_Bunker";
			_marker setMarkerText "HQ";
			//*** Task for player
			task1 = player createSimpleTask ["Destroy the Cell Tower"];
			task1 setSimpleTaskDescription ["The Enemy are using the Antenna for Propaganda Purposes, it needs to be Destroyed","",""];
			task1 setsimpletaskdestination _randPos2;
			task1 setTaskState "Assigned";
			player setCurrentTask task1;
			_grpBul = true;
			};
				for "_i" from 1 to 4 do 
				{
				_grps =[];
				_Xrnd = random [0,100,200];
				if (_grpBul) then [{_grpSpwn = _cargo getPos [_Xrnd,random (360)]} , {_grpSpwn = _locPos getPos [_Xrnd,random (360)];}];
				_mot = "Mechanized";
				_rnFr = selectRandomWeighted ["Infantry",3,"Mechanized",0.1];
				_rnSq = if (_rnFr == _Mot) then [ {"OIA_MechInfSquad"} , {selectRandomWeighted ["OIA_InfTeam",0.9,"OIA_InfTeam_AT",0.4,"OIA_InfSquad",0.1,"OIA_InfAssault",0.1,"OIA_ReconSquad",0.1]} ]; 
				_grp = [_grpSpwn ,EAST,(configfile >> "CfgGroups" >> "East" >> "OPF_F" >> _rnFr >> _rnSq)] call BIS_fnc_spawnGroup;
				[_grp,_grpSpwn,150] call bis_fnc_taskPatrol;
				_grps pushBack _grp;
				sleep 0.3;
				};
				_grp1 = _grps select 0;
				_grp1Ldr = leader _grp1;
				_grp1 = getpos _grp1Ldr;
				//systemChat format ["grps %1 |grp1 |%2 |_grp1Ldr %3 ",_grps,_grp,_grp1Ldr];
				systemChat format ["UAV: Multiple Enemies Sighted at %1 Degrees be Advised",floor(player getDir _locPos)];
				Sleep 1;
				waitUntil {sleep 50;((player distance _grp1) > 900)};
				{if (side _x == east) then {deleteVehicle _x};} foreach allunits;
				_objs = nearestObjects [_locPos, [], 410];
				{deleteVehicle _x} forEach _objs;
				player removeSimpleTask task1;
				deleteMarker _marker;
				_tower removeAllEventHandlers "killed";
				sleep 1;
				{deleteGroup _x} forEach allGroups;
				//{deleteVehicle _x} forEach allUnitsUAV;
				_grpBul = false;
				
				
		};
		
	  sleep 60;
	};

 

Share this post


Link to post
Share on other sites

not the best coding skills but I'm trying.

spawns radio tower when near hills and creates objective.

spawns roadblock when near roads.

spawns troop patrols when away from any location

_spwmgrp = compile preprocessfilelinenumbers "scripts\fn_spwngrp.sqf";
private ["_cargo","_ANIM","_grpBul","_grpBul1","_grpSpwn","_tower","_marker","_pPos","_locPos","_loc1","_task1","_ofr1","_fndLoc","_nearest","_CaseCnt"];
	// loop
	sleep 5;
	//systemChat "loop start";
	_grps =[];
	_mgguys = [];
	_cargo = objnull;
			while {true} do
{		_grps = [];
		_grpBul = false;
		_grpBul1 = false;
        _threshold = 3000;
		_nearest = [];
		_fndLoc = "";
		_loc1 = 0;
		_CaseCnt = 99;
		

		_locPos = player getPos [300,random (120)-60];
		_pPos = getPos player;
		 if (count (nearestLocations [_pPos, ["NameCity","NameLocal","NameCityCapital"], 600]) == 0) then
		{	
			{if( player distance _x < _threshold) exitWith {_nearestpos = getpos _x; _nearest append _nearestpos;};} forEach [radio1,radio2,radio3,radio4]; _nearest;
			hint "1";	
			if !(count (_nearest)==0) then {_fndLoc = (selectrandom (nearestLocations [_nearest, ["hill"], 1999]));
			hint "2";			
			_locPos = locationPosition _fndLoc;
			if (player inArea [_locPos, 3000, 3000, 45, false, 3000]) then { _loc1 = _fndLoc; _CaseCnt = 0;};};
			_fndLoc = player nearRoads 330;
			if (count (_fndLoc) > 0 && _CaseCnt == 99) then 
			{_CaseCnt = 1;			
			_loc1 = _fndLoc select 0;
			_locPos = getpos _loc1;};
			systemChat format ["UAV:%1",_CaseCnt];
			hint "3";	
switch (_CaseCnt) do
{
case 0:
	{
	hint "1.1";	
	systemChat format ["UAV:%1 %2",_fndLoc,_loc1];
			_randPos = [_locPos , 0, 200, 12, 0, 0.4, 0] call BIS_fnc_findSafePos;
			if (((_randPos distance _locPos) > 210)) then
				{_randPos =	[_locPos , 0, 200, 12, 0, 0.6, 0] call BIS_fnc_findSafePos;};
			_cargo = "Land_Cargo_HQ_V1_F" createVehicle _randPos;
			//***tower
			_randPos2 = [_locPos , 20, 100, 0, 0, 0.6, 0] call BIS_fnc_findSafePos;
			_tower = "Land_TTowerBig_2_F" createVehicle _randPos2; 
			_tower setVectorUp surfaceNormal position _tower;
			_tower setVectorUp [0,0,1]; // Make sure the tower is not leaning.
			//*** Task for player
			task1 = player createSimpleTask ["Destroy the Cell Tower"];
			task1 setSimpleTaskDescription ["The Enemy are using the Antenna for Propaganda Purposes, it needs to be Destroyed","Destroy Antenna","Destroy Antenna"];
			task1 setsimpletaskdestination _randPos2;
			task1 setTaskState "Assigned";
			player setCurrentTask task1;
			if (true) then{
			_tower addEventHandler ["Killed", {["task1", "Succeeded"] call BIS_fnc_taskSetState; ;}];}; 
   
			_towerbox = "Land_spp_Transformer_F" createVehicle _randPos2;
			_towerbox setVectorUp surfaceNormal position _towerbox;
			_towerbox setVectorUp [0,0,1];
			_towerbox2 = "Land_TTowerSmall_1_F" createVehicle _randPos2;
			_towerbox2 setVectorUp [0,0,1];
			_tower setVehicleVarName "tower1"; tower1 = _tower;
			_genny = _tower getRelPos [7, 9];
			//*** bunkers
			_randPos12 = _cargo getRelPos [105, 180];
			_randPos121 =[_randPos12 , 20, 100, 5, 0, 0.4, 0] call BIS_fnc_findSafePos;
			if (((_randPos121 distance _randPos) > 201)) then
				{_randPos121 =	_randPos12};
			_bunker1 = "Land_BagBunker_Small_F" createVehicle _randPos121;
			_bunker1 setVectorUp surfaceNormal position _bunker1;
			_randPos13 = _cargo getRelPos [105, 0];
			_randPos131 =[_randPos13 , 20, 100, 5, 0, 0.4, 0] call BIS_fnc_findSafePos;
			if (((_randPos131 distance _randPos) > 201)) then
				{_randPos131 =	_randPos13};
			_bunker2 = "Land_BagBunker_Small_F" createVehicle _randPos131;
			_bunker2 setDir 180;
			_randPos14 = _bunker2 getRelPos [0, 0];
			_bunker2 setVectorUp surfaceNormal position _bunker2;
			_mg13 = createVehicle ["O_HMG_01_high_F", _randPos14, [], 0, "CAN_COLLIDE"];
			_randPos15 = _bunker1 getRelPos [0, 180];
			_mg14 = createVehicle ["O_HMG_01_high_F", _randPos15, [], 0, "CAN_COLLIDE"];
			_bnkrOcup = [_locPos, EAST, ["O_Soldier_F","O_Soldier_F","O_Soldier_F"],[],[],[],[],[],232] call BIS_fnc_spawnGroup;
			_grps pushBack _bnkrOcup;
			systemChat format ["UAV: Enemy Antenna Spotted %1 Degrees",floor(player getDir _tower)];
			((units _bnkrOcup) select 0) moveInGunner _mg13;
			((units _bnkrOcup) select 1) moveInGunner _mg14;
			_mg14 setDir 180;
			_ofr1 = ((units _bnkrOcup) select 2);
			_ofr1 setPosATL (_cargo buildingPos 4);
			_ofr1 disableAI "PATH";
			_ofr1 addEventHandler ["Killed", {player addRating 3000; _score = rating player; systemChat format ["Player Score %1 ",_score];}];
			//*** create HQ Marker
			_marker = createMarkerLocal ["opfor_hq.", position player ];
			_marker setMarkerPos _randPos;
			_marker setMarkerShape "ICON";
			_marker setMarkerColor "ColorOPFOR";
			_marker setMarkerType "loc_Bunker";
			_marker setMarkerText "Enemy CP";
			_marker setMarkerSizeLocal [2.5, 2.5];
			
	};
	case 1: 
	{		hint "2.2";	
			_roadsSorted = [_fndLoc,[],{_loc1 distance _x},"ASCEND"] call BIS_fnc_sortBy;
			systemChat format ["UAV:%1 %2",_fndLoc,_loc1];
			_nearestRoad = _roadsSorted select 0;
			_roadConnectedTo = roadsConnectedTo _nearestRoad;
			_connectedRoad = _roadConnectedTo select 0;
			_roadCenter = getPos _nearestRoad;
			_cargo = _roadCenter;
			_roadDir = [_nearestRoad, _connectedRoad] call BIS_fnc_DirTo;
			//***roadblock
			_bunker1 = "Land_BagBunker_Small_F" createVehicle _roadCenter;
			_bunker1 setDir _roadDir;
			_bunkerpos = _bunker1 getRelPos [10, 90];
			_bunker1 setpos _bunkerpos;
			_bunker1 setVectorUp surfaceNormal position _bunker1;
			_gate = "Land_BarGate_F" createVehicle _cargo;
			_gate setDir _roadDir;
			_gate setpos [(getpos _gate select 0)+4,getpos _gate select 1, getpos _gate select 2];
			_randPos15 = _bunker1 getRelPos [0, 0];
			_mg14 = createVehicle ["O_HMG_01_high_F", _randPos15, [], 0, "CAN_COLLIDE"];
			_bnkrOcup = [_locPos, EAST, ["O_Soldier_F","O_Soldier_F"],[],[],[],[],[],232] call BIS_fnc_spawnGroup;
			_grps pushBack _bnkrOcup;
			_ANIM = (units _bnkrOcup) select 1; 
			_AnimPos = _gate getRelPos [6, 90];
			_ANIM setpos _AnimPos;
			((units _bnkrOcup) select 0) moveInGunner _mg14;
			[_ANIM, "WATCH2", "RANDOM"] call BIS_fnc_ambientAnimCombat;
			_ANIM addeventhandler ["AnimChanged", {
			if (behaviour ((units _bnkrOcup) select 0) == "combat") then {
			(_this select 0) call BIS_fnc_ambientAnim__terminate;
			(_this select 0) removeAllEventHandlers "AnimChanged";}}];
			_mg14 setDir _roadDir - 180;
			
	};
 
};
	
				waituntil {sleep 5; ((player distance _locPos) < 800) or ((player distance _locPos) > 3001) };
				_grps = [_CaseCnt,_cargo] call _spwmgrp;
				_grp0 = _grps select 0;
				_grp1 = ((units _grp0) select 0);
				_grp1Ldr = getPos _grp1;
				waitUntil {sleep 5;((player distance _grp1Ldr) > 900)};
				sleep 3;
				 {{deleteVehicle _x} forEach units _x}foreach _grps;

				if (_CaseCnt == 0) then
				{
				_objs = nearestObjects [_grp1Ldr, ["Building","StaticWeapon"], 410];
				{deleteVehicle _x} forEach _objs;
				player removeSimpleTask task1;
				deleteMarker _marker;
				_tower removeAllEventHandlers "killed";
				_ofr1 removeAllEventHandlers "killed";
				};
				if (_CaseCnt == 1) then
				{
				_ANIM call BIS_fnc_ambientAnim__terminate;
				_objs = nearestObjects [_grp1Ldr, ["Building","StaticWeapon"], 410];
				{deleteVehicle _x} forEach _objs;
				};
				sleep 1;
				{deleteGroup _x} forEach allGroups;
				_cargo = objnull;
				
};
sleep 10;
};

 

fn_spwngrp.sqf


				params[ ["_CaseCnt", 99,[]] , ["_cargo",[objNull,[]]]];
				for "_i" from 1 to 4 do 
				{
				_Xrnd = random [20,80,200];
				_Xrnd1 = random [250,250,500];
				if !(_CaseCnt == 99) then [{_grpSpwn = _cargo getPos [_Xrnd,random (360)]} , {_grpSpwn = player getPos [_Xrnd1,random (120)-60]}];
				_mot = "UInfantry";
				_rnFr = selectRandomWeighted ["Infantry",0.3,"UInfantry",1];
				_rnSq = if (_rnFr == _Mot) then [ {"OIA_GuardSentry"} , {selectRandomWeighted ["OIA_InfTeam",4,"OIA_InfTeam_AT",0.4,"OIA_InfTeam_AA",0.2]} ]; 
				_grp = [_grpSpwn ,EAST,(configfile >> "CfgGroups" >> "East" >> "OPF_F" >> _rnFr >> _rnSq)] call BIS_fnc_spawnGroup;
				[_grp,_grpSpwn,150] call bis_fnc_taskPatrol;
				_grps pushBack _grp;
				sleep 0.35;
				};

				//systemChat format ["**%1 **%2",_grpBul,_grpBul1];

				
				_grps

 

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  

×