ACE3/addons/vehiclelock/functions/fnc_addKeyForVehicle.sqf

41 lines
1.3 KiB
Plaintext
Raw Normal View History

2015-01-23 22:40:39 +00:00
/*
* Author: PabstMirror
* Adds a key to a unit that will open a vehicle
* Note: has global effects for Unit (will add items to remote unit)
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Vehicle <OBJECT>
* 2: custom key (true: custom key (magazine) - false: side key (item)) <BOOL>
*
* Return Value:
* None
*
* Example:
* [ACE_player, car, true] call ACE_VehicleLock_fnc_addKeyForVehicle
*
* Public: Yes
*/
2015-01-23 22:40:39 +00:00
#include "script_component.hpp"
private ["_previousMags","_newMags","_keyMagazine","_keyName"];
2015-01-23 22:40:39 +00:00
PARAMS_3(_unit,_veh,_useCustom);
2015-01-23 22:40:39 +00:00
if (isNull _unit) exitWith {ERROR("null unit");};
if (isNull _veh) exitWith {ERROR("null vehicle");};
2015-01-23 22:40:39 +00:00
if (_useCustom) then {
_previousMags = magazinesDetail _unit;
_unit addMagazine ["ACE_key_customKeyMagazine", 1]; //addMagazine array has global effects
_newMags = (magazinesDetail _unit) - _previousMags;
if ((count _newMags) == 0) exitWith {ERROR("failed to add magazine (inventory full?)");};
_keyMagazine = _newMags select 0;
TRACE_2("setting up key on server",_veh,_keyMagazine);
//Have the server run add the key to the vehicle's key array:
["VehicleLock_SetupCustomKey", [_veh, _keyMagazine]] call EFUNC(common,serverEvent);
2015-01-23 22:40:39 +00:00
} else {
_keyName = [_veh] call FUNC(getVehicleSideKey);
_unit addItem _keyName; //addItem has global effects
2015-01-23 22:40:39 +00:00
};