Jump to content
Sign in to follow this  
TurokGMT

Help with crate refill script

Recommended Posts

Hey guys, can anyone spot the problem here:

I've added a US vehicle ammo crate in editor with this in it's init line:

this allowdamage false; null = [this] execvm "guns.sqf";

contents of guns.sqf is:

// self filling weapons and ammo crate for USMC

private = ["_crate","_guns","_ammo"];

_crate = _this select 0;

_guns =

[

"M1014",

"M16A4",

"M16A4_ACG",

"M4A1_HWS_GL",

"M249",

"DMR",

"Javelin",

"SMAW",

"Binocular"

];

_ammo =

[

"8Rnd_B_Beneli_74Slug",

"30Rnd_556x45_Stanag",

"200Rnd_556x45_M249",

"20Rnd_762x51_DMR",

"Javelin",

"SMAW_HEAA"

"Handgrenade",

"Smokeshell"

];

clearmagazinecargo _crate;

clearweaponcargo _crate;

{_crate addweaponcargo [_x,10];} foreach _guns;

{_crate addmagazinecargo [_x,50];} foreach _ammo;

sleep 300;

[_crate] execvm "guns.sqf";

script seems to have no effect in editor on testing - little help anyone?

EDIT

Problem definitely seems to lie in the foreach commands - does anyone know if addweaponcargo can be used like this?

Edited by TurokGMT

Share this post


Link to post
Share on other sites

Do you need the ; within the { } of the forEach statements?

Share this post


Link to post
Share on other sites

yeah, tried that variant too.

can only get it to work by writing each addweaponcargo and each addmagazinecargo out in full.

Complete pain!

Share this post


Link to post
Share on other sites

_guns =
[
"M1014",
"M16A4",
"M16A4_ACG",
"M4A1_HWS_GL",
"M249",
"DMR",
"Javelin",
"SMAW",
"Binocular"
];

_ammo =
[
"8Rnd_B_Beneli_74Slug",
"30Rnd_556x45_Stanag",
"200Rnd_556x45_M249",
"20Rnd_762x51_DMR",
"Javelin",
"SMAW_HEAA"
"Handgrenade",
"Smokeshell"
];

Code tags next time please. Look at ammo, check your syntax.

...

If still not found it, look at SMAW_HEAA... :rolleyes:

Share this post


Link to post
Share on other sites

It's

private ["_crate","_guns","_ammo"];

and not

private = ["_crate","_guns","_ammo"];

Xeno

Share this post


Link to post
Share on other sites

thanks fellas - didn't spot the missing comma and really should have remembered how to structure private!

In my defense, I'm suffering from man-flu and only editing in notepad...

=]

Share this post


Link to post
Share on other sites
... null = [this] execvm "guns.sqf"; contents of guns.sqf is:

// self filling weapons and ammo crate for USMC

zipped..

I'm sure you've already figured out, that there's a comma missing. Still, there are other things/tips you might wanna hear:

  1. If you are sure that your script will take only one argument, you can do this:
    nul = this execVM "guns.sqf"
    


    In the script you then use `_this` instead of `_crate` which you won't need to define anymore. This can make a lot of simple scripts easier to read and use, especially if you pass one array. One array in your _this array just looks akward, hehe.

  2. You really don't have to define one single variable in your script. IMHO you should not, unless you have a reason to. You don't. You can write the following:
    {
      _this addWeaponCargo [(_x select 0), 10];
    } forEach [
      "M1014",
      "M16A4",
      ...
    ];
    


    You don't have to assign one single variable, and IMHO it reads a lot better because you don't have to track some obscure variables down.

Share this post


Link to post
Share on other sites

but if the variables are private to the script's locality, does it matter if they're defined - or am I meddling with the gods of unecessary CPU/MEM overhead here?

Share this post


Link to post
Share on other sites
but if the variables are private to the script's locality, does it matter if they're defined - or am I meddling with the gods of unecessary CPU/MEM overhead here?

No, of course not. And also I do not consider the declaration of a variable a thing or problem of any overhead (not these days, hehe). Actually it's the other way around and if you would reuse the above array/list of weapons, then you should definitely consider storing it in a variable, instead of declaring this array over and over again.

My point was only `sexy` coding practice. With what I suggested, the above script could be easily shortened. And that not in the bad way (premature optimisation). The script would be easier to call (without one item nested in an array, which is pointless), easier to read and yeah, we would save the declaration of some variables, but this was not my point. That's just a sideeffect.

Ok. If you're just interested to make your script work - at all - then this tips probably won't be interesting for you. And yeah, I'm probably in the wrong thread anyway... hehe

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  

×