Jump to content
Sign in to follow this  
bangabob

Looping my script with variable

Recommended Posts

I have a script that basically spawns enemy AI when BLUFOR players are PRESENT in a trigger.

And when BLUFOR are NOT PRESENT in another trigger the script deletes the enemy AI.

The problem is that the script doesn't spawn a new set of AI when BLUFOR are PRESENT again. I have attempted to use a variable in this fasion to attempt to turn parts of the scripts on/off.

while {loop) do {scripts... Loop = FALSE, scripts... Loop = TRUE, sleep 0.5};

//
//OCCUPATIONTILE.SQF FOR ARMA III
//
//Place a 50x50 Red Rectangle marker and name it
//null = ["parameter1",parameter2,parameter3,parameter4,parameter5] execvm "occupationtile.sqf"
//Null = ["mkr1",True,False,500] execVM "occupationtile.sqf"
//Parameter1 - "Markername"
//Parameter2 - True will spawn additional patrol squad (Default False)
//Parameter3 - True will spawn AI vehicle (Default False)
//Parameter4 - Spawn AI distance (Default 275)
//Parameter5 - Starts loop on spawning AI
//
//Script Written by BangaBob
//


//Sets my variables to private so they are onyl used within this script
private ["_hvyai","_spwnpos","_mkrname","_t", "_r","_vehai","_grp","_d","_Deldist","_loop"];

//My parameters from script call. 
_spwnpos = markerPos (_this select 0);				 //Gets position of marker
_mkrname = (_this select 0);					 //Gets Name of marker
_hvyai = if (count _this > 1) then {_this select 1} else {FALSE};//Sets variable for spawning units
_vehai = if (count _this > 2) then {_this select 2} else {FALSE};//Sets variable for spawning vehicle
_detcdst = if (count _this > 3) then {_this select 3} else {275};//Sets trigger area 
_loop = if (count _this > 4) then {_this select 4} else {FALSE}; //Sets respawning AI area
_Deldist = (_detcdst + 10);




//Create triggers
//Detects when BLUFOR are in range of marker
_t = createTrigger ["EmptyDetector",_spwnpos]; 
_t setTriggerArea [_detcdst,_detcdst,0,true]; 
_t setTriggerActivation ["WEST","PRESENT",true]; 
_t setTriggerStatements ["this && {((getPosATL _x) select 2) < 5} count thislist > 0","",""]; 
_t setTriggerType "NONE";
_t;

//Detects when Opfor are not present
_r = createTrigger ["EmptyDetector",_spwnpos]; 
_r setTriggerArea [50,50,0,true]; 
_r setTriggerActivation ["EAST","NOT PRESENT",true]; 
_r setTriggerStatements ["this","",""]; 
_r setTriggerType "NONE"; 
_r;

sleep 1;



//TIME TO CREATE SOME UNITS
Waituntil {triggeractivated _t};

//Deletion trigger
_d = createTrigger ["EmptyDetector",_spwnpos]; 
_d setTriggerArea [_Deldist,_Deldist,0,true]; 
_d setTriggerActivation ["WEST","NOT PRESENT",true]; 
_d setTriggerStatements ["this","",""]; 
_d setTriggerType "NONE"; 
_d;

