Jump to content
  • 0

Check, if vehicle is still in area..


Guest

Question

Hi,

 

i'm trying to check if the vehicle is still in the mission area:
 

while {true} do {
	_meters = _aiVehicle distance _position;
	
	if (_meters > 200) then {
		in_area = true;
	};
sleep 5;
	
};

But that didn't work... What am i doing wrong here?

_position is set like so:

_position = [getMarkerPos _spawnMarker,0,_spawnRadius,10,0,20,0] call BIS_fnc_findSafePos;

and _aiVehicle should be clear, what that is.. It's spawned somewhere inside the area of _position..

 

 

 

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

Hi,

 

i'm trying to check if the vehicle is still in the mission area:

 

while {true} do {
	_meters = _aiVehicle distance _position;
	
	if (_meters > 200) then {
		in_area = true;
	};
sleep 5;
	
};

But that didn't work... What am i doing wrong here?

_position is set like so:

_position = [getMarkerPos _spawnMarker,0,_spawnRadius,10,0,20,0] call BIS_fnc_findSafePos;

and _aiVehicle should be clear, what that is.. It's spawned somewhere inside the area of _position..

waitUntil {_aiVehicle distance _position <= 200};
Link to comment
Share on other sites

  • 0
waitUntil {_aiVehicle distance _position <= 200};

 

 

Thanks for that.. Can you explain me please, what the difference is? The code i used is doing exactly the same or not? But mine didn't work..

Just so i understand, what i did wrong..

Link to comment
Share on other sites

  • 0

waitUntil {_aiVehicle distance _position <= 200};

 

means that it will wait till the AIVehicle is less or 200 meters away from the marker (_position)

 

BUT if you want to use it to check if the vehicle is still there you should use: >= 200 so it will continue with the script when the vehicle is out of the range

 

You can use your code either, just change some conditions here:

 

 

 _meters = _aiVehicle distance _position;

while {_meters > 200} do {

    
 in_area = true;

 _meters = _aiVehicle distance _position;
 sleep 5;
    
};

in_area = false;

 

basically the same thing, its just clever to use a loovariable

 

 _meters = _aiVehicle distance _position;

_loop = true;

while {_loop} do {

    if (_meters > 200) then {
        in_area = true;

    } else {

        in_area = false;

       _loop = false; // in case you want to exit the loop, when the vehicle is in the range

    }; 

    _meters = _aiVehicle distance _position;
    sleep 5;
    
};

in_area = false;

Link to comment
Share on other sites

  • 0

Thanks for all that. Unfortionatly it's still not working, due to some other error:

 

 

"Deleting object ArmoredSUV_PMC_DZ with invalid ID at pos [4521.88,8478.67,0.000518799]"

_aiVehicle = createVehicle ["ArmoredSUV_PMC_DZ", _aivehicle_spawn_pos, [], 0, "NONE"];
_aiVehicle setPos _aivehicle_spawn_pos;
_aiVehicle addEventHandler ["Killed",{_this call DZAI_vehDestroyed;}];
_aiVehicle addEventHandler ["HandleDamage",{_this call DZAI_vHandleDamage}];
_aiVehicle setVariable ["Mission",1,true];
_aiVehicle call dayz_objectUID;
Link to comment
Share on other sites

  • 0
_aiVehicle = createVehicle ["ArmoredSUV_PMC_DZ", _aivehicle_spawn_pos, [], 0, "NONE"];
_aiVehicle setVariable["ObjectID", "0", true]; // set a ObjectID
_aiVehicle setPos _aivehicle_spawn_pos;
_aiVehicle addEventHandler ["Killed",{_this call DZAI_vehDestroyed;}];
_aiVehicle addEventHandler ["HandleDamage",{_this call DZAI_vHandleDamage}];
_aiVehicle setVariable ["Mission",1,true];
_aiVehicle call dayz_objectUID;
Link to comment
Share on other sites

  • 0

I guess thats due to a logical mistake

 

 

