Madame69 0 Posted September 17, 2005 Hey, i need a script that would let you spawn with a random weapon, I looked everywhere and I cant find one. Not that I suck at scripting, But I cant figure it out.. so I hope you'll help me Madame69 Share this post Link to post Share on other sites
DBR_ONIX 0 Posted September 17, 2005 Not bad idea/request, dont recall it being made before But, basicly.. Look on OFPEC for weaponHolder (in editors depot), for a script that lets you create just a weapon on the ground Then, use the random command, btween 1 and 10 (if you have 10 weapons) Then, make an array of weapon classnames (_weapons=["weap1","weap2"] etc) Then, _selWeapon=_weapons select _random And create that weapon, or put it in an ammo crate etc If you need more detailed help, say, but that gives you a half-decent outline of the code, I hope - Ben {Edit : first result is the code for the weaponHolder You can use an ammo crate in the same way } Share this post Link to post Share on other sites
Madame69 0 Posted September 17, 2005 I think you didnt understand ( Maybe I havent asked clearly? ) well, Im making a MP Mission, a DM one, and I want that every time you spawn, you get a random weapon, get it ? A friend made me a script that worked perfectly, but I deleted it by error.. Btw Peanut butter Ofp time  Edit: Ahh Nevermind I figuret it out myself  <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">; *************************************** ; Operation Flashpoint Script ; *************************************** _Unit = _This select 0 _RandNum = (Random 7) ?_RandNum < 1  && _RandNum > 0: Goto "W1" ?_RandNum < 2  && _RandNum > 1: Goto "W2" ?_RandNum < 3  && _RandNum > 2: Goto "W3" ?_RandNum < 4  && _RandNum > 3: Goto "W4" ?_RandNum < 5  && _RandNum > 4: Goto "W5" ?_RandNum < 6  && _RandNum > 5: Goto "W6" #W1 _Unit AddMagazine "M16" _Unit AddMagazine "M16" _Unit AddMagazine "M16" _Unit AddMagazine "M16" _Unit AddMagazine "M16" _Unit AddWeapon "M16" Goto "Exit" #W2 _Unit AddMagazine "M21" _Unit AddMagazine "M21" _Unit AddMagazine "M21" _Unit AddMagazine "M21" _Unit AddMagazine "M21" _Unit AddWeapon "M21" Goto "Exit" #W3 _Unit AddMagazine "6G30Magazine" _Unit AddMagazine "6G30Magazine" _Unit AddWeapon "6G30" Goto "Exit" #W4 _Unit AddMagazine "HK" _Unit AddMagazine "HK" _Unit AddMagazine "HK" _Unit AddMagazine "HK" _Unit AddMagazine "HK" _Unit AddWeapon "HK" Goto "Exit" #W5 _Unit AddMagazine "SteyrMag" _Unit AddMagazine "SteyrMag" _Unit AddMagazine "SteyrMag" _Unit AddMagazine "SteyrMag" _Unit AddMagazine "SteyrMag" _Unit AddWeapon "Steyr" Goto "Exit" #W6 _Unit AddMagazine "M60" _Unit AddMagazine "M60" _Unit AddMagazine "M60" _Unit AddMagazine "M60" _Unit AddMagazine "M60" _Unit AddWeapon "M60" Goto "Exit" #Exit Exit Just need to Add _unit selectweapon "weapon" everywhere and its ok Share this post Link to post Share on other sites
Doolittle 0 Posted September 17, 2005 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_RandNum = (Random 7) ?_RandNum < 1 Â && _RandNum > 0: Goto "W1" ?_RandNum < 2 Â && _RandNum > 1: Goto "W2" ?_RandNum < 3 Â && _RandNum > 2: Goto "W3" ?_RandNum < 4 Â && _RandNum > 3: Goto "W4" ?_RandNum < 5 Â && _RandNum > 4: Goto "W5" ?_RandNum < 6 Â && _RandNum > 5: Goto "W6" I just wanted to point out this could be: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_RandNum = (Random 7) ?_RandNum < 1 : Goto "W1" ?_RandNum < 2 : Goto "W2" ?_RandNum < 3 : Goto "W3" ?_RandNum < 4 : Goto "W4" ?_RandNum < 5 : Goto "W5" ?_RandNum < 6 : Goto "W6" ...I just think that's cool. Â I love programming. Doolittle Share this post Link to post Share on other sites
silola 1086 Posted September 17, 2005 hi, you can shorten the script around something... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Unit = _this select 0 _AmmoArray = [["M16","M16",5],["M21","M21",5],["6G30","6G30Magazine",2],["HK","HK",5],["Steyr","SteyrMag",5],["M60","M60",5]] _RandomAmmo = (_AmmoArray select (random ((count _AmmoArray) - 1))) _Unit AddWeapon (_RandomAmmo select 0);_i = 0 While {_i < (_RandomAmmo select 2)} do {_Unit AddMagazine (_RandomAmmo select 1);_i = _i + 1} exit bye silola Share this post Link to post Share on other sites
DBR_ONIX 0 Posted September 17, 2005 Ah, didn't notice you wanted to spawn the unit with a random weapon, though you meant spawn a random weapon (on the ground) Silola's idea is the neatest, and it's easy to add new weapons to, compared to the other example where you need to add several more lines - Ben Share this post Link to post Share on other sites
Doolittle 0 Posted September 18, 2005 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_RandomAmmo = (_AmmoArray select (random ((count _AmmoArray) - 1))) Doing a select of, say, 1.4 doesn't hurt anyone? Â I thought you had to do a _r - (_r % 1) or something. Share this post Link to post Share on other sites
silola 1086 Posted September 18, 2005 hi, this also functions in this form. OFP interprets 1.4 as 1 at this point, or 1.8164 as 2 et cetera bye silola Share this post Link to post Share on other sites