summaryrefslogtreecommitdiffstats
path: root/Common/Functions/Common_SortByDistance.sqf
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.pro>2026-06-11 19:38:09 +0300
committerhybrid <hybrid@hybridlabs.pro>2026-06-11 19:38:09 +0300
commita3a91d4f45b22fd487ecbc954ad979be5d03efdd (patch)
treea554ab159a347dcd6c00ca1c7c26c1ec3ac0a6bd /Common/Functions/Common_SortByDistance.sqf
downloada2wf_chernarus-a3a91d4f45b22fd487ecbc954ad979be5d03efdd.tar.gz
a2wf_chernarus-a3a91d4f45b22fd487ecbc954ad979be5d03efdd.tar.bz2
a2wf_chernarus-a3a91d4f45b22fd487ecbc954ad979be5d03efdd.zip
Diffstat (limited to 'Common/Functions/Common_SortByDistance.sqf')
-rw-r--r--Common/Functions/Common_SortByDistance.sqf24
1 files changed, 24 insertions, 0 deletions
diff --git a/Common/Functions/Common_SortByDistance.sqf b/Common/Functions/Common_SortByDistance.sqf
new file mode 100644
index 0000000..a34680e
--- /dev/null
+++ b/Common/Functions/Common_SortByDistance.sqf
@@ -0,0 +1,24 @@
+Private["_count","_count1","_current","_distance","_nearest","_nearestDistance","_object","_objects","_sorted","_total"];
+
+_object = _this Select 0;
+_objects = +(_this Select 1);
+
+_sorted = [];
+
+_total = Count _objects;
+for [{_count = 0},{_count < _total},{_count = _count + 1}] do {
+ _nearest = ObjNull;
+ _nearestDistance = 100000;
+
+ for [{_count1 = Count _objects - 1},{_count1 >= 0},{_count1 = _count1 - 1}] do {
+ _current = _objects Select _count1;
+ _distance = _current Distance _object;
+
+ if (_distance < _nearestDistance) then {_nearest = _current;_nearestDistance = _distance};
+ };
+
+ _sorted = _sorted + [_nearest];
+ _objects = _objects - [_nearest];
+};
+
+_sorted \ No newline at end of file