Jump to content
Sign in to follow this  
tonic-_-

[ALPHA] ARMA 3 Crate Filler

Recommended Posts

ARMA 3 Crate Filler



Version 0.2

by Tonic aka TAW_Tonic

Code:

/*
@file Version: v0.2
@file name: fillCrate.sqf
@file Author: TAW_Tonic
@file edit: 3/8/2013
@file Description: Automatically fill ammo box with everything in the game depending on paramenters
@params: [box,type,bool (optional),seconds(optional default: 5min)] execVM "fillCrate.sqf
@examples:
nul = [this,0,true] execVM "fillCrate.sqf"; //Fill ammo crate with everything - resupply enabled
nul = [this,1,true] execVM "fillCrate.sqf"; //Fill ammo crate with weapons & magazines - resupply enabled
nul = [this,2] execVM "fillCrate.sqf"; //Fill ammo crate with items - resupply disabled
nul = [this,3,true,(60 * 2)] execVM "fillCrate.sqf"; //Fill ammo crate with backpacks - resupply enabled - resupply every 2 minutes
*/
private["_box","_type","_boxn","_bType","_bType","_bPos","_boxn","_cfgweapons","_weapons","_magazines","_cur_wep","_classname","_wep_type","_scope","_picture","_items","_backpacks"];
_box = _this select 0;
_type = _this select 1;
_resupply = if(count _this > 2) then {_this select 2;} else {false;};
_resupply_time = if(count _this > 3) then {_this select 3;} else {60 * 5};

_bType = typeOf _box;
_bPos = getPos _box;

//Hide the global ammo box & create a local one *temp fix for locality issues).
if(!local _box) then
{
_box hideObject true;
_boxn = _bType createVehicleLocal [0,0,0];
_boxn setPosATL [_bPos select 0,_bPos select 1,0];

}
else
{
_boxn = _box;
};

clearWeaponCargo _boxn;
clearMagazineCargo _boxn;
clearItemCargo _boxn;
clearBackpackCargo _boxn;

