a3_exile_occupation/scripts/reactions/comeUnstuck.sqf

76 lines
3.1 KiB
Plaintext
Raw Normal View History

// Unstuck based on a function written by Chris (infiSTAR)
// http://pastebin.com/73pjvXPw
private["_vehicle","_curPos","_oldvehPos","_engineTime","_newPos"];
_vehicle = _this select 0;
if(count(crew _vehicle) > 0)then
{
_curPos = position _vehicle;
_newPos = _curPos;
_oldvehPos = _vehicle getVariable["vehPos",[0,0,0]];
if(isNil "_oldvehPos") then { _oldvehPos = [0,0,0]; };
if(str _oldvehPos != "[0,0,0]")then
{
if(_curPos distance _oldvehPos < 2)then
{
_engineTime = _vehicle getVariable["engineTime",-1];
if(_engineTime < 0)then
{
_vehicle setVariable["engineTime",time];
};
if(time - _engineTime > 10)then
{
_logDetail = format ["[OCCUPATION:Unstuck]:: %1 is stuck,attempting to unstick from %2 @ %3",_vehicle,_curPos,time];
[_logDetail] call SC_fnc_log;
_vehicle setVariable["engineTime",-1];
_vehicle setVectorUp [0,0,1];
_originalSpawnLocation = _vehicle getVariable "SC_vehicleSpawnLocation";
_group = group _vehicle;
//_vehClass = _vehicle getVariable "vehClass";
_vehClass = typeOf _vehicle;
if(_vehicle isKindOf "LandVehicle") then
{
//_newPos = [ _curPos, 1, 15, [ 0, 0, 1, 0, 0, 0, 0, 0, true] ] call DMS_fnc_FindSafePos_InRange;
//_newPos = [_curPos, 5, 20, 3, 0, 20, 0] call BIS_fnc_findSafePos;
_tempPos = _curPos findEmptyPosition [0,50,_vehClass];
_newPos = [_tempPos select 0, _tempPos select 1, 0];
_vehicle setPosATL _newPos;
};
if(_vehicle isKindOf "Ship") then
{
//_newPos = [ _curPos, 1,15, [ 0, 0, 1, 0, 0, 0, 0, 0, true, true ] ] call DMS_fnc_FindSafePos_InRange;
//_newPos = [_curPos, 5, 20, 3, 2, 20, 0] call BIS_fnc_findSafePos;
_newPos = _curPos findEmptyPosition [0,50,_vehClass];
_newPos = [_newPos select 0, _newPos select 1, 0];
_vehicle setPosATL _newPos;
};
if(_vehicle isKindOf "Air") then
{
_newPos = _curPos;
};
_GroupLeader = leader (group _vehicle);
_GroupLeader doMove _originalSpawnLocation;
[_group, _originalSpawnLocation, 2000] call bis_fnc_taskPatrol;
_group setBehaviour "AWARE";
_group setCombatMode "RED";
_logDetail = format ["[OCCUPATION:Unstuck]:: %1 was stuck and was moved from %2 to %3 @ %4",_vehicle,_curPos,_newPos, time];
[_logDetail] call SC_fnc_log;
};
};
};
_vehicle setVariable["vehPos",_newPos];
};