Hello all!
In working a bit on my mission, I realised I needed a function for determining the closest waypoint to any particular map spot. So what I did was I...erm...created one.
I suck at math, I really do, and I'm not generally too skilled with all kinds of embedded commands and whatnot. Also I'm not very skilled at properly setting up things (with tabs and {'s and ]'s all in the right place), so it might not be the fastest, most efficient, nor the prettiest way of doing this...but well, it's not a particularly complicated thing it does anyway.
***********
findNearestWaypoint.sqf function:
Input 2d position (from onMapSingleClick or waypointPosition for instance).
Input name of trigger that covers wider area you want checked/is activated by side you want checked (or Anybody if you don't care).
(Optionally input minimum distance the waypoint has to be from the 2d position for it to return anything)
Output : waypoint (in waypoint format, i.e. [GroupName, WaypointNumber]) closest to position input.
************
I'm sure Mandoble or someone could rewrite this script in about 15 minutes to only take up three lines or so, but what the heck.
They're busy doing other things. Basically what the function does is:
1) Create list from trigger of all possible units within the trigger radius.
2) Determine groups by finding out which are the group leaders of the units
3) Create an array of all the waypoints of all the groups
4) Check which waypoints are within the needed distance (by default, 1000m from the 2d position)
5) Check which waypoint is closest.
6) Output closest waypoint.
Use:
preload the file by calling it for instance in the init.sqs with:
RUG_FNWP = compile loadFile "findNearestWaypoint.sqf"
Create a trigger, give it an area corresponding to the WHOLE area of -units- you want checked, and make it Activated By: (SIDE you want checked - or anybody).
Call the function by inputting the two necessary pieces of data: a 2d position ([x,y]) + name of the trigger created above. Example: hint format ["%1", [waypointPosition (waypoints Player select 1), TriggerName] call RUG_FNWP]
Enjoy!
Example mission + readme attached below. Enjoy!
Wolfrug out.
OFPEC DOWNLOAD