switch (_type) do
{
//Master ammo crate (EVERYTHING).
case 0:
{	
	_cfgweapons = configFile >> "CfgWeapons";
	_weapons = [];

	for "_i" from 0 to (count _cfgWeapons)-1 do
	{
		_cur_wep = _cfgweapons select _i;

		if(isClass _cur_wep) then
		{
			_classname = configName _cur_wep;
			_wep_type = getNumber(_cur_wep >> "type");
			_scope = getNumber(_cur_wep >> "scope");
			_picture = getText(_cur_wep >> "picture");
			if(_scope >= 2 && _wep_type in [1,2,4,4096] && _picture != "" && !(_classname in _weapons) && _classname != "NVGoggles") then
			{
				//diag_log format["Class: %1 - Type: %2 - Scope: %3 - Pic: %4 - WEP: %5",_classname,_wep_type,_scope,_picture,_cur_wep];
				_weapons set[count _weapons, _classname];
			};
		};
	};

	_cfgweapons = configFile >> "CfgMagazines";
	_magazines = [];

	for "_i" from 0 to (count _cfgWeapons)-1 do
	{
		_cur_wep = _cfgweapons select _i;

		if(isClass _cur_wep) then
		{
			_classname = configName _cur_wep;
			//_wep_type = getNumber(_cur_wep >> "type");
			_scope = getNumber(_cur_wep >> "scope");
			_picture = getText(_cur_wep >> "picture");
			if(_scope >= 2 && _picture != "" && !(_classname in _magazines)) then
			{
				_magazines set[count _magazines, _classname];
			};
		};
	};

	{ _boxn addWeaponCargo [_x,50]; } foreach _weapons;
	{ _boxn addMagazineCargo [_x,50]; }foreach _magazines;

	_cfgweapons = configFile >> "CfgWeapons";
	_items = [];

	for "_i" from 0 to (count _cfgWeapons)-1 do
	{
		_cur_wep = _cfgweapons select _i;

		if(isClass _cur_wep) then
		{
			_classname = configName _cur_wep;
			_wep_type = getNumber(_cur_wep >> "type");
			_scope = getNumber(_cur_wep >> "scope");
			_picture = getText(_cur_wep >> "picture");
			//diag_log format["Class: %1 - Type: %2 - Scope: %3 - Pic: %4 - WEP: %5",_classname,_wep_type,_scope,_picture,_cur_wep];
			if(_scope >= 2 && _wep_type in [131072,4096] && _picture != "" && !(_classname in _items) && _classname != "Binocular") then
			{
				//diag_log format["Class: %1 - Type: %2 - Scope: %3 - Pic: %4 - WEP: %5",_classname,_wep_type,_scope,_picture,_cur_wep];
				_items set[count _items, _classname];
			};
		};
	};

	{ _boxn addItemCargo [_x,50]; } foreach _items;

		_cfgweapons = configFile >> "CfgVehicles";
	_backpacks = [];

	for "_i" from 0 to (count _cfgWeapons)-1 do
	{
		_cur_wep = _cfgweapons select _i;

		if(isClass _cur_wep) then
		{
			_classname = configName _cur_wep;
			_wep_type = getText(_cur_wep >> "vehicleClass");
			_scope = getNumber(_cur_wep >> "scope");
			_picture = getText(_cur_wep >> "picture");
			if(_scope >= 2 && _wep_type == "Backpacks" && _picture != "" && !(_classname in _backpacks)) then
			{
				//diag_log format["Class: %1 - Type: %2 - Scope: %3 - Pic: %4 - WEP: %5",_classname,_wep_type,_scope,_picture,_cur_wep];
				_backpacks set[count _backpacks, _classname];
			};
		};
	};

	{ _boxn addBackPackCargo [_x,5]; } foreach _backpacks;
};
//Fill box with Guns & Ammo only
case 1:
{
	_cfgweapons = configFile >> "CfgWeapons";
	_weapons = [];

	for "_i" from 0 to (count _cfgWeapons)-1 do
	{
		_cur_wep = _cfgweapons select _i;

		if(isClass _cur_wep) then
		{
			_classname = configName _cur_wep;
			_wep_type = getNumber(_cur_wep >> "type");
			_scope = getNumber(_cur_wep >> "scope");
			_picture = getText(_cur_wep >> "picture");
			if(_scope >= 2 && _wep_type in [1,2,4,4096] && _picture != "" && !(_classname in _weapons) && _classname != "NVGoggles") then
			{
				//diag_log format["Class: %1 - Type: %2 - Scope: %3 - Pic: %4 - WEP: %5",_classname,_wep_type,_scope,_picture,_cur_wep];
				_weapons set[count _weapons, _classname];
			};
		};
	};

	_cfgweapons = configFile >> "CfgMagazines";
	_magazines = [];

	for "_i" from 0 to (count _cfgWeapons)-1 do
	{
		_cur_wep = _cfgweapons select _i;

		if(isClass _cur_wep) then
		{
			_classname = configName _cur_wep;
			//_wep_type = getNumber(_cur_wep >> "type");
			_scope = getNumber(_cur_wep >> "scope");
			_picture = getText(_cur_wep >> "picture");
			if(_scope >= 2 && _picture != "" && !(_classname in _magazines)) then
			{
				_magazines set[count _magazines, _classname];
			};
		};
	};

	{ _boxn addWeaponCargo [_x,50]; } foreach _weapons;
	{ _boxn addMagazineCargo [_x,50]; }foreach _magazines;
};

//Items only
case 2:
{	
	_cfgweapons = configFile >> "CfgWeapons";
	_items = [];

	for "_i" from 0 to (count _cfgWeapons)-1 do
	{
		_cur_wep = _cfgweapons select _i;

		if(isClass _cur_wep) then
		{
			_classname = configName _cur_wep;
			_wep_type = getNumber(_cur_wep >> "type");
			_scope = getNumber(_cur_wep >> "scope");
			_picture = getText(_cur_wep >> "picture");
			//diag_log format["Class: %1 - Type: %2 - Scope: %3 - Pic: %4 - WEP: %5",_classname,_wep_type,_scope,_picture,_cur_wep];
			if(_scope >= 2 && _wep_type in [131072,4096] && _picture != "" && !(_classname in _items) && _classname != "Binocular") then
			{
				//diag_log format["Class: %1 - Type: %2 - Scope: %3 - Pic: %4 - WEP: %5",_classname,_wep_type,_scope,_picture,_cur_wep];
				_items set[count _items, _classname];
			};
		};
	};

	{ _boxn addItemCargo [_x,50]; } foreach _items;
};

case 3:
{

	_cfgweapons = configFile >> "CfgVehicles";
	_backpacks = [];

	for "_i" from 0 to (count _cfgWeapons)-1 do
	{
		_cur_wep = _cfgweapons select _i;

		if(isClass _cur_wep) then
		{
			_classname = configName _cur_wep;
			_wep_type = getText(_cur_wep >> "vehicleClass");
			_scope = getNumber(_cur_wep >> "scope");
			_picture = getText(_cur_wep >> "picture");
			if(_scope >= 2 && _wep_type == "Backpacks" && _picture != "" && !(_classname in _backpacks)) then
			{
				//diag_log format["Class: %1 - Type: %2 - Scope: %3 - Pic: %4 - WEP: %5",_classname,_wep_type,_scope,_picture,_cur_wep];
				_backpacks set[count _backpacks, _classname];
			};
		};
	};

	{ _boxn addBackPackCargo [_x,5]; } foreach _backpacks;
};
};