while {true} do {
    _meters = _aiVehicle distance _position;
    
    
if (_meters > 200) then {

        in_area = true;
    };
sleep 5;
    
};

 

You need to reconsider if this part is right:

 

if (_meters > 200) then {

        in_area = true;
};

 

shouldnt this be:

if (_meters < 200) then {

 

        in_area = true;
};

because if the range is higher than 200 it would be outside the area..

maybe you can post the rest of the script and I will have a look on it

Link to comment
Share on other sites

  • 0

are you having your _inArea in your private section?

 

also maybe something like this can be a bit better:

while {true} do {
	_meters = _aiVehicle distance _position;
	
	if (_meters > 200) exitWith {
		in_area = true;
	};
sleep 5;
	
};

Just giving out some more ideas

 

Does it needs to be a global Variable?

Link to comment
Share on other sites

  • 0

I really doubt, that the whole script will help ^^ more likely it'll confuse, but anyway:

 

/*
	File Name: FMission_M3_Assassination.sqf
	File Created: 2/26/2014
	File Version: 1.2
	File Author: Foamy 
	File Last Edit Date: 3/26/2014
	File Description: Assassination Mission (M3)
*/

// CHECK FOR ANOTHER MISSION 1 RUNNING START ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

	if (isNil "EPOCH_MISSION3_RUNNING") then 
	{
	EPOCH_MISSION3_RUNNING = false;
	};

	if (EPOCH_MISSION3_RUNNING) exitWith 
	{
	diag_log("MISSION 3 already running");
	};

// CHECK FOR ANOTHER MISSION 1 RUNNING END ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

private ["_pname","_aigroup","_vehLoopPos","_missionSpawnChance","_spawnMarker","_spawnRadius","_markerRadius","_markerColor","_loot","_loot_lists","_loot_box","_wait_time","_spawnRoll","_position","_meters","_loot_pos","_base","_aiunit_spawn_pos","_aivehicle","_aiVehicleDObj","_aivehicle_spawn_pos","_aiheli_spawn_pos","_targetunitsAlive","_targetgroup","_target1","_attackgroup","_attacker1","_attacker2","_attacker3","_attacker4","_attacker5","_aiunit1","_aiunit2","_aiunit3","_aiunit4","_aiunit5","_aiunit6","_aiunit7","_aiunit8","_aiunit9","_aiunit10","_aiunit11","_aiunit12","_timeout"];

diag_log("[FMISSION] MISSION 3: Capture - Script Started");

_missionSpawnChance =  1;
_spawnRoll = random 1;

_pname = _this select 0;

diag_log("[FMISSION] MISSION 3: Capture  - Checking MissionSpawnChance");
if (_spawnRoll > _missionSpawnChance) exitWith 
{
diag_log format ["[FMISSION] MISSION 3: Capture  - Failed with %1 it needed to be lower than %2",_spawnRoll,_missionSpawnChance];
};

sleep .5;
diag_log("[FMISSION] MISSION 3: Capture  - Mission SpawnChance Success");

sleep .5;
diag_log("[FMISSION] MISSION 3: Capture  - Mission Script Started");

EPOCH_MISSION3_RUNNING = true;

