mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Added AddCargoItem event and function to add an item by classname
This commit is contained in:
parent
e110874800
commit
4c86db9505
@ -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);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
ADDON = false;
|
||||
|
||||
PREP(addCargoItem);
|
||||
PREP(canLoad);
|
||||
PREP(canLoadItemIn);
|
||||
PREP(canUnloadItem);
|
||||
|
33
addons/cargo/functions/fnc_addCargoItem.sqf
Normal file
33
addons/cargo/functions/fnc_addCargoItem.sqf
Normal 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;
|
||||
};
|
||||
};
|
@ -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)]
|
||||
|
@ -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"));
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user