Added AddCargoItem event and function to add an item by classname

This commit is contained in:
jonpas 2015-08-18 23:51:30 +02:00
parent e110874800
commit 4c86db9505
5 changed files with 37 additions and 14 deletions

View File

@ -2,3 +2,4 @@
["LoadItem", {_this call FUNC(loadItem)}] call EFUNC(common,addEventHandler); ["LoadItem", {_this call FUNC(loadItem)}] call EFUNC(common,addEventHandler);
["UnloadItem", {_this call FUNC(unloadItem)}] call EFUNC(common,addEventHandler); ["UnloadItem", {_this call FUNC(unloadItem)}] call EFUNC(common,addEventHandler);
["AddCargoItem", {_this call FUNC(addCargoItem)}] call EFUNC(common,addEventHandler);

View File

@ -2,6 +2,7 @@
ADDON = false; ADDON = false;
PREP(addCargoItem);
PREP(canLoad); PREP(canLoad);
PREP(canLoadItemIn); PREP(canLoadItemIn);
PREP(canUnloadItem); PREP(canUnloadItem);

View File

@ -0,0 +1,33 @@
/*
* Author: Glowbal, Jonpas
* Adds a cargo item to the vehicle.
*
* Arguments:
* 0: Item Classname <STRING>
* 1: Vehicle <OBJECT>
* 2: Amount <NUMBER> (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;
};
};

View File

@ -19,7 +19,7 @@ private "_config";
params ["_item"]; params ["_item"];
_config = (configFile >> "CfgVehicles" >> typeof _item >> QGVAR(size)); _config = (configFile >> "CfgVehicles" >> typeOf _item >> QGVAR(size));
if (isNumber (_config)) exitWith { if (isNumber (_config)) exitWith {
_item getVariable [QGVAR(size), getNumber (_config)] _item getVariable [QGVAR(size), getNumber (_config)]

View File

@ -25,20 +25,8 @@ _initializedClasses = GETMVAR(GVAR(initializedClasses),[]);
if (isServer) then { if (isServer) then {
{ {
if (isClass _x) then { if (isClass _x) then {
private ["_className", "_amount","_position","_object"]; [getText (_x >> "type"), _vehicle, getNumber (_x >> "amount")] call FUNC(addItem);
_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;
};
};
}; };
nil
} count ("true" configClasses (configFile >> "CfgVehicles" >> _type >> "ACE_Cargo" >> "Cargo")); } count ("true" configClasses (configFile >> "CfgVehicles" >> _type >> "ACE_Cargo" >> "Cargo"));
}; };