_loot_box = "GuerillaCacheBox";
_loot_lists = [
[
["M9SD","M16A4_ACG","M16A4","ItemMachete","Binocular"],
["15Rnd_9x19_M9SD","15Rnd_9x19_M9SD","15Rnd_9x19_M9SD","ItemGoldBar","ItemGoldBar","ItemGoldBar","ItemGoldBar","ItemTrashToiletpaper"],
["DZ_CivilBackpack_EP1"]
],
[
["DMR","Sa58V_RCO_EP1","NVGoggles","Binocular_Vector"],
["20Rnd_762x51_DMR","20Rnd_762x51_DMR","20Rnd_762x51_DMR","ItemSodaMdew","PipeBomb","ItemAntibiotic","ItemGoldBar10oz"],
["DZ_GunBag_EP1"]
],
[
["MP5SD","SCAR_L_STD_Mk4CQT","ItemFlashlightRed","ItemCompass"],
["30Rnd_9x19_MP5SD","30Rnd_9x19_MP5SD","30Rnd_9x19_MP5SD","ItemSodaMdew","ItemWire","ItemSilverBar10oz","ItemSilverBar10oz","ItemSilverBar10oz"],
["DZ_TerminalPack_EP1"]
],
[
["SVD_CAMO","M8_sharpshooter","ItemWatch","Binocular"],
["10Rnd_762x54_SVD","10Rnd_762x54_SVD","10Rnd_762x54_SVD","ItemSodaMdew","ItemBurlap","ItemGoldBar","ItemGoldBar","ItemGoldBar"],
["DZ_Backpack_EP1"]
],
[
["M4A1_AIM_SD_CAMO","M4A1_HWS_GL_camo","ItemGPS","Binocular"],
["30Rnd_556x45_StanagSD","30Rnd_556x45_StanagSD","30Rnd_556x45_StanagSD","ItemSodaRbull","ItemGoldBar10oz","ItemGoldBar10oz"],
["DZ_ALICE_Pack_EP1"]
]
];
_loot = _loot_lists call BIS_fnc_selectRandom;

mission_despawn_timer = 1200;
_wait_time = 900;
_spawnRadius = 5000;
_spawnMarker = 'center';
_markerRadius = 175; // Radius the loot can spawn and used for the marker
_markerColor = "ColorBlue";
_textMarker_IconType = "mil_objective";
_markerText = format["Capture (%1)",_pname];
_markerBrush = "SOLID";

// Random location
_position = [getMarkerPos _spawnMarker,0,_spawnRadius,10,0,20,0] call BIS_fnc_findSafePos;
_loot_pos = [_position,0,(_markerRadius - 100),10,0,20,0] call BIS_fnc_findSafePos;

// FMarker Launch
[_position,_loot_pos,_markerRadius,_markerColor,false,_textMarker_IconType,_markerText,_markerBrush] execVM "\z\addons\dayz_server\FMission\FMarker\FMarker3.sqf";

diag_log(format["[FMISSION] MISSION 3: Capture - Spawning loot event at %1", _position]);
 
_aiunit_spawn_pos = [_loot_pos, 30, 50, 30, 0, 20, 0] call BIS_fnc_findSafePos;
_aivehicle_spawn_pos = [_loot_pos, 15, 15, 15, 0, 20, 0] call BIS_fnc_findSafePos;
_aiheli_spawn_pos = [_loot_pos, 30, 50, 30, 0, 20, 0] call BIS_fnc_findSafePos;
	
_base = createVehicle ["Land_fortified_nest_big",_loot_pos,[], 0, "CAN_COLLIDE"];
_base setPos _loot_pos;

sleep 1;

diag_log("[FMISSION] MISSION 3: Capture  - Loading -=FAI Units=- Started");

