Robustcolor 30 Posted November 28, 2019 Hi, could someone help me finish this? My goal is to have a script waiting for any player to be near the specific marker then it runs the code. The question is with the While {true} do i would like to loop a check if those Ai's near the specific marker is still alive or if theres no players left within a specific distance. Is it possible to fetch all Ai's near the specific marker with the command forEach (allUnits select {!isPlayer _x}); adding some more code to it or do i need to be more specific about which groups to fetch? waitUntil {sleep 5; allPlayers findIf {(_x distance2d _markerpos) < (250 + (random 50)) && (ASLToAGL getPosASL _x)#2 < 2} > -1}; private _Aispawn = [] spawn Robust_fnc_Aispawn; _allUnits inAreaArray [getMarkerPos _markerpos, 150, 150]; Below is just an example how i would like it to run. while {true} do { if (_Ainearspecificmarker == 0) or (not alive _Leader )) then { "Completed" remoteExec ["hint"]; [] spawn { "EventTrack03_F_Curator" remoteExec ["playMusic",west,false]; }; }; if (allPlayers findIf {_x distance2D getMarkerpos _markerpos > 350} > -1) then { "Failed" remoteExec ["hint"]; Remove all Ai enemy near the specific marker; }; sleep 5; }; Also, is it possible to remoteExec a hint and playmusic only to the players near the specific marker? Thanks! Share this post Link to post Share on other sites
Dedmen 2653 Posted November 28, 2019 1 minute ago, Robustcolor said: Is it possible to fetch all Ai's near the specific marker with the command forEach (allUnits select {!isPlayer _x}); adding some more code or do i need to be more specific about which groups to fetch? allUnits combined with inAreaArray https://community.bistudio.com/wiki/inAreaArray you can give it the array of objects, and the marker name so just _unitsInArea = allUnits inAreaArray _currentMission and after that filter out all players (you do it after because its faster that way) if in marker is not enough, you can use alt syntax 3 from biki. allUnits inAreaArray [getMarkerPos _currentMission, 350, 350]; 1 Share this post Link to post Share on other sites
Robustcolor 30 Posted November 28, 2019 5 hours ago, Dedmen said: allUnits combined with inAreaArray https://community.bistudio.com/wiki/inAreaArray you can give it the array of objects, and the marker name so just _unitsInArea = allUnits inAreaArray _currentMission and after that filter out all players (you do it after because its faster that way) if in marker is not enough, you can use alt syntax 3 from biki. allUnits inAreaArray [getMarkerPos _currentMission, 350, 350]; Thanks Dedmen, how would i delete the units i fetch with these commands? Not sure how to filter out players. Something like this? private _enemy = count (allUnits + vehicles inAreaArray [getMarkerPos "marker_0", 50, 50]); if ((_enemy == 1) or (!alive _leader)) then { {deletevehicle} something? {deletevehicle} _leader; }; or _enemy = count (allUnits select {!isPlayer _x} inAreaArray [getMarkerPos "marker_0",50,50]); if (_enemy == 0) then { "Completed" remoteExec ["hint"]; }; Share this post Link to post Share on other sites
Robustcolor 30 Posted November 28, 2019 Got it to work, If you have any tips to improve the script let me know. waitUntil {sleep 1; allPlayers findIf {(_x distance2d getmarkerpos "marker_0") < (50 + (random 20)) && (ASLToAGL getPosASL _x)#2 < 2} > -1}; for "_i" from 1 to 2 do { private ["_grp1","_unit"]; _grp01 = createGroup [east, true]; _unit = _grp01 createUnit [selectRandom ["O_Soldier_TL_F","O_Soldier_F"], getmarkerpos "marker_0", [], 10, "FORM"]; sleep 1; }; while {true} do { if (allPlayers findIf {_x distance2D getMarkerpos "marker_0" > 60} > -1) exitWith { "Completed allPlayers check" remoteExec ["hint"]; {deleteVehicle _x;} count (allUnits select {!isPlayer _x} inAreaArray [getMarkerPos "marker_0",50,50]); {deleteVehicle _x;} count (allDead inAreaArray [getMarkerPos "marker_0",50,50]); }; if (count (allUnits select {!isPlayer _x} inAreaArray [getMarkerPos "marker_0",50,50])<=1) exitWith { "Completed _enemy check" remoteExec ["hint"]; {deleteVehicle _x;} count (allUnits select {!isPlayer _x} inAreaArray [getMarkerPos "marker_0",50,50]); {deleteVehicle _x;} count (allDead inAreaArray [getMarkerPos "marker_0",50,50]); }; sleep 1; "New loop" remoteExec ["hint"]; }; Share this post Link to post Share on other sites
Dedmen 2653 Posted November 29, 2019 11 hours ago, Robustcolor said: (allUnits select {!isPlayer _x} inAreaArray [getMarkerPos "marker_0",50,50]) 18 hours ago, Dedmen said: and after that filter out all players (you do it after because its faster that way) (allUnits inAreaArray [getMarkerPos "marker_0",50,50]) select {!isPlayer _x} Share this post Link to post Share on other sites
killzone_kid 1329 Posted November 29, 2019 (allUnits - allPlayers) inAreaArray [getMarkerPos "marker_0",50,50] 2 Share this post Link to post Share on other sites
Dedmen 2653 Posted November 29, 2019 3 hours ago, killzone_kid said: (allUnits - allPlayers) Wow. Sometimes you can't see the tree because the forest is blocking the view. (That sounds better in german..) I wonder if that's faster, but select should be so slow that your variant should be the best in most cases. 1 Share this post Link to post Share on other sites
killzone_kid 1329 Posted November 29, 2019 19 minutes ago, Dedmen said: I wonder if that's faster In C++ would be slower most likely than 1 straight iteration, but in SQF who knows Share this post Link to post Share on other sites
Robustcolor 30 Posted November 29, 2019 On 11/29/2019 at 10:48 AM, killzone_kid said: (allUnits - allPlayers) inAreaArray [getMarkerPos "marker_0",50,50] So i guess it should look something like this then or is it wrong? { if (count (allUnits - allPlayers inAreaArray [getMarkerPos "marker_0",50,50])<=1) exitWith { "Completed _enemy check" remoteExec ["hint"]; };}; This is how it looks like now. My call command at the top is to prevent from spawning mission near a player, maybe there's a better way of checking. private _currentMission = selectRandom ["S1","S2","S3","S4","S5"]; Call { if (allPlayers findIf {_x distance2D getMarkerpos _currentMission < 30} > -1) exitWith { [] execVM "Test.sqf"; }; private _marker2 = createMarker ["Marker2",getmarkerpos _currentMission]; _marker2 setMarkerShape "ELLIPSE"; _marker2 setMarkerSize [150,150]; _marker2 setMarkerBrush "Cross"; _marker2 setMarkerAlpha 1; _marker2 setMarkerColor "ColorOPFOR"; private _marker3 = getMarkerpos _marker2; waitUntil {sleep 1; allPlayers findIf {(_x distance2d _marker3) < (150 + (random 20)) && (ASLToAGL getPosASL _x)#2 < 2} > -1}; for "_i" from 1 to 2 do { private ["_grp1","_unit"]; _grp01 = createGroup [east, true]; _unit = _grp01 createUnit [selectRandom ["O_Soldier_TL_F","O_Soldier_F"], _marker3, [], 10, "FORM"]; sleep 1; }; while {true} do { if (allPlayers findIf {_x distance2D _marker3 > 200} > -1) exitWith { "Completed allPlayers check" remoteExec ["hint"]; {deleteVehicle _x;} count (allUnits - allPlayers inAreaArray [_marker3,50,50]); {deleteVehicle _x;} count (allDead inAreaArray [_marker3,50,50]); }; if (count (allUnits - allPlayers inAreaArray [_marker3,50,50])<=1) exitWith { "Completed _enemy check" remoteExec ["hint"]; {deleteVehicle _x;} count (allUnits - allPlayers inAreaArray [_marker3,50,50]); {deleteVehicle _x;} count (allDead inAreaArray [_marker3,50,50]); }; sleep 1; "New loop" remoteExec ["hint"]; }; deleteMarker "Marker2"; [] execVM "Test.sqf"; }; @killzone_kid and while we're at it, should i start skip using }]} forEach (allUnits select {!isPlayer _x}); and just start using }]} forEach (allUnits - allPlayers); Example: { _x setSkill 1; } forEach (allUnits - allPlayers); Share this post Link to post Share on other sites
Robustcolor 30 Posted December 1, 2019 Thanks @Dedmen and @killzone_kid. Share this post Link to post Share on other sites