if(_resupply) then
{
sleep _resupply_time;
[_boxn,_type,_resupply,_resupply_time] execVM "fillCrate.sqf";
};

Parameters:

[box,type (number),bool,seconds] execVM "fillCrate.sqf";

Examples:

nul = [this,0,true] execVM "fillCrate.sqf"; //Fill ammo crate with everything - resupply enabled
nul = [this,1,true] execVM "fillCrate.sqf"; //Fill ammo crate with weapons & magazines - resupply enabled
nul = [this,2] execVM "fillCrate.sqf"; //Fill ammo crate with items - resupply disabled
nul = [this,3,true,(60 * 2)] execVM "fillCrate.sqf"; //Fill ammo crate with backpacks - resupply enabled - resupply every 2 minutes

Changelog:

Changed: Ammo box is now becomes local to the client to avoid locality issues within the end (temp fix).

Added: Backpacks

Added: All magazine types

Added: Various parameter options to make super crates, weapon/ammo crates,item crates and backpack only crates.

Added: Resupply Option with optional time adjustment (in seconds).

Fixed: Cleaned up code to remove bad config entries returning No Entry for certain items/guns.

Thanks/Credits:

unknownx9 - For Backpack code

Download:

ARMA 3 Crate Filler v0.2

Armaholic.com - [ALPHA] ARMA 3 Crate Filler v0.1

Edited by Tonic-_-

Share this post


Link to post
Share on other sites

I believe the extra weapon 'models' are just config entries - as there's a lot of combinations that aren't listed in the config yet you can create on your own with the attachments

Share this post


Link to post
Share on other sites
I believe the extra weapon 'models' are just config entries - as there's a lot of combinations that aren't listed in the config yet you can create on your own with the attachments

Probably, none the less this is built for future updates so if people absolutely get annoyed at having super crates with like 346346 guns I'll be splitting it up soon >.>

Share this post


Link to post
Share on other sites

Thanks for this! It beats having to go through and a line for each classname...

Will this work for the cargo of a vehicle as well?

Share this post


Link to post
Share on other sites
Thanks for this! It beats having to go through and a line for each classname...

Will this work for the cargo of a vehicle as well?

Should work for anything that uses the commands addWeaponCargoGlobal etc. Although I think most of the items will be pushed out of the vehicles gear... Ammo crates don't have a gear limit but vehicles do.

Share this post


Link to post
Share on other sites

I seen some error pop up about cows optic:

Warning Message: No entry 'bin\config.bin/CfgWeapons.optic_COWS'.

Share this post


Link to post
Share on other sites
I seen some error pop up about cows optic:

Warning Message: No entry 'bin\config.bin/CfgWeapons.optic_COWS'.

It pops up every now an then, will look into what causes it.

Share this post


Link to post
Share on other sites

	
clearWeaponCargoGlobal _box;
clearMagazineCargoGlobal _box;
clearItemCargoGlobal _box;
clearBackpackCargoGlobal _box;

//Backpacks are located in cfgvehicles
_CfgPacks = configFile >> "cfgVehicles";

for "_i" from 0 to (count _CfgPacks)-1 do
{
_pack = _CfgPacks select _i;

if(isClass _pack) then
{
	_packName = configName _pack;
	_veh_class = getText(_pack >> "vehicleClass");//Rather than using the type which is shared by other vehicles, I used the class type which was unique.
	if(_veh_class == "Backpacks")then
	{
		_box addBackpackCargoGlobal[_packName,_amount];//It will only add 1 pack for some reason.
	};
};
};

This script is based of your script/logic.

This will pull all the backpacks from the cfgvehicles. The packs with no pictures, do not work.

Edited by unknownx9

Share this post


Link to post
Share on other sites

To get unknowns script to work you need:

_box = _this select 0;
_amount = 1;

at the top of it.

The packs with no pictures are the tripod and mortar backpacks - don't seem complete but you can still equip with them and assemble a mortar.

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites
To get unknowns script to work you need:

_box = _this select 0;
_amount = 1;

at the top of it.

Here is the full code I am using:

