sizraide 4 Posted July 5 Hello, I have made a script here that runs on a player and gets a nearby AI to heal that player (player must be in incapacitated state). The problem is, this code works completely fine when the player is not unconscious, but the moment the player is unconscious I get an error that waitUntil returns nil. Here is the code: Spoiler SIZ_Test = { params["_injured"]; _nearbyUnits = []; _list = getPos _injured nearEntities["Man", 25]; // Get all nearby units _list = _list - [_injured]; if(count _list > 0) then { { if(side _x == side _injured && [_x, "FirstAidKit", true] call BIS_fnc_hasItem) then { _nearbyUnits pushBack _x; }; } forEach _list; // Sort units by side and if they have first aid for "_i" from 0 to count _nearbyUnits - 1 do // Loop to get the nearest unit from the list nearby incapacitated player. { _currentDistance = (_nearbyUnits select _i) distance _injured; for "_j" from 0 to count _nearbyUnits - 1 do { _selectedDistance = (_nearbyUnits select _j) distance _injured; if(_selectedDistance < _currentDistance) then { _currentDistance = _selectedDistance; _healer = _nearbyUnits select _j; }; }; }; [_healer, _injured] spawn { params["_healer", "_injured"]; _injuredPos = getPosATL _injured; _healer doMove _injuredPos; // Move to incapacitated unit waitUntil{moveToCompleted _healer}; // Error occurs here <---- doStop _healer; _relDir = (_healer getDir _injured); _healer setFormDir (_healer getDir _injured); sleep 1; _injured setVariable ["SIZ_BeingRevived", true]; _healer setVariable ["SIZ_RevivingUnit", true]; _time = _injured call SIZ_calculateReviveTime; // Function to calculate revive time based on damage of incapacitated unit. while{alive _healer} do // Perform healing animation { _time = _time - 1; hint str _time; if(_time == 0) exitWith { _injured setVariable ["SIZ_BeingRevived", nil]; _healer setVariable ["SIZ_RevivingUnit", nil]; _healer playMoveNow "AinvPknlMstpSnonWnonDnon_medicEnd"; }; _healer playMove "AinvPknlMstpSnonWnonDnon_medic1"; _healer playMove "AinvPknlMstpSnonWnonDnon_medic2"; _healer playMove "AinvPknlMstpSnonWnonDnon_medic3"; sleep 1; }; if(alive _healer) then { // Return to leader once done. _leader = leader _healer; _healer setFormDir (_healer getDir _leader); _healer doFollow _leader; }; }; } else { // Do bunch of stuff here if healer is not found }; }; player call SIZ_Test; Any help would be appreciated.EDIT: I fixed it, I used the wrong unit for moveToCompleted. The code kind of works, but only works when the unit is not in a incapacitated state. Share this post Link to post Share on other sites
Larrow 2753 Posted July 7 Spoiler SIZ_Test = { params["_injured"]; // Get all nearby healers in order of distance _nearbyHealers = _injured nearEntities["Man", 25] select{ _x isNotEqualTo _injured && { side _x isEqualTo side _injured && { [ _x, "FirstAid", true ] call BIS_fnc_hasItem }} } apply{ [ _x distance _injured, _x ] }; _nearbyHealers sort true; if( _nearbyHealers isNotEqualTo [] ) then { [ _nearbyHealers select 0 select 1, _injured ] spawn { params["_healer", "_injured"]; //... 1 Share this post Link to post Share on other sites
sizraide 4 Posted July 8 9 hours ago, Larrow said: Hide contents SIZ_Test = { params["_injured"]; // Get all nearby healers in order of distance _nearbyHealers = _injured nearEntities["Man", 25] select{ _x isNotEqualTo _injured && { side _x isEqualTo side _injured && { [ _x, "FirstAid", true ] call BIS_fnc_hasItem }} } apply{ [ _x distance _injured, _x ] }; _nearbyHealers sort true; if( _nearbyHealers isNotEqualTo [] ) then { [ _nearbyHealers select 0 select 1, _injured ] spawn { params["_healer", "_injured"]; //... I really appreciate the solution Larrow, I have an unrelated problem. How do you work around when a unit radio's "NEGATIVE" in chat when it refuses to perform a doMove command. I often get this issue when the position is inside a building, because I have this command running in a script where the healer moves to the incapacitated unit. I have tried getting all the positions in a building and looping through all those positions to find the nearest one to the incapacitated unit, but it doesn't work. Share this post Link to post Share on other sites