Stormmy1950 42 Posted September 26, 2019 Ok i am currently trying to make simple spawning and despawning objects with a single ace interaction. My currently poblem is how to make a codition that checks distance between 2 objects and returns true or false This is what i have so far: _objects = nearestObjects [Targets_50m,["Target_PopUp_Moving_90deg_F"],10]; _bool = false; if(_bool) then { { deletevehicle _x; }forEach _objects; systemChat "Targets at 50m are deleted"; _bool = false; } else { _Target1 = createVehicle ["Target_PopUp_Moving_90deg_F", Targets_50m modelToWorld [0, 2, 0], [], 0, "NONE"]; _Target2 = createVehicle ["Target_PopUp_Moving_90deg_F", Targets_50m modelToWorld [0, -2, 0], [], 0, "NONE"]; _Target3 = createVehicle ["Target_PopUp_Moving_90deg_F", Targets_50m modelToWorld [0, 6, 0], [], 0, "NONE"]; _Target4 = createVehicle ["Target_PopUp_Moving_90deg_F", Targets_50m modelToWorld [0, -6, 0], [], 0, "NONE"]; _Target1 setDir 270; _Target2 setDir 270; _Target3 setDir 270; _Target4 setDir 270; _bool = true; systemChat "Targets at 50m Spawned"; }; Share this post Link to post Share on other sites
gokitty1199 225 Posted September 26, 2019 use distance. when i was making my weapon/zombie spawner/despawner, i got an array of all the players and all of the weaponholders/zombie units and simply had a control variable that determined if they should be deleted by looping through all of the objects and zombies and players with a nested foreach. so outer foreach loop was for an array of objects and zombies, the inner foreach loop was for players. i would do a check, if the object/zombie was less than 300 meters from the player, dont delete and break out of that foreach to the outter foreach. i have to go real quick but heres a quick example of what i mean { _object = _x; _deleteObject = true; { if (_object distance _x < 300) then { _deleteObject = false; //break out of loop }; } forEach _players; if (_deleteObject) then { deleteVehicle _object; }; } forEach _objects; Share this post Link to post Share on other sites
Mr H. 402 Posted September 26, 2019 43 minutes ago, gokitty1199 said: Share this post Link to post Share on other sites
Mr H. 402 Posted September 26, 2019 _fnc_deleteObjectsWithinRange = { params ["_objetcs","_posOrObject"]; { if ((_x distance _posOrObject)< 300) then {deleteVehicle _x}; } forEach _objects; }; [_myArrayOfObjects,_myDesiredPos] call _fnc_deleteObjectsWithinRange; // will delete all objects from _myArraYOfObjects within 300m from _mydesiredPos Share this post Link to post Share on other sites
Stormmy1950 42 Posted September 26, 2019 @Mr H. Ty for that but how do i spawn them again so basicly i want to spawn and delete them X amout of times ? To sum it all up how to create a Toggle codition ? Share this post Link to post Share on other sites
Mr H. 402 Posted September 26, 2019 _objects will return an empty array if there are no targets nearby anyway. So use something like if (_objects isEqualTo []) then ... Share this post Link to post Share on other sites
Stormmy1950 42 Posted September 26, 2019 @Mr H. Sorry i am still haveing problems whit this can you tell me how do i get the empty array from your function that you gave me. Share this post Link to post Share on other sites
Mr H. 402 Posted September 26, 2019 You don't need it actually just modify yours _bool = !(_objects isEqualTo []); Share this post Link to post Share on other sites
Stormmy1950 42 Posted September 26, 2019 _objects = nearestObjects [Targets_50m,["Target_PopUp_Moving_90deg_F"],10]; _bool = !(_objects isEqualTo []); if(_bool) then { { deletevehicle _x; }forEach _objects; systemChat "Targets at 50m are deleted"; //_bool = false; } else { _Target1 = createVehicle ["Target_PopUp_Moving_90deg_F", Targets_50m modelToWorld [0, 2, 0], [], 0, "NONE"]; _Target2 = createVehicle ["Target_PopUp_Moving_90deg_F", Targets_50m modelToWorld [0, -2, 0], [], 0, "NONE"]; _Target3 = createVehicle ["Target_PopUp_Moving_90deg_F", Targets_50m modelToWorld [0, 6, 0], [], 0, "NONE"]; _Target4 = createVehicle ["Target_PopUp_Moving_90deg_F", Targets_50m modelToWorld [0, -6, 0], [], 0, "NONE"]; _Target1 setDir 270; _Target2 setDir 270; _Target3 setDir 270; _Target4 setDir 270; //_bool = true; systemChat "Targets at 50m Spawned"; }; This is what i have now and I get the error on Line 2 Invalid number in Expression. Share this post Link to post Share on other sites
Mr H. 402 Posted September 26, 2019 Replace the condition itself eg if !(_objects isEqualTo []) then etc. Share this post Link to post Share on other sites
Stormmy1950 42 Posted September 26, 2019 @Mr H. Same thing same error. Share this post Link to post Share on other sites
Mr H. 402 Posted September 26, 2019 I don't see anything wrong, I'm not at my computer to test it. Check for hidden characters that might be copied along with the code from this forum it's a known issue. Also if you're trying it from the console the commented parts will throw errors. 1 Share this post Link to post Share on other sites
Stormmy1950 42 Posted September 26, 2019 @Mr H. Apperently that was it i was copying from the forum and when i type it my self the it work Big thank you For helping me with this Moderator you are clear to lock the Topic Now ;D 1 Share this post Link to post Share on other sites