It is currently Thu Oct 18, 2018 11:33 am

All times are UTC

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

Joined: Wed Feb 15, 2012 2:03 pm
Posts: 1076
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.01

   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"];

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

if (isNull _container) exitWith {};

_droppedBag = (getBackpackCargo (nearestObjects [_unit, ["WeaponHolder"], 5] select 0) select 0);
if (count _droppedBag == 0) exitWith {};

_droppedBagClass = _droppedBag select 0;
if (_droppedBagClass != _requiredBag) exitWith {};

deleteVehicle _container;

_spawnPos = _unit modelToWorld [0,1.5,0];
_object = createVehicle [_objectToSpawn,_spawnPos,[],0, "CAN_COLLIDE"];
_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