I'm trying to make my own CTF mode where i want to find the nearest unit within 5 meters of the flag where that unit is _unit. i have been searching around in different forums but cannot find anything that i can use that works. I am quite new to scripting and trying to learn as much as i can.
This is what i have so far:
//the init of the flag
[[blueflag,["Pickup","blueflag.sqf"]],"addAction",true] call BIS_fnc_MP;
//blueflag.sqf
_unit playActionNow "MedicOther";
sleep 6;
blueflag attachto [_unit, [0, 0.4, 5] ];
scopeName "loop";
while {alive _unit} do {
if (!alive _unit) then {detach blueflag; blueflag setpos getpos _unit; breakTo "loop2"} else {breakTo "loop"};
scopeName "loop2";
if (!alive _unit) then {[[blueflag,["Pickup","blueflag.sqf"]],"addAction",true] call BIS_fnc_MP; breakTo "loop";} else {breakTo "loop2"};
this code works when i make _unit = player. But if the player dies and someone else picks up the flag i want _unit to change to the unit which picked up the flag.