From 4c86db95052dcdd0bedcdd124e30d201717962c3 Mon Sep 17 00:00:00 2001 From: jonpas Date: Tue, 18 Aug 2015 23:51:30 +0200 Subject: [PATCH] Added AddCargoItem event and function to add an item by classname --- addons/cargo/XEH_postInit.sqf | 1 + addons/cargo/XEH_preInit.sqf | 1 + addons/cargo/functions/fnc_addCargoItem.sqf | 33 +++++++++++++++++++++ addons/cargo/functions/fnc_getSizeItem.sqf | 2 +- addons/cargo/functions/fnc_initVehicle.sqf | 14 +-------- 5 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 addons/cargo/functions/fnc_addCargoItem.sqf diff --git a/addons/cargo/XEH_postInit.sqf b/addons/cargo/XEH_postInit.sqf index 8a6accb95a..e5feddb6b1 100644 --- a/addons/cargo/XEH_postInit.sqf +++ b/addons/cargo/XEH_postInit.sqf @@ -2,3 +2,4 @@ ["LoadItem", {_this call FUNC(loadItem)}] call EFUNC(common,addEventHandler); ["UnloadItem", {_this call FUNC(unloadItem)}] call EFUNC(common,addEventHandler); +["AddCargoItem", {_this call FUNC(addCargoItem)}] call EFUNC(common,addEventHandler); diff --git a/addons/cargo/XEH_preInit.sqf b/addons/cargo/XEH_preInit.sqf index 93de0f6951..8924cacfd5 100644 --- a/addons/cargo/XEH_preInit.sqf +++ b/addons/cargo/XEH_preInit.sqf @@ -2,6 +2,7 @@ ADDON = false; +PREP(addCargoItem); PREP(canLoad); PREP(canLoadItemIn); PREP(canUnloadItem); diff --git a/addons/cargo/functions/fnc_addCargoItem.sqf b/addons/cargo/functions/fnc_addCargoItem.sqf new file mode 100644 index 0000000000..8ea90d5ae9 --- /dev/null +++ b/addons/cargo/functions/fnc_addCargoItem.sqf @@ -0,0 +1,33 @@ +/* + * Author: Glowbal, Jonpas + * Adds a cargo item to the vehicle. + * + * Arguments: + * 0: Item Classname + * 1: Vehicle + * 2: Amount (default: 1) + * + * Return Value: + * None + * + * Example: + * ["item", vehicle] call ace_cargo_fnc_addItem + * + * Public: No + */ +#include "script_component.hpp" + +private ["_position", "_item", "_i"]; +params ["_itemClass", "_vehicle", ["_amount", 1]]; +TRACE_3("params",_itemClass,_vehicle,_amount); + +_position = getPos _vehicle; +_position set [1, (_position select 1) + 1]; +_position set [2, (_position select 2) + 7.5]; + +for "_i" from 1 to _amount do { + _item = createVehicle [_itemClass, _position, [], 0, "CAN_COLLIDE"]; + if !([_item, _vehicle] call FUNC(loadItem)) exitWith { + deleteVehicle _item; + }; +}; diff --git a/addons/cargo/functions/fnc_getSizeItem.sqf b/addons/cargo/functions/fnc_getSizeItem.sqf index a3556c8a25..dacd6a4982 100644 --- a/addons/cargo/functions/fnc_getSizeItem.sqf +++ b/addons/cargo/functions/fnc_getSizeItem.sqf @@ -19,7 +19,7 @@ private "_config"; params ["_item"]; -_config = (configFile >> "CfgVehicles" >> typeof _item >> QGVAR(size)); +_config = (configFile >> "CfgVehicles" >> typeOf _item >> QGVAR(size)); if (isNumber (_config)) exitWith { _item getVariable [QGVAR(size), getNumber (_config)] diff --git a/addons/cargo/functions/fnc_initVehicle.sqf b/addons/cargo/functions/fnc_initVehicle.sqf index 8449a316b2..f6426c2a75 100644 --- a/addons/cargo/functions/fnc_initVehicle.sqf +++ b/addons/cargo/functions/fnc_initVehicle.sqf @@ -25,20 +25,8 @@ _initializedClasses = GETMVAR(GVAR(initializedClasses),[]); if (isServer) then { { if (isClass _x) then { - private ["_className", "_amount","_position","_object"]; - _className = getText (_x >> "type"); - _amount = getNumber (_x >> "amount"); - _position = getPos _vehicle; - _position set [1, (_position select 1) + 1]; - _position set [2, (_position select 2) + 7.5]; - for "_i" from 1 to _amount do { - _object = createVehicle [_className, _position, [], 0, "CAN_COLLIDE"]; - if !([_object, _vehicle] call FUNC(loadItem)) exitWith { - deleteVehicle _object; - }; - }; + [getText (_x >> "type"), _vehicle, getNumber (_x >> "amount")] call FUNC(addItem); }; - nil } count ("true" configClasses (configFile >> "CfgVehicles" >> _type >> "ACE_Cargo" >> "Cargo")); };