ACE3/addons/cargo/functions/fnc_initVehicle.sqf

79 lines
2.8 KiB
Plaintext
Raw Normal View History

2015-08-10 21:07:47 +00:00
/*
* Author: Glowbal
* Initializes vehicle, adds open cargo menu action if available.
2015-08-10 21:07:47 +00:00
*
* Arguments:
2015-08-16 20:41:35 +00:00
* 0: Vehicle <OBJECT>
2015-08-10 21:07:47 +00:00
*
* Return Value:
* None
*
2015-08-16 20:41:35 +00:00
* Example:
* [vehicle] call ace_cargo_fnc_initVehicle
*
2015-08-10 21:07:47 +00:00
* Public: No
*/
#include "script_component.hpp"
params ["_vehicle"];
TRACE_1("params", _vehicle);
2016-01-19 03:53:48 +00:00
private _type = typeOf _vehicle;
2015-08-10 21:07:47 +00:00
2016-04-03 12:17:16 +00:00
if (getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(hasCargo)) != 1) exitWith {};
if (isServer) then {
{
if (isClass _x) then {
private _cargoClassname = getText (_x >> "type");
private _cargoCount = getNumber (_x >> "amount");
TRACE_3("adding ACE_Cargo", (configName _x), _cargoClassname, _cargoCount);
["ace_addCargo", [_cargoClassname, _vehicle, _cargoCount]] call CBA_fnc_localEvent;
};
} count ("true" configClasses (configFile >> "CfgVehicles" >> _type >> "ACE_Cargo" >> "Cargo"));
};
2015-08-10 21:07:47 +00:00
// do nothing if the class is already initialized
2016-01-19 03:53:48 +00:00
if (_type in GVAR(initializedVehicleClasses)) exitWith {};
2015-08-10 21:07:47 +00:00
// set class as initialized
2016-01-19 03:53:48 +00:00
GVAR(initializedVehicleClasses) pushBack _type;
2015-08-10 21:07:47 +00:00
2016-01-19 03:53:48 +00:00
if (!hasInterface) exitWith {};
2015-08-10 21:07:47 +00:00
2016-01-19 03:53:48 +00:00
TRACE_1("Adding unload cargo action to class", _type);
private _condition = {
2016-01-27 00:01:01 +00:00
GVAR(enable) && {locked _target < 2} && {alive _target} && {[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)}
2015-08-26 21:26:08 +00:00
};
2016-01-19 03:53:48 +00:00
private _statement = {
GVAR(interactionVehicle) = _target;
GVAR(interactionParadrop) = false;
2016-01-19 03:53:48 +00:00
createDialog QGVAR(menu);
};
private _text = localize LSTRING(openMenu);
private _icon = "";
2015-08-10 21:07:47 +00:00
2016-01-19 03:53:48 +00:00
private _action = [QGVAR(openMenu), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
2015-08-10 21:07:47 +00:00
[_type, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass);
// Add the paradrop self interaction for planes and helicopters
if (_vehicle isKindOf "Air") then {
private _condition = {
GVAR(enable) && {[_player, _target, []] call EFUNC(common,canInteractWith)} && {
private _turretPath = _player call CBA_fnc_turretPath;
(_player == (driver _target)) || // pilot
{(getNumber (([_target, _turretPath] call CBA_fnc_getTurret) >> "isCopilot")) == 1} || // coPilot
{_turretPath in (getArray (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(loadmasterTurrets)))}} // loadMaster turret from config
};
private _statement = {
GVAR(interactionVehicle) = _target;
GVAR(interactionParadrop) = true;
createDialog QGVAR(menu);
};
private _text = localize LSTRING(openMenu);
private _icon = "";
private _action = [QGVAR(openMenu), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
[_type, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToClass); // self action on the vehicle
};