ACE3/addons/refuel/functions/fnc_takeNozzle.sqf

86 lines
3.1 KiB
Plaintext
Raw Normal View History

2015-08-13 17:33:55 +00:00
/*
* Author: GitHawk
2015-08-20 20:10:26 +00:00
* Take a fuel nozzle either from a fuel truck/station or from the ground.
2015-08-13 17:33:55 +00:00
*
* Arguments:
2015-08-20 20:10:26 +00:00
* 0: Unit <OBJECT>
* 1: Target <OBJECT>
* 2: Nozzle <OBJECT> (optional)
2015-08-13 17:33:55 +00:00
*
* Return Value:
2015-08-14 01:18:54 +00:00
* None
2015-08-13 17:33:55 +00:00
*
* Example:
* [unit, target, truck] call ace_refuel_fnc_takeNozzle
*
2015-08-14 01:18:54 +00:00
* Public: No
2015-08-13 17:33:55 +00:00
*/
#include "script_component.hpp"
private ["_endPosOffset"],
2015-08-20 20:10:26 +00:00
params ["_unit", "_target", ["_nozzle", objNull]];
2015-08-13 17:33:55 +00:00
[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus);
REFUEL_HOLSTER_WEAPON
2015-08-13 17:33:55 +00:00
2015-08-20 20:10:26 +00:00
// TODO add pickup animation
_endPosOffset = [0, 0, 0];
2015-08-13 17:33:55 +00:00
if (isNull _nozzle) then { // func is called on fuel truck
2015-08-20 20:10:26 +00:00
_target setVariable [QGVAR(engineHit), _target getHitPointDamage "HitEngine", true];
_target setHitPointDamage ["HitEngine", 1];
_target setVariable [QGVAR(isConnected), true, true];
_endPosOffset = getArray (configFile >> "CfgVehicles" >> typeOf _target >> "ace_refuel_hooks");
if (count _endPosOffset == 2) then {
if (_unit distance (_target modelToWorld (_endPosOffset select 0)) < _unit distance (_target modelToWorld (_endPosOffset select 1))) then {
_endPosOffset = _endPosOffset select 0;
} else {
_endPosOffset = _endPosOffset select 1;
};
} else {
_endPosOffset = _endPosOffset select 0;
};
2015-08-13 17:33:55 +00:00
[{
params ["_unit", "_target", "_endPosOffset"];
2015-08-13 17:33:55 +00:00
_newNozzle = "ACE_refuel_fuelNozzle" createVehicle position _unit;
_newNozzle attachTo [_unit, [-0.02,-0.05,0], "righthandmiddle1"]; // TODO replace with right coordinates for real model
_unit setVariable [QGVAR(nozzle), _newNozzle];
_rope = ropeCreate [_target, _endPosOffset, _newNozzle, [0, 0, 0], 12];
_newNozzle setVariable [QGVAR(attachPos), _endPosOffset, true];
2015-08-13 17:33:55 +00:00
_newNozzle setVariable [QGVAR(source), _target, true];
_newNozzle setVariable [QGVAR(rope), _rope, true];
}, [_unit, _target, _endPosOffset], 2, 0] call EFUNC(common,waitAndExecute);
} else { // func is called in muzzle either connected or on ground
[{
2015-08-20 20:10:26 +00:00
params ["_unit", "_nozzle"];
2015-08-13 17:33:55 +00:00
_nozzle attachTo [_unit, [-0.02,-0.05,0], "righthandmiddle1"]; // TODO replace with right coordinates for real model
_unit setVariable [QGVAR(nozzle), _nozzle];
2015-08-20 20:10:26 +00:00
}, [_unit, _nozzle], 2, 0] call EFUNC(common,waitAndExecute);
_target = _nozzle getVariable QGVAR(source);
_endPosOffset = _nozzle getVariable QGVAR(attachPos);
2015-08-13 17:33:55 +00:00
};
2015-08-20 20:10:26 +00:00
[{
private ["_nozzle"];
params ["_args", "_pfID"];
_args params ["_unit", "_source", "_endPosOffset"];
if (_unit distance (_source modelToWorld _endPosOffset) > 10) exitWith {
_nozzle = _unit getVariable [QGVAR(nozzle), objNull];
if !(isNull _nozzle) then {
REFUEL_UNIT_DROP_NOZZLE
REFUEL_UNHOLSTER_WEAPON
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
[LSTRING(Hint_TooFar), 2, _unit] call EFUNC(common,displayTextStructured);
};
[_pfID] call cba_fnc_removePerFrameHandler;
};
}, 0, [_unit, _target, _endPosOffset]] call cba_fnc_addPerFrameHandler;
_unit setVariable [QGVAR(isRefueling), true];