_aiunit1 = [_aiunit_spawn_pos,50,4,"Bandit",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

_aiunit2 = [_aiunit_spawn_pos,50,4,"Sniper",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

_aiunit3 = [_aiunit_spawn_pos,50,4,"Medic",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

_aiunit4 = [_aiunit_spawn_pos,50,4,"Bandit",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

_aiunit5 = [_aiunit_spawn_pos,50,4,"Bandit",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

_aiunit6 = [_aiunit_spawn_pos,50,4,"Medic",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

_aiunit7 = [_aiunit_spawn_pos,50,4,"Bandit",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

_aiunit8 = [_aiunit_spawn_pos,50,4,"Bandit",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

_aiunit9 = [_aiunit_spawn_pos,50,4,"Bandit",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

_aiunit10 = [_aiunit_spawn_pos,50,4,"Medic",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

_aiunit11 = [_aiunit_spawn_pos,50,4,"Bandit",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

_aiunit12 = [_aiunit_spawn_pos,50,4,"Bandit",_loot_pos,"M3"] execVM "\z\addons\dayz_server\FMission\FAI\FAI_Create_Unit.sqf";

sleep 10;
diag_log("[FMISSION] MISSION 3: Capture - Loading -=FAI=- Completed");

sleep .5;
diag_log("[FMISSION] MISSION 3: Capture - Loading -=FAI Vehicle=- Started");
_aiVehicle = createVehicle ["ArmoredSUV_PMC_DZ", _aivehicle_spawn_pos, [], 0, "NONE"];
_aiVehicle setVariable ["ObjectID","1",true];
_aiVehicle setPos _aivehicle_spawn_pos;
_aiVehicle addEventHandler ["Killed",{_this call DZAI_vehDestroyed;}];
_aiVehicle addEventHandler ["HandleDamage",{_this call DZAI_vHandleDamage}];
_aiVehicle setVariable ["Mission",1,true];

sleep 1;
diag_log("[FMISSION] MISSION 3: Capture - Loading -=FAI Vehicle=- Completed");

sleep 1;

diag_log("[FMISSION] MISSION 3: Capture - Creating Assassination Target");
// Add Assassination Target
_targetgroup = createGroup civilian;
		_target1 = _targetgroup createUnit ["Hooker4", _base, [], 0, "Form"];
			_target1 setUnitPos "DOWN";
			_target1 disableAI "MOVE";
			_target1 setCaptive true;
			removeAllItems _target1;
			
			_target1 moveInDriver _aiVehicle;
			
// Add Interior Guards
diag_log("[FMISSION] MISSION 3: Capture - Spawning Interior Attackers");
	_attackgroup = createGroup east;
	
		_attacker1 = _attackgroup createUnit ["TK_INS_Soldier_3_EP1", _base, [], 0, "Form"];
			_attacker1 setUnitPos "AUTO";
			_null = [_attacker1] execVM "\z\addons\dayz_server\FMission\FLoot\FLoot_Bandit.sqf";
			_attacker1 setUnitPos "Middle";
		
		_attacker2 = _attackgroup createUnit ["TK_Soldier_Medic_EP1", _base, [], 0, "Form"];
			_attacker2 setUnitPos "AUTO";
			_null = [_attacker2] execVM "\z\addons\dayz_server\FMission\FLoot\FLoot_Medic.sqf";
			_attacker2 setUnitPos "Middle";
			
		_attacker3 = _attackgroup createUnit ["TK_INS_Soldier_3_EP1", _base, [], 0, "Form"];
			_attacker2 setUnitPos "AUTO";
			_null = [_attacker2] execVM "\z\addons\dayz_server\FMission\FLoot\FLoot_Bandit.sqf";
			_attacker2 setUnitPos "Middle";
			
		_attacker4 = _attackgroup createUnit ["TK_INS_Soldier_3_EP1", _base, [], 0, "Form"];
			_attacker2 setUnitPos "AUTO";
			_null = [_attacker2] execVM "\z\addons\dayz_server\FMission\FLoot\FLoot_Bandit.sqf";
			_attacker2 setUnitPos "Middle";
			
		_attacker5 = _attackgroup createUnit ["TK_INS_Soldier_3_EP1", _base, [], 0, "Form"];
			_attacker2 setUnitPos "AUTO";
			_null = [_attacker2] execVM "\z\addons\dayz_server\FMission\FLoot\FLoot_Bandit.sqf";
			_attacker2 setUnitPos "Middle";
			
			_attackgroup setCombatMode "RED";
			_attackgroup setBehaviour "STEALTH";

// Add a chance to spawn a Mine Field
//[_loot_pos,east,.50] execVM "\z\addons\dayz_server\FMission\FMinefield\FMinefield.sqf";

[nil,nil,rTitleText,"MISSION: Capture - An enemy vehicle has been spotted. Capture the Vehicle and drive off, to prevent Bandits from re-supplying their friends.", "PLAIN",10] call RE;			
			
diag_log("[FMISSION] MISSION 3: Capture - Waiting...");
_timeout = time + mission_despawn_timer;
waitUntil 
{
//_targetunitsAlive = {alive _x} count (units _targetgroup);
((time > _timeout))
};

//_targetunitsAlive = {alive _x} count (units _targetgroup);


_meters = _aiVehicle distance _position;
_loop = true;
while {_loop} do {

    if (_meters > 200) then {
        vehicle_captured = true;
		_loop = false; // in case you want to exit the loop, when the vehicle is in the range
    } else {
        vehicle_captured = false;
    }; 

    _meters = _aiVehicle distance _position;
    sleep 5;
    
};

if (vehicle_captured) then
{
[nil,nil,rTitleText,"MISSION: Vehicle Captured, Good Job.", "PLAIN",10] call RE;

		// Create loot box
		diag_log("[FMISSION] MISSION 3: Capture - Target eliminated creating loot box");
		_loot_box = createVehicle [_loot_box,_loot_pos,[], 0, "NONE"];
		_loot_box setPos _loot_pos;
		clearMagazineCargoGlobal _aiVehicle;
		clearWeaponCargoGlobal _aiVehicle;
		clearBackpackCargoGlobal _aiVehicle;
				 
		// Add loot
		diag_log("[FMISSION] MISSION 3: Capture - Loot box created, adding loot to loot box");
		{
		_aiVehicle addWeaponCargoGlobal [_x,1];
		} forEach (_loot select 0);
		{
		_aiVehicle addMagazineCargoGlobal [_x,1];
		} forEach (_loot select 1);
		{
		_aiVehicle addBackpackCargoGlobal [_x,1];
		} forEach (_loot select 2);
		// Wait
		sleep 2;
		
		// Clean everything else
		EPOCH_MISSION3_RUNNING = false;
		deleteVehicle _base;
		{ deleteVehicle _x } forEach units _targetgroup;
		deleteGroup _targetgroup;
		{ deleteVehicle _x } forEach units _attackgroup;
		deleteGroup _attackgroup;
		
 		sleep _wait_time;

		deleteVehicle _loot_box;
		diag_log("[FMISSION] MISSION 3: Capture - Script Finished");
};

while {true} do {
	if (time > _timeout) then
	{
	[nil,nil,rTitleText,"[FMISSION] MISSION 3: Capture - The area was re-supplied.", "PLAIN",10] call RE;
			// Clean up
			EPOCH_MISSION3_RUNNING = false;
			deleteVehicle _base;
			{ deleteVehicle _x } forEach units _targetgroup;
			deleteGroup _targetgroup;
			{ deleteVehicle _x } forEach units _attackgroup;
			deleteGroup _attackgroup;
			diag_log("[FMISSION] MISSION 3: Capture - Script Finished");
	};
	sleep 60;
};
Link to comment
Share on other sites

  • 0

//_targetunitsAlive = {alive _x} count (units _targetgroup);
 
_loop = true;
while {_loop} do {
 
_meters = _aiVehicle distance _position;
 
    if (_meters > 200) then {
        vehicle_captured = true;
_loop = false; // in case you want to exit the loop, when the vehicle is in the range
    } else {
        vehicle_captured = false;
    }; 
    
    sleep 5;
    
};

or maybe this can help:

//_targetunitsAlive = {alive _x} count (units _targetgroup);

_loop = true;
while {_loop} do {

	_meters = (getPos _aiVehicle) distance _position;

    if (_meters > 200) then {
        vehicle_captured = true;
		_loop = false; // in case you want to exit the loop, when the vehicle is in the range
    } else {
        vehicle_captured = false;
    }; 
    
    sleep 5;
    
};

have you tried to get the output of _meters with a 

diag_log format ["DEBUG:_meters %1",_meters];

 ?

Link to comment
Share on other sites

  • 0

That script was actually working fine, i just never thought about that wait untill, which i had inbetween it. That's why i never saw results. I removed it and all is working fine :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...