Ammo box script work in progress

Credits-
krix for inital code
ghostphantom172 for work in progress

HELP IS APPRECIATED

first inside server_cleanup.fsm....

Code:
"{" \n
"    _keep = _x getVariable [""permaLoot"",false];" \n
"    _nearby = {isPlayer _x} count (_x nearEntities [[""CAManBase""], 250]);" \n
"" \n
and change it too.....
Code:
"{" \n
"    _keep = _x getVariable [""permaLoot"",false];" \n
"    _krixKeep = _x getVariable [""KrixKeep"",false];" \n
"    _nearby = {isPlayer _x} count (_x nearEntities [[""CAManBase""], 250]);" \n
"" \n
find this line....
Code:
"    if ( (!_keep) && (_nearby==0) && (_age > 60) ) then {" \n
change it too....
Code:
"    if ( (!_keep) && (_nearby==0) && (_age > 60) && (!_krixKeep) ) then {" \n


THE (ammobox.sqf) still not sure if it is working yet currently set to 3 boxes total

Code:
//Ammo box spawn script by ghostphantom172
//Currently working on 1.7.7.1
//---------------------The CODE---------------------
//Box Models
    _ammoBoxModel = ["GuerillaCacheBox","USBasicAmmunitionBox"] call BIS_fnc_selectRandom;
 
//-------Box 1 Information--------
//Box attributes
    //box attributes
    _boxPos1 = [8108,9149,0]; //Change postion of ammo box one
 
//Ammo Box spawning
    //Spawning the box
    _ammoBox = createVehicle [_ammoBoxModel, _boxPos1, [], 0, "CAN_COLLIDE"];
    _ammoBox setDir 0.0;
    _ammoBox setPos _boxPos1;
   
//-------Box 2 information--------
//Box attributes
    //box attributes
    _boxPos2 = [5380,5581,0]; //Change postion of ammo box two
 
//Ammo box spawning
    //Spawning the box
    _ammoBox = createVehicle [_ammoBoxModel, _boxPos2, [], 0, "CAN_COLLIDE"];
    _ammoBox setDir 0.0;
    _ammoBox setPos _boxPos2;
   
//-------Box 3 information--------
//Box attributes
    //box attributes
    _boxPos3 = [8112,9149,0]; //Change postion of ammo box three
 
//Ammo box spawning
    //Spawning the box
    _ammoBox = createVehicle [_ammoBoxModel, _boxPos3, [], 0, "CAN_COLLIDE"];
    _ammoBox setDir 0.0;
    _ammoBox setPos _boxPos3;
   
//----------Box Contents---------
//Box contents
 
