It is currently Wed Jun 26, 2019 2:10 am

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Thu Sep 20, 2018 4:54 pm 

Joined: Wed Feb 15, 2012 2:03 pm
Posts: 1084
Location: Derby, United Kingdom
Hi all,

A quick script for creating objects when players drop a backpack. Useful if you want to simulate radio jammers, carrying ammoboxes, or any other object. Feel free to edit as per your requirements.

   File: createObjectFromBackpack.sqf
   Author: Hellfire257
   Version: 1.02

   Creates defined object when players drop a defined backpack from inventory.
   The created object can be picked up and returned to the player's backpack slot.
   Requires the use of the InventoryClosed event handler:

   _this select 0: _this array returned from event handler (do not change!)
   _this select 1: Required classname of backpack in order to trigger script (string)
   _this select 2: Classname of object to create when backpack dropped (string)

   Example Call(s):
   Requires Tropical Bergen, spawns a data terminal:
   this addEventHandler ["InventoryClosed", {null = [_this,"B_Bergen_tna_F","Land_DataTerminal_01_F"] execVM "createObjectFromBackpack.sqf"}];

   Requires Olive Carryall, spawns an ammo crate:
   this addEventHandler ["InventoryClosed", {null = [_this,"B_Carryall_oli","Box_NATO_Ammo_F"] execVM "createObjectFromBackpack.sqf"}];

   Best used within the initialisation field of a unit.

params ["_ehArray","_requiredBag","_objectToSpawn"];

_debug = true;
_unit = _ehArray select 0;
_container = _ehArray select 1;

if (isNull _container) exitWith {};

_nearestBag = nearestObjects [_unit, ["WeaponHolder"], 1] select 0;
if (isNil "_nearestBag") exitWith {if (_debug) then {systemChat "COFB - Aborting - No Backpack Nearby! (Stage 1)"}};
_droppedBag = getBackpackCargo _nearestBag select 0;
if (count _droppedBag == 0) exitWith {systemChat "COFB - Aborting - No Backpack Nearby! (Stage 2)"}; //May be redundant, better to keep in as a safeguard!
if (_debug) then {systemChat format ["COFB - Nearest bags are %1",_droppedBag]};

_droppedBagClass = _droppedBag select 0;
if (_droppedBagClass != _requiredBag) exitWith {if (_debug) then {systemChat format ["COFB - Aborting - Dropped bag %1 doesn't match %2",_droppedBagClass,_requiredBag]}};
if (_debug) then {systemChat format ["COFB - Dropped bag class is %1",_droppedBagClass]};

deleteVehicle _container;

_spawnPos = _unit modelToWorld [0,1.5,0];
_object = createVehicle [_objectToSpawn,_spawnPos,[],0, "CAN_COLLIDE"];
if (_debug) then {systemChat format ["COFB - Created %1 (%2)",_object,_objectToSpawn]};
_object setDir ([_unit, _object] call BIS_fnc_dirTo);

if (typeOf _object == "Land_DataTerminal_01_F") then {sleep 1; null = [_object,3] call BIS_fnc_dataTerminalAnimate};

_objectName = getText (configFile >> "CfgVehicles" >> _objectToSpawn >> "displayName");
_actionText = format ["Take %1",_objectName];
_object addAction [_actionText,{deleteVehicle (_this select 3 select 0); player addBackpack (_this select 3 select 1)},[_object,_requiredBag]];

Example mission attached.


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group