OFPEC Forum
Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: Andor14 on 10 May 2011, 19:58:28
-
hi
well i believe i have ask it before, but i cannot find the post and i lost my mission file. so i will ask again.
How do you make a soldier carry a weapon random selected in a list. i remember that it was somthing like this addweapon "m16a4,m4a1(((random)count)2)" , well i totally forgot how it worked.
plz help me, many thanks in advance.
-
Hi there,
perhaps this will help:
_wpns = ["m4a1","m16a4","m24","m107","m240","m249"];
_wcount = count _wpns;
_rdm = round (random _wcount);
_wpn = _wpns select _rdm;
_this addweapon format ["%1", _wpn];
Not sure if this can be shortened or simplified here and there... Written from memory, ye kno?
Btw, what you see above is to be put into a script. If you want to put that stuff directly into a unit's init-line, make sure to remove all the _'s (as in, "wpns" instead of "_wpns", etc.). Should then work.
Good day,
mr_book
-
whoohoo :D it worked thanks for your help.
edit: i did run into a problem though, there is a chance that it random selects no weapon at all. you will get the message that it can't find the weapon <null>. how can u solve this?
-
count counts the elements in the array from 1 to whatever but the first element index is 0 (zero) so you need to use
_wcount = (count _wpns) - 1;
The count of the array ["m4a1","m16a4","m24","m107","m240","m249"] is 6 but the indexes start from 0 and end in 5.
-
ok it works perfect now. many thanks h- and mr_book :D