Jump to content
Sign in to follow this  
whisky

Random loots and weapons

Recommended Posts

So, I am trying to make a random loot with random weapons, I placed empty triggers with names, and I made a script that chooses a random weapon from an array and then a I made a "for" loop that will create a "WeaponHolder" with that random Weapon.

_var1 = 0;
weap = [_var1];

_rndPrim = 0;

_prim = ["PK", "AA12_PMC", "ACE_AK74M", "ACE_AK74M_GL", "ACE_G36A1_AG36A1_D", "ACE_G36K_iron", "ACE_HK416_D10_AIM", "ACE_KAC_PDW", "ACE_M1014_Eotech", "ACE_m16a2gl_scope", "ACE_M16A4_EOT"];

//the loop
for [{_var1 = 1}, {_var1 < 2}, {_var1 = _var1 + 1}] do {
weap = createVehicle ["WeaponHolder", getPos test, [],0, "NONE"];
_rndPrim = ceil Random (count _prim);	
_weapon = _prim select _rndPrim;

weap addWeaponCargo [_weapon,1];

};

When I run the script it won't spawn the weapon, please help.

Edited by whisky

Share this post


Link to post
Share on other sites

Double-check your weapons. I've had multiple errors with the latest version of ACE & ACEX telling me these weapons can't be found. For a list of weapons I recommend this (it includes ACE & ACEX weapons): http://browser.six-projects.net/cfg_weapons/classlist?utf8=%E2%9C%93&version=62&commit=Change&options

//Edit

Checked it with other weapons and it's giving me an error of _weapon not being defined.

Edited by tryteyker

Share this post


Link to post
Share on other sites
Double-check your weapons. I've had multiple errors with the latest version of ACE & ACEX telling me these weapons can't be found, the script generally works fine. For al ist of weapons I recommend this (it includes ACE & ACEX weapons): http://browser.six-projects.net/cfg_weapons/classlist?utf8=%E2%9C%93&version=62&commit=Change&options[group_by]=weap_type&options[custom_type]=&options[faction]=USMC

Well, the weapons are fine, I also have put FN_FAL to test it instead of _weapon and it still didn't work.

Share this post


Link to post
Share on other sites

Hi... maybe something like this.... note the changes. Also the marker name is passed to the script.

script.sqf:-

_mkr = _this select 0;

_prim = ["M16A2GL", "M4A1_RCO_GL", "M4A1_HWS_GL", "G36_C_SD_eotech"];

_weapholder = createVehicle ["WeaponHolder", getMarkerPos _mkr, [],0, "CAN COLLIDE"];

//the loop
for "_i" from 1 to 2 do {
_weapon = _prim select floor (random (count _prim));
_weapholder addWeaponCargo [_weapon,1];
hint "weapon added";
sleep 1;
};

Execute with...

nul = ["mkr_test"] execVM "script.sqf";

Share this post


Link to post
Share on other sites
Hi... maybe something like this.... note the changes. Also the marker name is passed to the script.

script.sqf:-

_mkr = _this select 0;

_prim = ["M16A2GL", "M4A1_RCO_GL", "M4A1_HWS_GL", "G36_C_SD_eotech"];

_weapholder = createVehicle ["WeaponHolder", getMarkerPos _mkr, [],0, "CAN COLLIDE"];

//the loop
for "_i" from 1 to 2 do {
_weapon = _prim select floor (random (count _prim));
_weapholder addWeaponCargo [_weapon,1];
hint "weapon added";
sleep 1;
};

Execute with...

nul = ["mkr_test"] execVM "script.sqf";

Thanks, I check this out tommorow.

But from what I see it will only spawn one Weapon Holder because there is only one "_weapholder". Or am I wrong?

Share this post


Link to post
Share on other sites

It will spawn 1 weapon holder....with 2 weapons in that holder.

If you want weaponholder's at random positions then the code will be slightly different. You will need to also generate random positions from a list of markers or whatever.

Share this post


Link to post
Share on other sites
It will spawn 1 weapon holder....with 2 weapons in that holder.

If you want weaponholder's at random positions then the code will be slightly different. You will need to also generate random positions.

---------- Post added at 10:49 AM ---------- Previous post was at 10:48 AM ----------

It will spawn 1 weapon holder....with 2 weapons in that holder.

If you want weaponholder's at random positions then the code will be slightly different. You will need to also generate random positions from a list of markers or whatever.

What I want is to spawn several Weapon Holders with one random weapon. I understand that createVehicle can take radius from a marker so I can spawn several creates in a 'random' location, which works, but the problem is to create in a loop several Weapon Holders.

I know it's possible, but I don't know how.

Share this post


Link to post
Share on other sites

Just testing and for createVehicle you have to specify the radius around the markers center. It doesn't use the markers dimensions.

The problem with "random locations" is that they sometimes end up being less than ideal. Half way through a wall, in a tree trunk... that kind of stuff. Finding good locations is a whole other scripting experience. Lots of posts on random good locations. Check them out.

Anyhow... if you have a list of markers it's easier. Here is the loop you need.

[b]_markers[/b] = ["mkr1","mkr2","mkr3","mkr4","mkr5"];

_prim = ["M16A2GL", "M4A1_RCO_GL", "M4A1_HWS_GL", "G36_C_SD_eotech"];

//the loop
for "_i" from 1 to 2 do {
_weapholder = createVehicle ["WeaponHolder", getPos player, [b]_markers[/b],0, "CAN COLLIDE"];
_weapon = _prim select floor (random (count _prim));
_weapholder addWeaponCargo [_weapon,1];
hint format ["weapon %1 added",_i];
sleep 1;
};

Share this post


Link to post
Share on other sites
Just testing and for createVehicle you have to specify the radius around the markers center. It doesn't use the markers dimensions.

The problem with "random locations" is that they sometimes end up being less than ideal. Half way through a wall, in a tree trunk... that kind of stuff. Finding good locations is a whole other scripting experience. Lots of posts on random good locations. Check them out.

Anyhow... if you have a list of markers it's easier. Here is the loop you need.

[b]_markers[/b] = ["mkr1","mkr2","mkr3","mkr4","mkr5"];

_prim = ["M16A2GL", "M4A1_RCO_GL", "M4A1_HWS_GL", "G36_C_SD_eotech"];

//the loop
for "_i" from 1 to 2 do {
_weapholder = createVehicle ["WeaponHolder", getPos player, [b]_markers[/b],0, "CAN COLLIDE"];
_weapon = _prim select floor (random (count _prim));
_weapholder addWeaponCargo [_weapon,1];
hint format ["weapon %1 added",_i];
sleep 1;
};

So instead of writing about 70~ marker names, is there a way that the script will auto add them instead me writing, and use that?

Share this post


Link to post
Share on other sites

You can use a for loop and the format command to compile your array:

_array = [];
for "_i" from 0 to 10 do 
{
_marker = format ["marker_%1",_i];
_array = _array + [_marker];
};

Share this post


Link to post
Share on other sites
You can use a for loop and the format command to compile your array:

_array = [];
for "_i" from 0 to 10 do 
{
_marker = format ["marker_%1",_i];
_array = _array + [_marker];
};

thanks a lot.

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  

×