Biscuit90 4 Posted July 31, 2019 Hi everyone, What is the best way to spawn/despawn ai's if a player is near or far away from a specific marker? I have two different codes but not sure if it's a good way to execute for what i need in my mission. i'm using multiple markers on my mission to spawn and despawn ai's if players is near but i can't figure out how to make it into one script using something like Markers=["1","2","3","4","5","6","7","8","9","10"]; then spawn/despawn if player is near or driving away. [] spawn { while {true} do { sleep 5; Call { if ({(_x distance2d getMarkerpos "test"< 10)} count allPlayers > 0) exitWith { _grp01 = [getMarkerpos "test", east, ["I_L_Looter_SMG_F","I_L_Looter_SG_F","I_L_Looter_Pistol_F","I_L_Looter_Rifle_F","I_L_Hunter_F","I_L_Criminal_SMG_F","I_L_Criminal_SG_F"],[],[],[1,1],[1,1]] call BIS_fnc_spawnGroup; {_x setSkill ["AimingAccuracy",0.1]} forEach (units _grp01); _grp01 enableDynamicSimulation true; _grp01 allowFleeing 0; _grp01 deleteGroupWhenEmpty true; _grp01 setSpeedMode "LIMITED"; _grp01 setBehaviour "SAFE"; _grp01 setCombatMode "Red"; [_grp01, getMarkerpos "test"] call bis_fnc_taskDefend; waitUntil {sleep 5; ({(_x distance2d getMarkerpos "test") < 20} count allPlayers < 1)}; {deleteVehicle _x;}forEach units _grp01; deleteGroup _grp01; {deleteVehicle _x;} count allDead; };}; }; }; Second code [] spawn { waitUntil {sleep 5; ({(_x distance2d getMarkerpos "test1") < 10} count allPlayers > 0)}; _grp01 = [getMarkerpos "test1", east, ["I_L_Looter_SMG_F","I_L_Looter_SG_F","I_L_Looter_Pistol_F","I_L_Looter_Rifle_F","I_L_Hunter_F","I_L_Criminal_SMG_F","I_L_Criminal_SG_F"],[],[],[1,1],[1,1]] call BIS_fnc_spawnGroup; {_x setSkill ["AimingAccuracy",0.1]} forEach (units _grp01); _grp01 enableDynamicSimulation true; _grp01 allowFleeing 0; _grp01 deleteGroupWhenEmpty true; _grp01 setSpeedMode "LIMITED"; _grp01 setBehaviour "SAFE"; _grp01 setCombatMode "Red"; [_grp01, getMarkerpos "test"] call bis_fnc_taskDefend; waitUntil {sleep 5; ({(_x distance2d getMarkerpos "test1") < 30} count allPlayers < 1)}; {deleteVehicle _x;}forEach units _grp01; deleteGroup _grp01; private _bridge = [] spawn Biscuit_fnc_bridge; }; Share this post Link to post Share on other sites
wogz187 1086 Posted July 31, 2019 @Biscuit90, As you know there are lots of ways to do this. It's a "whack-a-mole". You know how to spawn cool dudes. The module I made the other day has everything you need for the rest. Like this, zoneHINT= ["Zone Exited", " Zone One ", " Zone Two ", " Zone Three "] select zoneID; switch (zoneID) do { case 1: { hint format ["You entered %1", zoneHINT]; ["task1",[area1_1,true]] call BIS_fnc_taskSetDestination; enemyMark setPos (getPos area1_1); execVM "badguys.sqf"; }; case 2: { hint format ["You entered %1", zoneHINT]; ["task1",[area2_1,true]] call BIS_fnc_taskSetDestination; enemyMark setPos (getPos area2_1); execVM "badguys.sqf"; }; case 3: { hint format ["You entered %1", zoneHINT]; ["task1",[area3_1,true]] call BIS_fnc_taskSetDestination; enemyMark setPos (getPos area3_1); execVM "badguys.sqf"; }; case 0: { hint format ["%1", zoneHINT]; ["task1",[objNULL,false]] call BIS_fnc_taskSetDestination; enemyMark setPos (getPos locationNULL); }; }; Make area triggers in the editor which switch the variable "zoneID" from 0 to 1, 2, 3 depending on which area the player is in. And back to 0 on deactivation. Look at the module and you can add a layer of randomness to the area selection. 1 Share this post Link to post Share on other sites
wogz187 1086 Posted August 1, 2019 enemyDEST= []spawn { waitUntil { sleep 1; (vehicle player distance enemyMark1 < 50) }; hint "You entered Zone 1"; enemyMark setpos (getpos enemyMark1); execVM "badguys.sqf"; }; Or that's even more simple and no trigger required just make "enemyMark#" for each zone. badguys.sqf-- just an example Emark = createMarker ["Enemy", enemyMark]; sleep 1; badguys = [getmarkerPOS "Enemy", east, ["I_C_Soldier_Bandit_8_F", "I_G_sharpshooter_F", "I_C_Soldier_Bandit_8_F"]] call BIS_fnc_SpawnGroup; _wp1 = badguys addwaypoint [position player ,0]; _wp1 setwaypointtype "move"; 1 Share this post Link to post Share on other sites
Biscuit90 4 Posted August 1, 2019 Thanks @wogz187 1 Share this post Link to post Share on other sites
Smart Games 76 Posted August 2, 2019 _Markers = ["m1","m2","m3","m4","m5","m6","m7","m8","m9","m10"]; while {true} do { { _distance = player distance _x; if (_distance < 300) then { _count = count nearEntities (getmarkerpos _x) ["Man", 300]; if (count < 3) then { _pos = getmarkerpos _x; _group = [_pos, east, ["I_C_Soldier_Bandit_8_F", "I_G_sharpshooter_F", "I_C_Soldier_Bandit_8_F"]] call BIS_fnc_SpawnGroup; sleep 0.5; [_group, _pos, 200] call bis_fnc_taskPatrol; } else {}; }; if (_distance > 300) then { {deletevehicle _x} foreach nearEntities (getmarkerpos _x) ["Man", 300]; }; } foreach _Markers; sleep 2; }; 🙂 1 Share this post Link to post Share on other sites
Smart Games 76 Posted August 2, 2019 @wogz187, could you test it? Share this post Link to post Share on other sites
wogz187 1086 Posted August 2, 2019 @Smart Games, If we can agree that I didn't screw up your syntax, _Markers = ["m1","m2","m3","m4"]; //"m5","m6","m7","m8","m9","m10" while {true} do { { _distance = player distance _x; if (_distance < 300) then { _count = count nearEntities (getmarkerpos _x) ["Man", 300]; if (_count < 3) then { _pos = getmarkerpos _x; _group = [_pos, east, ["I_C_Soldier_Bandit_8_F", "I_G_sharpshooter_F", "I_C_Soldier_Bandit_8_F"]] call BIS_fnc_SpawnGroup; sleep 0.5; [_group, _pos, 200] call bis_fnc_taskPatrol; } else {}; }; if (_distance > 300) then { {deletevehicle _x} foreach nearEntities (getmarkerpos _x) ["Man", 300]; }; } foreach _Markers; sleep 2; }; Firstly I tried it exactly as was (after editing out a nonsense amount of "?"-- the most I've ever seen!). No joy. I went through line by line and just moved stuff around so I could see it better and made sure there were no more hidden "?" lurking about. It stops at: "_count = count nearEntities (getmarkerpos _x) ["Man", 300];", missing ";". I changed: "if (count < 3) then" to "if (_count < 3) then", because I think that was how it's supposed to go but it doesn't matter, the script doesn't make it that far. It seems like you have the right idea but maybe something with params or syntax. 1 Share this post Link to post Share on other sites
Smart Games 76 Posted August 2, 2019 Thank you, i will try to fix it at home 🙂 Share this post Link to post Share on other sites
Biscuit90 4 Posted August 2, 2019 Not sure if it's a good way to do it but i made it into a switch, so when a player is near one of the marker it spawns ai's and when the player is far away it despawns the ai's. [] spawn { while {true} do { sleep 5; Call { if ({(_x distance2d getMarkerpos "test"< 300)} count allPlayers > 0) exitWith { _grp01 = [getMarkerpos "test", east, ["I_L_Looter_SMG_F","I_L_Looter_SG_F","I_L_Looter_Pistol_F","I_L_Looter_Rifle_F","I_L_Hunter_F","I_L_Criminal_SMG_F","I_L_Criminal_SG_F"],[],[],[1,1],[1,1]] call BIS_fnc_spawnGroup; {_x setSkill ["AimingAccuracy",0.01]} forEach (units _grp01); _grp01 enableDynamicSimulation true; _grp01 allowFleeing 0; _grp01 deleteGroupWhenEmpty true; _grp01 setSpeedMode "LIMITED"; _grp01 setBehaviour "AWARE"; _grp01 setCombatMode "Red"; [_grp01, getMarkerpos "test"] call bis_fnc_taskDefend; waitUntil {sleep 5; ({(_x distance2d getMarkerpos "test") < 300} count allPlayers < 1)}; {deleteVehicle _x;}forEach units _grp01; deleteGroup _grp01; {deleteVehicle _x;} count allDead; }; if ({(_x distance2d getMarkerpos "test2"< 300)} count allPlayers > 0) exitWith { _grp01 = [getMarkerpos "test2", east, ["I_L_Looter_SMG_F","I_L_Looter_SG_F","I_L_Looter_Pistol_F","I_L_Looter_Rifle_F","I_L_Hunter_F","I_L_Criminal_SMG_F","I_L_Criminal_SG_F"],[],[],[1,1],[1,1]] call BIS_fnc_spawnGroup; {_x setSkill ["AimingAccuracy",0.1]} forEach (units _grp01); _grp01 enableDynamicSimulation true; _grp01 allowFleeing 0; _grp01 deleteGroupWhenEmpty true; _grp01 setSpeedMode "LIMITED"; _grp01 setBehaviour "AWARE"; _grp01 setCombatMode "Red"; [_grp01, getMarkerpos "test2"] call bis_fnc_taskDefend; waitUntil {sleep 5; ({(_x distance2d getMarkerpos "test2") < 300} count allPlayers < 1)}; {deleteVehicle _x;}forEach units _grp01; deleteGroup _grp01; {deleteVehicle _x;} count allDead; };};};}; 2 Share this post Link to post Share on other sites
Smart Games 76 Posted August 3, 2019 The idea isn't bad, but don't forget: you need a lot of code for every marker. 🙂Maybe it's better to work with a function: fnc_test = { _marker = _this; if ({(_x distance2d getMarkerpos _marker < 300)} count allPlayers > 0) exitWith { _grp01 = [getMarkerpos _marker, east, ["I_L_Looter_SMG_F","I_L_Looter_SG_F","I_L_Looter_Pistol_F","I_L_Looter_Rifle_F","I_L_Hunter_F","I_L_Criminal_SMG_F","I_L_Criminal_SG_F"],[],[],[1,1],[1,1]] call BIS_fnc_spawnGroup; {_x setSkill ["AimingAccuracy",0.01]} forEach (units _grp01); _grp01 enableDynamicSimulation true; _grp01 allowFleeing 0; _grp01 deleteGroupWhenEmpty true; _grp01 setSpeedMode "LIMITED"; _grp01 setBehaviour "AWARE"; _grp01 setCombatMode "Red"; [_grp01, getMarkerpos _marker] call bis_fnc_taskDefend; }; }; call it with: while {true} do { sleep 5; [“m1“] spawn fnc_test; //*1 [“m2“] spawn fnc_test; //... }; *1 or: _markers: [“m1“, “m2“ , “m3“ , “m4“]; { [_x] spawn fnc_test} foreach _markers; 2 Share this post Link to post Share on other sites
Biscuit90 4 Posted August 3, 2019 Thanks @Smart Games I made it into this _marker = ["test","test2"]; { [_x] spawn Biscuit_fnc_bridgeloop } foreach _marker; Then _marker = _this; while {true} do { sleep 5; Call { if ({(_x distance2d getMarkerpos _marker < 10)} count allPlayers > 0) exitWith { _grp01 = [getMarkerpos _marker, east, ["I_L_Looter_SMG_F","I_L_Looter_SG_F","I_L_Looter_Pistol_F","I_L_Looter_Rifle_F","I_L_Hunter_F","I_L_Criminal_SMG_F","I_L_Criminal_SG_F"],[],[],[1,1],[1,1]] call BIS_fnc_spawnGroup; {_x setSkill ["AimingAccuracy",0.01]} forEach (units _grp01); _grp01 enableDynamicSimulation true; _grp01 allowFleeing 0; _grp01 deleteGroupWhenEmpty true; _grp01 setSpeedMode "LIMITED"; _grp01 setBehaviour "SAFE"; _grp01 setCombatMode "Red"; [_grp01, getmarkerpos _marker] call bis_fnc_taskDefend; waitUntil {sleep 5; ({(_x distance2d getMarkerpos _marker) < 30} count allPlayers < 1)}; {deleteVehicle _x;}forEach units _grp01; deleteGroup _grp01; {deleteVehicle _x;} count allDead; };};}; Works good. Not sure about this one Test1 = { _marker = _this; while {true} do { sleep 5; Call { if ({(_x distance2d getMarkerpos _marker < 10)} count allPlayers > 0) exitWith { _grp01 = [getMarkerpos _marker, east, ["I_L_Looter_SMG_F","I_L_Looter_SG_F","I_L_Looter_Pistol_F","I_L_Looter_Rifle_F","I_L_Hunter_F","I_L_Criminal_SMG_F","I_L_Criminal_SG_F"],[],[],[1,1],[1,1]] call BIS_fnc_spawnGroup; {_x setSkill ["AimingAccuracy",0.01]} forEach (units _grp01); _grp01 enableDynamicSimulation true; _grp01 allowFleeing 0; _grp01 deleteGroupWhenEmpty true; _grp01 setSpeedMode "LIMITED"; _grp01 setBehaviour "SAFE"; _grp01 setCombatMode "Red"; [_grp01, getmarkerpos _marker] call bis_fnc_taskDefend; waitUntil {sleep 5; ({(_x distance2d getMarkerpos _marker) < 30} count allPlayers < 1)}; {deleteVehicle _x;}forEach units _grp01; deleteGroup _grp01; {deleteVehicle _x;} count allDead; };};};}; _marker = ["test","test2"]; {[_x] spawn Test1} foreach _marker; But works too, everything in one file. 1 Share this post Link to post Share on other sites
Biscuit90 4 Posted August 4, 2019 One more question, if i spawn a function from initserver with _marker = ["test","test2"]; { [_x] spawn Biscuit_fnc_Looters } foreach _marker; Should i use [] spawn { _grp01 = [getMarkerpos _marker, east, ["I_L_Looter_SMG_F","I_L_Looter_SG_F","I_L_Looter_Pistol_F","I_L_Looter_Rifle_F","I_L_Hunter_F","I_L_Criminal_SMG_F","I_L_Criminal_SG_F"],[],[],[1,1],[1,1]] call BIS_fnc_spawnGroup; }; Or only _grp01 = [getMarkerpos _marker, east, ["I_L_Looter_SMG_F","I_L_Looter_SG_F","I_L_Looter_Pistol_F","I_L_Looter_Rifle_F","I_L_Hunter_F","I_L_Criminal_SMG_F","I_L_Criminal_SG_F"],[],[],[1,1],[1,1]] call BIS_fnc_spawnGroup; Share this post Link to post Share on other sites
Dedmen 2714 Posted August 5, 2019 12 hours ago, Biscuit90 said: [] spawn { _grp01 = you are assigning a variable you never read. and the spawn is useless, if you want a "spawn" you can just spawn the BIS function instead of "call"ing it But afaik you don't need to spawn fnc_spawnGroup. So.. 12 hours ago, Biscuit90 said: Or only That. Share this post Link to post Share on other sites