_box = _this select 0;
_resupplyTime = 800;
_amount = 30;
while{true}do
{
clearWeaponCargoGlobal _box;
clearMagazineCargoGlobal _box;
clearItemCargoGlobal _box;
clearBackpackCargoGlobal _box;

_CfgPacks = configFile >> "cfgVehicles";

for "_i" from 0 to (count _CfgPacks)-1 do
{
	_pack = _CfgPacks select _i;

	if(isClass _pack) then
	{
		_packName = configName _pack;
		_veh_class = getText(_pack >> "vehicleClass");
		if(_veh_class == "Backpacks")then
		{
			_box addBackpackCargoGlobal[_packName,_amount];
		};
	};
};
sleep _resupplyTime;
};

In the initialization:

theBackPackBox = [this] execVM "Scripts\backpacks.sqf";

The box that I am using is, not sure if it matters:

[blue] Supply Box

Share this post


Link to post
Share on other sites

Your script appears to lack 40mm grenades of every variant.

Otherwise, great work!

Share this post


Link to post
Share on other sites
I have an extremely stupid question. Where do I put the sqf file? :o

If using the init statment such as 'theBackPackBox = [this] execVM "Scripts\backpacks.sqf"; '

Then the backpacks.sqf has to go in a 'Scripts' folder in the mission folder.

The mission folder itself will be named whatever you have called the mission when you saved it in the editor; this folder will be a sub folder of 'C:\Users\Blah\Documents\Arma 3 Alpha\missions' or 'C:\Users\Blah\Documents\Arma 3 Alpha - Other Profiles\otherprofilename\missions' depending whether you have set up a different profile in Arma 3 or not.

Share this post


Link to post
Share on other sites

Hi guys,

I've tried adding this to a crate i spawn ingame, and ive got a problem. The crate gets filled with clothing, hats, attachments etc, but no guns and no ammo whatsoever. Anyone had this problem?

Share this post


Link to post
Share on other sites

Thanks Tonic,

It works as described execVM in init of the ammo create .. sqf in my mission root folder.. and I have a loaded crate..

However, I also get the COWS error..

Thanks Tonic and Celery!!

Share this post


Link to post
Share on other sites

I just tested this in my mission and my clanmates reported that the create filler script works only for host. They can't use any item from the create (vest's ect...) only the host can. Didn't test it on dedicated server.

/*
@file Version: v0.1
@file name: fillCrate.sqf
@file Author: TAW_Tonic
@file edit: 3/5/2013
@file Description: Automatically fill ammo box with everything in the game.
@usage: put in a ammoboxes init field: nul = [this] execVM "fillCrate.sqf";
*/

if(!isServer) exitWith {};
private["_box","_CfgWeapons","_weapons","_items","_wep","_wep_type","_mags","_misc","_mag"];
_box = _this select 0;

clearWeaponCargoGlobal _box;
clearMagazineCargoGlobal _box;
clearItemCargoGlobal _box;
clearBackpackCargoGlobal _box;

_CfgWeapons = configFile >> "cfgWeapons";
_weapons = [];
_items = [];
_misc = [];

for "_i" from 0 to (count _Cfgweapons)-1 do
{
_weapon = _CfgWeapons select _i;

if(isClass _weapon) then
{
	_wep = configName _weapon;
	_wep_type = getNumber(_weapon >> "type");
	_scope = getNumber(_weapon >> "scope");

	if(_scope == 2 && _wep_type != 65536) then
	{
	if(_wep_type in [1,2,4,5,4096] && _wep != "NVGoggles") then
	{
		_weapons set[count _weapons,_wep];
	}
		else
	{
		_items set[count _items,_wep];
	};
	};
};
};

//Build Throw/Put magazine array
{_misc=_misc+getArray (configFile/"CfgWeapons"/"Throw"/_x/"magazines")} forEach getArray (configFile/"CfgWeapons"/"Throw"/"muzzles");  
{_misc=_misc+getArray (configFile/"CfgWeapons"/"Put"/_x/"magazines")} forEach getArray (configFile/"CfgWeapons"/"Put"/"muzzles");

{
_box addMagazineCargoGlobal [_x,100];
} foreach _misc;

//Add weapons & Mags
{
_box addWeaponCargoGlobal [_x,100];
diag_log format["Weapon %1 added", _x];

_mags = getArray(configFile >> "CfgWeapons" >> _x >> "magazines");

if(count _mags > 0) then
{
	{
		if(!(_x in ((getMagazineCargo _box) select 0))) then
		{
			_box addMagazineCargoGlobal [_x,100];
			diag_log format["Magazine %1 added", _x];
		};
	} foreach _mags;
};
} foreach _weapons;