while {_loop} do {

Waituntil {triggeractivated _t};
//If parameter2 is TRUE then spawns extra enemies
if (_hvyai) then {

		if (isServer) then
			{
   			_grp= _this select 1;
   			_grp = [_spwnpos, East, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam"),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup;
   			sleep 0.1;
   			0=[_spwnpos,units _grp,50,0,[0,4],true] execvm "shk_buildingpos.sqf";

   			_grp= _this select 1;
   			_grp = [_spwnpos, East, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam"),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup;
   			0=[_grp,_spwnpos,40] call bis_fnc_taskPatrol;
		};

//Uses another variable from paramter3. If TRUE spawns vehicle group. If FALSE ignores it
	if (_vehai) then {
		if (isServer) then
				{
			_grp= _this select 1;
   				_grp = [_spwnpos, East, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Motorized_MTP" >> "OIA_MotInfTeam"),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup;
   				0=[_grp,_spwnpos] call bis_fnc_taskDefend;
			};
		};

//If parameter2 is FALSE then defaults to spawn one set of AI
} ELSE {
 	if (isServer) then
			{
   			_grp= _this select 1;
   			_grp = [_spwnpos, East, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam"),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup;
   			sleep 0.1;
   			0=[_spwnpos,units _grp,50,0,[0,4],true] execvm "shk_buildingpos.sqf";
		};
_loop = false;
};
sleep 1;

Waituntil {triggeractivated _t};	

//TIME TO SEE WHATS GOING ON

//Begins loop
while {true} do {


										//If OPFOR are NOT PRESENT in trigger then set marker colour Green	
										//DELETE UNITS WHEN TRIGGERED			
	if (triggeractivated _d) then 	
{

	{deleteVehicle _x} forEach units _grp; 
	deleteGroup _grp;
	hint "deleting units"; _loop = true;
} else {

			if(triggeractivated _r) then 
	{
		sleep 0.5; _mkrname setMarkerColor "ColorGreen";

	} else {
		_mkrname setMarkerColor "ColorRed";
		};
	};	
										//Repeat this loop every 0.5 seconds
		sleep 0.5;
};
sleep 0.5;
};//loop

Maybe im an idiot and missing something completely obvious but please can someone experienced take a look and let me know how to fix this problem

Share this post


Link to post
Share on other sites

Your never falling out of the loop

//TIME TO SEE WHATS GOING ON  

//Begins loop                 
while {true} do {             

which checks to delete spawned OPFOR units if BLUFOR not present OR sets marker colour dependant on if OPFOR are present or not. Your never getting back to see if BLUFOR are present and respawn your units again. I forsee other problems

Share this post


Link to post
Share on other sites

Okay. Im new to scripting but this is my script without the deletion section.

So what this script does is it simulates an insurgency style red square. All you need to do is place a marker and call the script

//
//OCCUPATIONTILE.SQF FOR ARMA III
//
//Place a 50x50 Red Rectangle marker and name it
//null = ["parameter1",parameter2,parameter3,parameter4] execvm "occupationtile.sqf"
//Null = ["mkr1",True,False,500] execVM "occupationtile.sqf"
//Parameter1 - "Markername"
//Parameter2 - True will spawn additional patrol squad (Default False)
//Parameter3 - True will spawn AI vehicle (Default False)
//Parameter4 - Spawn AI distance (Default 275)
//
//Script Written by BangaBob
//


//Sets my variables to private so they are onyl used within this script
private ["_hvyai","_spwnpos","_mkrname","_t", "_r","_vehai"];

//My parameters from script call. 
_spwnpos = markerPos (_this select 0);				 //Gets position of marker
_mkrname = (_this select 0);					 //Gets Name of marker
_hvyai = if (count _this > 1) then {_this select 1} else {FALSE};//Sets variable for spawning units
_vehai = if (count _this > 2) then {_this select 2} else {FALSE};//Sets variable for spawning vehicle
_detcdst = if (count _this > 3) then {_this select 3} else {275};//Sets trigger area 

//Create triggers
//Detects when BLUFOR are in range of marker
_t = createTrigger ["EmptyDetector",_spwnpos]; 
_t setTriggerArea [_detcdst,_detcdst,0,true]; 
_t setTriggerActivation ["WEST","PRESENT",true]; 
_t setTriggerStatements ["this && {((getPosATL _x) select 2) < 5} count thislist > 0","",""]; 
_t setTriggerType "NONE";
_t;

//Detects when Opfor are not present
_r = createTrigger ["EmptyDetector",_spwnpos]; 
_r setTriggerArea [50,50,0,true]; 
_r setTriggerActivation ["EAST","NOT PRESENT",true]; 
_r setTriggerStatements ["this","",""]; 
_r setTriggerType "NONE"; 
_r;

sleep 1;

//Waits until BLUFOR trigger is activated
Waituntil {triggeractivated _t};

//If parameter2 is TRUE then spawns extra enemies
if (_hvyai) then {

		if (isServer) then
			{
   			_grp= _this select 1;
   			_grp = [_spwnpos, East, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam"),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup;
   			sleep 0.1;
   			0=[_spwnpos,units _grp,50,0,[0,4],true] execvm "shk_buildingpos.sqf";

   			_grp= _this select 1;
   			_grp = [_spwnpos, East, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam"),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup;
   			0=[_grp,_spwnpos,40] call bis_fnc_taskPatrol;
		};

//Uses another variable from paramter3. If TRUE spawns vehicle group. If FALSE ignores it
	if (_vehai) then {
		if (isServer) then
				{
			_grp= _this select 1;
   				_grp = [_spwnpos, East, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Motorized_MTP" >> "OIA_MotInfTeam"),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup;
   				0=[_grp,_spwnpos] call bis_fnc_taskDefend;
			};
		};

//If parameter2 is FALSE then defaults to spawn one set of AI
} ELSE {
 	if (isServer) then
			{
   			_grp= _this select 1;
   			_grp = [_spwnpos, East, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam"),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup;
   			sleep 0.1;
   			0=[_spwnpos,units _grp,50,0,[0,4],true] execvm "shk_buildingpos.sqf";
		};
};	

//Waits until BLUFOR activated the trigger
Waituntil {triggeractivated _t};

//Begins loop
while {true} do {

//If OPFOR are NOT PRESENT in trigger then set marker colour Green	
	if(triggeractivated _r) then 
	{
		sleep 0.5; _mkrname setMarkerColor "ColorGreen"

	} else {
		_mkrname setMarkerColor "ColorRed"
		};

//Repeat this loop every 0.5 seconds
sleep 0.5;
};

How would i go about falling out the loop?

//Begins loop

while {true} do {

Share this post


Link to post
Share on other sites

you need to do an

if (something) exitWith{}; 

inside the loop to exit the loop.

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  

×