//Box contents
    if (_ammoBoxModel == "GuerillaCacheBox") then
{
    //clear items
    clearMagazineCargoGlobal _ammoBox;
    clearWeaponCargoGlobal _ammoBox;
    //add items
    _ammoBox addWeaponCargoGlobal ["M16A2", 1]; // for the weapons
    _ammoBox addMagazineCargoGlobal ["30Rnd_556x45_Stanag", 2]; // for the ammo
    _ammoBox addMagazineCargoGlobal ["ItemAntibiotic", 2]; // for the items;}
    else
{
    //clear items
    clearMagazineCargoGlobal _ammoBox;
    clearWeaponCargoGlobal _ammoBox;
    //add items
    _ammoBox addWeaponCargoGlobal ["M16A2", 2]; // for the weapons
    _ammoBox addMagazineCargoGlobal ["30Rnd_556x45_Stanag", 6]; // for the ammo
    _ammoBox addMagazineCargoGlobal ["ItemAntibiotic", 2]; // for the items;};
 
//-------Set Variables------------
//set variables
    _ammoBox setVariable ["KrixKeep",true,true];

as i said before i need a bit of help i want it to spawn the boxes but the model and content to be random!
 
All right after whole night of testing i made it this far and im still having a few bugs!
Install
Step 1-


Also exe in the init.sqf
Under is dedicated

Code:
    //Spawn ammo boxes
    [] execVM "scripts\ammobox.sqf";

step 2-
open up server_cleanup.sfm

find this
Code:
"{" \n
"    _keep = _x getVariable [""permaLoot"",false];" \n
"    _nearby = {isPlayer _x} count (_x nearEntities [[""CAManBase""], 250]);" \n
"" \n

and change it too.....
Code:
"{" \n
"    _keep = _x getVariable [""permaLoot"",false];" \n
"    _krixKeep = _x getVariable [""KrixKeep"",false];" \n
"    _nearby = {isPlayer _x} count (_x nearEntities [[""CAManBase""], 250]);" \n
"" \n

find this line....
Code:
"    if ( (!_keep) && (_nearby==0) && (_age > 60) ) then {" \n

change it too....
Code:
"    if ( (!_keep) && (_nearby==0) && (_age > 60) && (!_krixKeep) ) then {" \n

step 3-
Make the sqf called ammbox.sqf
and paste the following code in it!

BUGS:
1. Can't spawn more then one box
2. Both boxes spawn at one location
3. with more boxes loot will not clear and set
4. The boxes will have wrong loot set

MY CODE:


thanks to some help from kirx

Code:
//Ammo box spawn script by ghostphantom172
//Currently working on 1.7.7.1
//---------------------The CODE---------------------
//Box Models
    _ammoBoxModel = ["USBasicAmmunitionBox", "GuerillaCacheBox"] call BIS_fnc_selectRandom;
 
//box position
    _boxPos1 = [8110,9149,0]; //Change postion of ammo box
    //_boxPos2 = [5380,5581,0];
    //_boxPos3 = [6882,11448,0];
 
//-------Box spawn in--------
//Spawn Boxes
 
    //Spawning Box 1
    _BoxModel = _ammoBoxModel;
    _ammoBox1 = createVehicle [_BoxModel, _boxPos1, [], 0, "CAN_COLLIDE"];
    _ammoBox1 setDir 0.0;
    _ammoBox1 setPos _boxPos1;
 
//---------Box Contents------------
//Clear contents
    clearMagazineCargoGlobal _ammoBox1;
    clearWeaponCargoGlobal _ammoBox1;
//Add contents
if(_ammoBoxModel == "USBasicAmmunitionBox") then  {
    {_ammoBox1 addWeaponCargoGlobal [_x, 1];} forEach
        ['M16A2'];
    {_ammoBox1 addMagazineCargoGlobal [_x, 2];} forEach
        ['30Rnd_556x45_Stanag'];
    {_ammoBox1 addBackpackCargoGlobal [_x, 1];} forEach
        ['DZ_Assault_Pack_EP1'];
    };
if(_ammoBoxModel == "GuerillaCacheBox") then  {
    {_ammoBox1 addWeaponCargoGlobal [_x, 1];} forEach
        ['DMR','Binocular_Vector','NVGoggles'];
    {_ammoBox1 addMagazineCargoGlobal [_x, 2];} forEach
        ['20Rnd_762x51_DMR'];
    {_ammoBox1 addBackpackCargoGlobal [_x, 1];} forEach
        ['DZ_Backpack_EP1'];
    };
 
//-------Set Variable------------
//set variable
    _ammobox1 setVariable ["KrixKeep",true,true];

step 4-
add the boxes to your creatvehicle.txt in battleeye should be line #2

Code:
5 "box" !="MedBox0" !="AmmoBoxSmall_556" !="AmmoBoxSmall_762" !="ItemMatchbox" !="ItemToolbox" !="CardBoardBox" !="FoodBox1" !="FoodBox2" !="FoodBox3" !="USBasicAmmunitionBox" !="GuerillaCacheBox"

step 5-
add the boxes to safe objects in variables

and it should be set up for testing
PLEASE I NEED SOME HELP I LAID THE GROUND WORK I JUST NEED SOME HELP!
 
I managed to spawn in the boxes from the database but is there is a problem. When they contain alot of stuff they don't spawn. Is there anyway to lock the amount of space or check what the limit is?
 
No they can fit way more loot then tents. Because my boxes with way more stuff then tents still spawn.
 
if you put to much they will despawn the tents can hold 10 guns and such the boxes don't show the loot limit but when going through database the box acts like a tent because it defaults to it considering there is no script for content limit on the boxes through database originaly
 
It wasn't that the boxes can hold ALOT. My anti-hack was removing them. I currently have around 10 boxes on my server and atleast 50% of them have 40 guns and shit loads of other junk :p.
 
So what I am wonder, since your just adding another variable for the code to check

couldn't you just take

Code:
_vehicle_456 = objNull;
if (true) then
{
  _this = createVehicle ["USBasicAmmunitionBox", [10372.535, 2239.1392, 0.034007989], [], 0, "CAN_COLLIDE"];
  _vehicle_456 = _this;
  _this setDir 32.845772;
  _this setVehicleInit "null0 = this execVM ""cache.sqf""";
  _this setPos [10372.535, 2239.1392, 0.034007989];
};


and do this

Code:
_vehicle_456 = objNull;
if (true) then
{
  _this = createVehicle ["USBasicAmmunitionBox", [10372.535, 2239.1392, 0.034007989], [], 0, "CAN_COLLIDE"];
  _vehicle_456 = _this;
  _this setDir 32.845772;
  _this setVehicleInit "null0 = this execVM ""cache.sqf""";
  _this setPos [10372.535, 2239.1392, 0.034007989];
  _this setVariable ["KrixKeep",true,true];
};


EDIT:

Heck for that matter you should just be able to add

Code:
_vehicle_456 = objNull;
if (true) then
{
  _this = createVehicle ["USBasicAmmunitionBox", [10372.535, 2239.1392, 0.034007989], [], 0, "CAN_COLLIDE"];
  _vehicle_456 = _this;
  _this setDir 32.845772;
  _this setVehicleInit "null0 = this execVM ""cache.sqf""";
  _this setPos [10372.535, 2239.1392, 0.034007989];
  _this setVariable ["permaLoot",true,true];
};

Possibly, depending on what else that Variable is tied to...
 
its not for an admin menu box its for the server to manually spawn in a box at specific location, with specific loot. the loot resets after restart, AKA hidden treasure chest. also later on down the road i will compact the code and update it sorry if you though this was an admin box
 
So if I have my file that contains code similar to this
Code:
_vehicle_10 = objNull;
if (true) then
{
  _this = createVehicle ["vil_RUammoBoxBasic80s90s", [4656.8965, 13515.831, -0.00012207031], [], 0, "CAN_COLLIDE"];
  _vehicle_10 = _this;
  _this setDir -0.0741731;
  _this setPos [4656.8965, 13515.831, -0.00012207031];
Can I execute that in the init.sqf and using the Server_cleanup.fsm fix will it spawn the boxes or not?
 
Yeah Retra, but you "DO NOT" have to add any additional variables. The Variable is already there.

Code:
"    _keep = _x getVariable [""permaLoot"",false];" \n

Code:
"    if ( (!_keep) && (_nearby==0) && (_age > 60) ) then {" \n

All you really have to is add

Code:
_this setVariable ["permaLoot",true,true];

To your

Code:
_vehicle_10 = objNull;
if (true) then
{
  _this = createVehicle ["vil_RUammoBoxBasic80s90s", [4656.8965, 13515.831, -0.00012207031], [], 0, "CAN_COLLIDE"];
  _vehicle_10 = _this;
  _this setDir -0.0741731;
  _this setPos [4656.8965, 13515.831, -0.00012207031];

So it looks like

Code:
_vehicle_10 = objNull;
if (true) then
{
  _this = createVehicle ["vil_RUammoBoxBasic80s90s", [4656.8965, 13515.831, -0.00012207031], [], 0, "CAN_COLLIDE"];
  _vehicle_10 = _this;
  _this setDir -0.0741731;
  _this setPos [4656.8965, 13515.831, -0.00012207031];
  _this setVariable ["permaLoot",true,true];

I don't know why they added an additional variable. Tested all that out on my own server and works like a gem.
 
To further expand for you I'll give you my example

This is the code in my mission pbo to add in my gear box

Code:
_vehicle_20 = objNull;
if (true) then
{
  _this = createVehicle ["LocalBasicAmmunitionBox", [2932.281, 12821.079, -9.1552734e-005], [], 0, "CAN_COLLIDE"];
  _vehicle_20 = _this;
  _this setDir 13.635636;
  _this setVehicleInit "null0 = this execVM ""addons\camps\docgearbox.sqf""";
  _this setPos [2932.281, 12821.079, -9.1552734e-005];
  _this setVariable ["permaLoot",true,true];
};

Which you can also see executes another sqf called docgearbox.sqf with this

Code:
while {alive _this} do
{
 
 
clearweaponcargo _this;
clearmagazinecargo _this;
 
 
_this addWeaponCargo ["RH_p90sdeot",1];
_this addWeaponCargo ["R3F_Famas_F1_J4_M203_SD",1];
_this addWeaponCargo ["Binocular",1];
_this addWeaponCargo ["Binocular_Vector",1];
_this addWeaponCargo ["ItemGPS",1];
 
_this addmagazineCargo ["FoodMRE",30];
_this addmagazineCargo ["ItemSodaLemonade",30];
_this addmagazineCargo ["ItemAntibiotic",10];
_this addmagazineCargo ["ItemBloodbag",10];
_this addmagazineCargo ["ItemMorphine",10];
_this addmagazineCargo ["ItemBandage",10];
_this addmagazineCargo ["ItemPainkiller",10];
_this addmagazineCargo ["ItemHeatPack",10];
_this addmagazineCargo ["RH_57x28mm_50RND_SD_Mag",50];
_this addmagazineCargo ["30Rnd_556x45_StanagSD",50];
 
 
sleep 3600;
};

inside of it.

The

Code:
clearweaponcargo _this;
clearmagazinecargo _this;

Empties out anything "predefined" in the box you want to use

And the

Code:
_this addWeaponCargo ["",1];
_this addmagazineCargo ["",30];

Adds the content you wish to have put into your now empty box.

And this line

Code:
_this setVariable ["permaLoot",true,true];

Keeps this bit of code in the server_cleanup.fsm

Code:
init = /*%FSM<STATEINIT""">*/"//_missionObjs = allMissionObjects ""WeaponHolder"" + allMissionObjects ""WeaponHolderBase"" ;" \n
      "_missionObjs = allMissionObjects ""ReammoBox"";" \n
      "_qty = count _missionObjs;" \n
      "" \n
      "diag_log (""CLEANUP:TOTAL "" + str(_qty) + "" LOOT BAGS"");" \n
      "" \n
      "_delQty = 0;" \n
      "" \n
      "{" \n
      "    _keep = _x getVariable [""permaLoot"",false];" \n
      "    _nearby = {isPlayer _x} count (_x nearEntities [[""CAManBase""], 250]);" \n
      "" \n
      "    _created = (_x getVariable [""created"",-0.1]);" \n
      "" \n
      "    if (_created == -0.1) then {" \n
      "        _x setVariable [""created"",(DateToNumber date)];" \n
      "    };" \n
      "" \n
      "    _age = ((DateToNumber date) - _created) * 525948;" \n
      "" \n
      "//diag_log format [""Pile : %1, Created: %2, Age: %3"", _x,  _created, _age];" \n
      "" \n
      "    if ( (!_keep) && (_nearby==0) && (_age > 300) then {" \n
      "        deleteVehicle _x;" \n
      "        _delQty = _delQty + 1;" \n
      "    };" \n
      "" \n
      "} forEach _missionObjs;" \n

From deleting it....


Hope this helps....
 
Hey, 80% of what I know came from you gathering all those learning resources together. I'm just paying it forward. Thank you man.
 
Back
Top