//Add Items
{
_box addItemCargoGlobal [_x,100];
} foreach _items;

Share this post


Link to post
Share on other sites
If using the init statment such as 'theBackPackBox = [this] execVM "Scripts\backpacks.sqf"; '

Then the backpacks.sqf has to go in a 'Scripts' folder in the mission folder.

The mission folder itself will be named whatever you have called the mission when you saved it in the editor; this folder will be a sub folder of 'C:\Users\Blah\Documents\Arma 3 Alpha\missions' or 'C:\Users\Blah\Documents\Arma 3 Alpha - Other Profiles\otherprofilename\missions' depending whether you have set up a different profile in Arma 3 or not.

I can't seem to get this working, I've placed the fillCrate.sqf in C:\Users\name\Documents\Arma 3 Alpha - Other Profiles\profilename\missions\missionname\Scripts

No luck.

Share this post


Link to post
Share on other sites
I can't seem to get this working, I've placed the fillCrate.sqf in C:\Users\name\Documents\Arma 3 Alpha - Other Profiles\profilename\missions\missionname\Scripts

No luck.

Same here. :/

Share this post


Link to post
Share on other sites

I encountered some problems today with Scripts that were in a Scripts folder, once I had saved the mission for mp purposes and the Editor created the .pbo

Not sure if I was doing something wrong :(

Putting scripts in a Scripts folder is a nice way to organise things however you can put them in the root mission folder.

That worked for me with backpacks.sqf, I just changed the init statement to 'theBackPackBox = [this] execVM "backpacks.sqf";' and saved the script into the missionname folder and then saved it as a mp mission.

Out of interest has anyone one, who knows what they are doing:D, had problems with the built in save as mp mission option when using a sub folder for the scripts?

Share this post


Link to post
Share on other sites
I just tested this in my mission and my clanmates reported that the create filler script works only for host. They can't use any item from the create (vest's ect...) only the host can. Didn't test it on dedicated server.

/*
@file Version: v0.1
@file name: fillCrate.sqf
@file Author: TAW_Tonic
@file edit: 3/5/2013
@file Description: Automatically fill ammo box with everything in the game.
@usage: put in a ammoboxes init field: nul = [this] execVM "fillCrate.sqf";
*/

if(!isServer) exitWith {};
private["_box","_CfgWeapons","_weapons","_items","_wep","_wep_type","_mags","_misc","_mag"];
_box = _this select 0;

clearWeaponCargoGlobal _box;
clearMagazineCargoGlobal _box;
clearItemCargoGlobal _box;
clearBackpackCargoGlobal _box;

_CfgWeapons = configFile >> "cfgWeapons";
_weapons = [];
_items = [];
_misc = [];

for "_i" from 0 to (count _Cfgweapons)-1 do
{
_weapon = _CfgWeapons select _i;

if(isClass _weapon) then
{
	_wep = configName _weapon;
	_wep_type = getNumber(_weapon >> "type");
	_scope = getNumber(_weapon >> "scope");

	if(_scope == 2 && _wep_type != 65536) then
	{
	if(_wep_type in [1,2,4,5,4096] && _wep != "NVGoggles") then
	{
		_weapons set[count _weapons,_wep];
	}
		else
	{
		_items set[count _items,_wep];
	};
	};
};
};

//Build Throw/Put magazine array
{_misc=_misc+getArray (configFile/"CfgWeapons"/"Throw"/_x/"magazines")} forEach getArray (configFile/"CfgWeapons"/"Throw"/"muzzles");  
{_misc=_misc+getArray (configFile/"CfgWeapons"/"Put"/_x/"magazines")} forEach getArray (configFile/"CfgWeapons"/"Put"/"muzzles");

{
_box addMagazineCargoGlobal [_x,100];
} foreach _misc;

//Add weapons & Mags
{
_box addWeaponCargoGlobal [_x,100];
diag_log format["Weapon %1 added", _x];

_mags = getArray(configFile >> "CfgWeapons" >> _x >> "magazines");

if(count _mags > 0) then
{
	{
		if(!(_x in ((getMagazineCargo _box) select 0))) then
		{
			_box addMagazineCargoGlobal [_x,100];
			diag_log format["Magazine %1 added", _x];
		};
	} foreach _mags;
};
} foreach _weapons;

//Add Items
{
_box addItemCargoGlobal [_x,100];
} foreach _items;

Could this be the problem?

if(!isServer) exitWith {};

If you are not the server, the script exits. Try commenting out this line so that the server and client will both run this script.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×