Jump to content
Sign in to follow this  
Spunned

ammo box refill script - foreach loop or something?

Recommended Posts

hiya

i've been searching high and low for a script that would take whatever is in the ammobox (in my case just the default layout) and simply add the items back in 60 times, so that the ammobox contains more than just 1 instance of a rifle.

anyone know how to accomplish this? maybe through a loop or something?

Thanks for the help :)

Share this post


Link to post
Share on other sites

While you were typing the title of this thread you'd have seen a bunch of other, identical, threads about ammo box refill. Did you check any of them?

If you just want 60 rifles in a box put this in it's init field:

this addWeaponCargoGlobal ["MyRifleClassName", 60];

Share this post


Link to post
Share on other sites
While you were typing the title of this thread you'd have seen a bunch of other, identical, threads about ammo box refill. Did you check any of them?

If you just want 60 rifles in a box put this in it's init field:

this addWeaponCargoGlobal ["MyRifleClassName", 60];

i did indeed.

instead of having to go through each and every weapon class name, i was asking for a loop that would read whatever is already in the crate from the beginning and simply add more of said items.

Share this post


Link to post
Share on other sites

I've used an ammorefiller script and it totally messed up my mission. every 2-5 minutes the server had complete ( 100000 ) desyncs... now im using the VAS script and it works fine.

Just my 2 cents..

Share this post


Link to post
Share on other sites
I've used an ammorefiller script and it totally messed up my mission. every 2-5 minutes the server had complete ( 100000 ) desyncs... now im using the VAS script and it works fine.

Just my 2 cents..

thanks for your input.

ive used VAS as well, however i'd prefer to simply have a refiller script with the features i was talking about. unless no one's made something like that, in which case i'd "settle" with VAS. (im not trash talking VAS, it's amazing but not what im looking for)

Share this post


Link to post
Share on other sites

You can add 60 of each existing item via this:

{box addMagazineCargoGlobal [(_x select 0), 60]} forEach ((magazineCargo box) call BIS_fnc_consolidateArray);

Repeat for Weapons and Items.

Share this post


Link to post
Share on other sites
You can add 60 of each existing item via this:

{box addMagazineCargoGlobal [(_x select 0), 60]} forEach ((magazineCargo box) call BIS_fnc_consolidateArray);

Repeat for Weapons and Items.

thanks for your help :)

unfortunately i cant get it to work. im not sure if im using it correct though. the code goes in the init field of the box, right? if so, i cant get it to work.

Share this post


Link to post
Share on other sites

try this as your init in the ammo box:

{this addMagazineCargoGlobal [(_x select 0), 60]} forEach ((magazineCargo this) call BIS_fnc_consolidateArray);  {this addWeaponCargoGlobal [(_x select 0), 60]} forEach ((WeaponCargo this) call BIS_fnc_consolidateArray); {this addItemCargoGlobal [(_x select 0), 60]} forEach ((ItemCargo this) call BIS_fnc_consolidateArray);

The first example was using an ammobox named box. This one is ready for init field.

Share this post


Link to post
Share on other sites
try this as your init in the ammo box:

{this addMagazineCargoGlobal [(_x select 0), 60]} forEach ((magazineCargo this) call BIS_fnc_consolidateArray);  {this addWeaponCargoGlobal [(_x select 0), 60]} forEach ((WeaponCargo this) call BIS_fnc_consolidateArray); {this addItemCargoGlobal [(_x select 0), 60]} forEach ((ItemCargo this) call BIS_fnc_consolidateArray);

The first example was using an ammobox named box. This one is ready for init field.

i went back and tried the first one again with the name box, that didnt work. the box is completely empty when spawned and unfortunately the same thing happens when i try the new method as well.

Share this post


Link to post
Share on other sites

Ok well if it's empty that's your problem. :) All that code does is say "What's in the box? Give me 60 more of each type of item/mag/weap already in the box please". So if you have nothing, nothing + 60 is still nothing.

If you only wanted specific items in the box just clear it and add in 60 of each of what you wanted via the normal addMagazineCargoGlobal commands.

Share this post


Link to post
Share on other sites
Ok well if it's empty that's your problem. :) All that code does is say "What's in the box? Give me 60 more of each type of item/mag/weap already in the box please". So if you have nothing, nothing + 60 is still nothing.

If you only wanted specific items in the box just clear it and add in 60 of each of what you wanted via the normal addMagazineCargoGlobal commands.

hmm after a bit of testing ive figured some stuff out.

if i use the code (both old and new) on certain boxes, they're empty. if i do the same thing on other certain boxes (like nato standard wep and such) the box spawn with the default layout and nothing more.

im not sure if it's the code that's not working or if im doing something wrong

Share this post


Link to post
Share on other sites
i was asking for a loop that would read whatever is already in the crate from the beginning and simply add more of said items.

That's what the code does. What certain boxes is this not working with? I've tested this with every type of default ammo box and it worked for all of them (Vehicle ammo boxes are empty by default, so they remain empty).

---------- Post added at 11:52 AM ---------- Previous post was at 11:45 AM ----------

Oh, hey. It's not working since that function was just added 6 hours ago. :)

So yeah, switch to the Dev Branch and it'll work. or wait for the next beta patch, or hand code it all. :)

Share this post


Link to post
Share on other sites
That's what the code does. What certain boxes is this not working with? I've tested this with every type of default ammo box and it worked for all of them (Vehicle ammo boxes are empty by default, so they remain empty).

all the basic ammo and basic weapons crates. the three special weapons crates as well.

---------- Post added at 15:55 ---------- Previous post was at 15:53 ----------

ahh thank you ^^

im not using dev branch but ill switch to it and give it a go.

thanks for your help :)

Share this post


Link to post
Share on other sites

another solution is a while/do loop !!

put a weapon or ammobox on the map an put this in the init :

this allowdamage false;_handle = [this] execvm "weapons.sqf"

the weapons.sqf :

private ["_ammobox"];

_ammobox = _this select 0;

while {true} do
{
clearMagazineCargo _ammobox; 
clearWeaponCargo _ammobox;

_ammobox addWeaponCargo ["yourweapon",10];

_ammobox addMagazineCargo ["yourammo",50];

sleep 300;
};

:)

  • Like 1

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  

×