Jump to content
Sign in to follow this  
Abrahamsen

Need some help trimming down a script.

Recommended Posts

I'm at a very basic level of scripting, I hope someone can help me trim down this little one and by doing so teach me some syntax and tricks.

officer1 removeWeapon	"AKS_74_U";
officer1 addWeapon	"AK_107_kobra";
officer1 addMagazine	["30Rnd_545x39_AK",10];

officer2 removeWeapon	"AKS_74_U";
officer2 addWeapon	"AK_107_kobra";
officer2 addMagazine	["30Rnd_545x39_AK",10];

officer3 removeWeapon	"AKS_74_U";
officer3 addWeapon	"AK_107_kobra";
officer3 addMagazine	["30Rnd_545x39_AK",10];

officer4 removeWeapon	"AKS_74_U";
officer4 addWeapon	"AK_107_kobra";
officer4 addMagazine	["30Rnd_545x39_AK",10];

It's very basic stuff.

oh, and hi, I'm new!

edit: hmm, now it's not even working. Only the first guy gets the weapon.

Edited by Abrahamsen

Share this post


Link to post
Share on other sites

for "_i" from 1 to 4 do {
for "_j" from 0 to 9 do {call compile format ["officer%1 addMagazine ""30Rnd_545x39_AK""",_i];};
call compile format ["officer%1 removeWeapon ""AKS_74_U"";officer%1 addWeapon ""AK_107_kobra""",_i];
};

Or just:

{
for "_i" from 0 to 9 do { _x addMagazine "30Rnd_545x39_AK"; };
_x removeWeapon "AKS_74_UN_kobra";
_x addWeapon "AK_107_kobra";
} foreach [officer1,officer2,officer3,officer4];

Share this post


Link to post
Share on other sites

Try this:

{
_unit = _x;
_unit removeWeapon "AKS_74_U";
_unit removeMagazines "30Rnd_545x39_AK"; //<- as to have the number he wants.. not 10 + default 3
{_unit addMagazine "30Rnd_545x39_AK";} forEach [1,2,3,4,5,6,7,8,9,10];
_unit addWeapon	"AK_107_kobra";
} forEach [officer1,officer2,officer3,officer4];

The reason it stopped was you have the wrong syntax for the addmag..

officer1 addMagazine ["30Rnd_545x39_AK",10];

the [magname,10] only works for addmagazinecargo (ammobox etc)

You have to add 1 magazine several times.

And add the mag before the weapon, so the unit doesn't have to reload at start.

Ahh.. good catch Oden...

Edited by Big_Daddy

Share this post


Link to post
Share on other sites

<officer1 addMagazine ["30Rnd_545x39_AK",10];> is mixing up command with addMagazineCargo, used for vehicles.

try:

officer1 removeWeapon "AK_74_U";
{ officer1 addMagazine "30Rnd_545x39_AK" } forEach [1,2,3,4,5,6,7,8,9,0];  // actual number in array not used
officer1 addWeapon "AK_107_kobra";

You can even make it:

{
 _unit = _x;
 { _unit addMagazine "30Rnd_545x39_AK" } forEach [1,1,1,1,1,1,1,1,1,1];
} forEach [officer1,officer2,officer3,officer4];

nesting "forEach" that is, just remember to keep your eye on what _x is :)

/theOden

Edit: hahaha I got so ninja'd

Edited by [ASA]ODEN
I hate world

Share this post


Link to post
Share on other sites

heh, yeah, just how my brain works. find the solution, then find the problem. :)

Share this post


Link to post
Share on other sites

I just skimmed your posts and I just want to express how wonderful it feels actually getting some help. I have been hopelessly stuck on every attempt at anything more advanced than just using waypoints and triggers. (I know they won't become obsolete, but I think you get what I'm saying)

Just getting some feedback on my simple coding is a giant help. I think I will pile together some different questions in a big thread.:yay:

Thank you guys, you sure did Ninja :D:yay:

edit: Now I'll make my map work (at least that part ;))

edit2: Results: The only solution I could get working was the first posted one, but I know what the trouble is. I'm still not very used to how you pass values through scripts being called by those that call them. Like, I execute a "weapons.sqf" from the init.sqf file, just like execVM "weapons.sqf";.

But how do I syntax it (if that's a verb) so that the other examples willl work? (the ones that make use of _x)

Sorry, english isn't my first language. I hope I'm making my self clear.

---------- Post added at 12:03 AM ---------- Previous post was Yesterday at 11:31 PM ----------

Oh and: I put my self in control of one of the officers and when I ran the script to give him the other gun, he got it put equipped his pistol, the makarov. This doesn't happen if he is moving while he gets the gun though.

Edited by Abrahamsen

Share this post


Link to post
Share on other sites

[val1,val2,val3,val4] execVM "weapons.sqf";

weapons.sqf ->

_val1 = _this select 0;

_val2 = _this select 1;

_val3 = _this select 2;

_val4 = _this select 3;

etc...

But what your asking about is the _x.. that is a built in place holder for the foreach command.

So in my example:

{
_x removeWeapon "AKS_74_U";
_x addWeapon	"AK_107_kobra";
} forEach [officer1,officer2,officer3,officer4];

foreach will run the code for each item in the array given it. this example is

officer1

officer2

officer3

officer4.. so the first time it runs, _x gets replaced with officer1, then 2, etc..

Share this post


Link to post
Share on other sites

Oh, right yeah, I'm mixing it up. All I wanted to be cleared on was passing that array through.

edit: sorry, I'm a noob

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  

×