Jump to content
Sign in to follow this  
thedog88

spawn random item in buildings within a given radius

Recommended Posts

hey guys, i spent the last 3 hours searching for something like this and i know its going to sound like the dayz loot system, but thats not what its for. im trying to figure out how i can spawn a random number (lets say between 0-5) of randomly selected items (predefined list) inside of buildings within a certain radius.

so lets say i place a trigger center of town, with a 200 meter radius and define a list of objects in either the editor or in an sqf. now when the player goes into this town, every building within 200 meters that he walks into will have between 0-5 items inside.

again, this sounds like the loot system from dayz but what im trying to accomplish here is giving people buildings that they actually need to search. how many missions do we have that require a player to go into a village and search the entire village for stuff but only the item they need to find is inside a predefined building? so usually it takes you 2 seconds to walk through a house. imagine every house had shit laying around inside of it and now the player has to check all that crap. searching a house would take up more time.

i figured you could somehow use the AI points within buildings as spawn points and i looked into scripts that look for the points and what not. im not a newb but im not good at scripting so i just got lost in most scripts i opened.

i found this thread and it seems that person is the closest to what im looking for but he is trying to spawn items on a marker or specific spot to where i want it randomized within buildings. http://forums.bistudio.com/showthread.php?142227-Random-loots-and-weapons&highlight=loot

would anybody know how to do this? :(

Share this post


Link to post
Share on other sites

I'm using this in my wip zombie sandbox mission:

_houseList = getPos _trig nearObjects ["House",200];
{
 _c = 0;
 while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
 if (_c > 0) then
    {
       _ranNum = floor(random _c);
       _crate = "USBasicAmmunitionBox" createVehicle [0,0,0];
       _crate setPos (_x buildingPos _ranNum);
    };
 sleep 0.123;
} forEach _houseList;

Share this post


Link to post
Share on other sites

awesome i will give this ago as soon as possible. can you explain this a bit though? i take it the 200 in here ["House",200] is the radius it checks for? does this create a crate or does it use whats inside of "usbasicammunitionbox"? also where do you define how many items per house spawn? im so glad you replied btw o.0 if your making a zombie survival mod check out my ARP addon. 125 random items added to the game :)

edit, also did you just put this in a trigger activation line or did u make it a sqf and launch it?

Edited by Thedog88

Share this post


Link to post
Share on other sites
i take it the 200 in here ["House",200] is the radius it checks for?

Yes.

does this create a crate or does it use whats inside of "usbasicammunitionbox"?

Yes in this example it spawn US Basic Ammunitionbox, "MtvrRefuel" would spawn a fuel truck.

also where do you define how many items per house spawn?

This example is just for testing i havent finished it yet. As it is now it will select one random position per house(if it got any positions) and place a ammobox. Let me know you needs and i will edit it to do so.

also did you just put this in a trigger activation line or did u make it a sqf and launch it?

In this example i executed it from a trigger but it can be done from anywhere.

im so glad you replied btw o.0 if your making a zombie survival mod check out my ARP addon 125 random items added to the game :)

I did see it and already posted there. I actually started making my own "items" mod as i need other stuff like ammoboxes without "Rearm at US Basic Ammobox" action etc.

Here's an example mission -> http://www.filedropper.com/spawnobjectschernarus

Start spawn with radio alpha. A marker is created where a ammobox is spawned.

Edited by JW Custom
added mission example

Share this post


Link to post
Share on other sites

thats awesome. how can i make it choose a random item from a defined list and then spawn that. what im trying to do is drop several items into each house within that 200 meter radius. so that players can go into that house and physically search it.

_houseList = getPos _trig nearObjects ["House",200];

{

_c = 0;

while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};

if (_c > 0) then

{

_ranNum = floor(random _c);

_crate = ["item", "item", "item"] createVehicle [0,0,0];

_crate setPos (_x buildingPos _ranNum);

};

sleep 0.123;

} forEach _houseList;

would this work? adding the items there?

Edited by Thedog88

Share this post


Link to post
Share on other sites

Here it select a random gun from the items array:

private ["_houseList","_i","_c","_ranNum","_items"];

_items = ["glock17_EP1","Makarov","M9","M9SD","MakarovSD","Colt1911","revolver_EP1"];

_trig      = _this select 0;
_spawnSize = _this select 1;
_debug     = _this select 2;     

_houseList = getPos _trig nearObjects ["House",100];

_i = 0;

{
_c = 0;

 while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
 if (_c > 0) then
 {
     _ranNum = floor(random _c);
     _item = _items select floor(random(count _items));
     _loot = _item createVehicle [0,0,0];
     _loot setPos (_x buildingPos _ranNum);

   if (_debug) then
   {
      _marker = format ['_marker%1',_i];
      _mkr = createMarker[_marker, getPos _crate];
      _marker setMarkerType 'hd_dot';
      _marker setMarkerSize[1, 1];
      _marker setMarkerDir 1;
      _marker setMarkerColor 'ColorOrange';
      _marker setMarkerText '';
      _i = _i + 1;
   };
 };

sleep 0.123;

} forEach _houseList;

Share this post


Link to post
Share on other sites

sweet, i will try it in a minute.

---------- Post added at 14:03 ---------- Previous post was at 13:41 ----------

not getting it to work :(

i tried your script out of your mission, works fine, but the second one nothing happens o.0

Edited by Thedog88

Share this post


Link to post
Share on other sites

yeah theres a few errors, first you cant spawn weapons with createVehicle but with addWeapon to a weaponHolder, doh :p

This should work:

private ["_houseList","_i","_c","_ranNum","_items","_loot"];

_items = ["USBasicAmmunitionBox","RUOrdnanceBox","LocalBasicAmmunitionBox","LocalBasicWeaponsBox"];

_trig      = _this select 0;
_spawnSize = _this select 1;
_debug     = _this select 2;     

_houseList = getPos _trig nearObjects ["House",100];

_i = 0;

{
_c = 0;

 while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
 if (_c > 0) then
 {
     _ranNum = floor(random _c);
     _item = _items select floor(random(count _items));
     _loot = _item createVehicle [0,0,0];
     _loot setPos (_x buildingPos _ranNum);

   if (_debug) then
   {
      _marker = format ['_marker%1',_i];
      _mkr = createMarker[_marker, getPos _loot];
      _marker setMarkerType 'hd_dot';
      _marker setMarkerSize[1, 1];
      _marker setMarkerDir 1;
      _marker setMarkerColor 'ColorOrange';
      _marker setMarkerText '';
      _i = _i + 1;
   };
 };

sleep 0.123;

} forEach _houseList;

So if you wanna place items/weapons/mags on the ground you would need something like this with the above:

_loot = "WeaponHolder" createVehicle [0,0,0];
_loot addWeaponCargoGlobal ["AKS_74_kobra",1];
_loot setPos (_x buildingPos _ranNum);

Edited by JW Custom

Share this post


Link to post
Share on other sites

so how can i spawn a weaponsholder and add a item with this script? also how can i make it so between 0-5 items spawn per building? (im planning on using my ARP mod with this so the items are randomly found in buildings)

edit:

so it would look like this?

private ["_houseList","_i","_c","_ranNum","_items","_loot"];

_items = ["weaponholder"];

_trig      = _this select 0;
_spawnSize = _this select 1;
_debug     = _this select 2;     

_houseList = getPos _trig nearObjects ["House",100];

_i = 0;

{
_c = 0;

 while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
 if (_c > 0) then
 {
     _ranNum = floor(random _c);
     _loot = "WeaponHolder" createVehicle [0,0,0];
     _loot addWeaponCargoGlobal ["AKS_74_kobra",1];
     _loot setPos (_x buildingPos _ranNum);

   if (_debug) then
   {
      _marker = format ['_marker%1',_i];
      _mkr = createMarker[_marker, getPos _loot];
      _marker setMarkerType 'hd_dot';
      _marker setMarkerSize[1, 1];
      _marker setMarkerDir 1;
      _marker setMarkerColor 'ColorOrange';
      _marker setMarkerText '';
      _i = _i + 1;
   };
 };

sleep 0.123;

if that is correct let me know? so where do i define how many items per building drop and where can i make the content of the weaponholder random?

edit 2:

it wouldnt be as simple as this would it?

      _loot addWeaponCargoGlobal ["AKS_74_kobra","item1", "item2",1];

Edited by Thedog88

Share this post


Link to post
Share on other sites

i love you! it works perfect. i hope you dont mind if i tweak this as needed. ill create spawn_norm.sqf, spawn_susp.sqf, and maybe a spawn_mil.sqf so i can trigger normal, suspicious and military items as needed. this is too perfect my friend. i appreciate it so much! i am talking to somebody about making a similar script that would remove all items from civilians and add random items again so you dont always find map, compass, radio, watch on them. once i have these 2 scripts together im wanting to possibly make a module containing all this. would you be ok with me using your codes that you gave me provided i give you credit?

Share this post


Link to post
Share on other sites

Feel free to use it as you please.

No credits needed, all i know i've learned from this community :cool:

Share this post


Link to post
Share on other sites

Can I use this code for arma3? Do I have "init.sqf" in which only the "execVM" loot.sqf "," submit or I have to create the "marker"?

private ["_houseList","_i","_c","_ranNum","_items","_loot"];

_items = ["weaponholder"];

_trig = _this select 0;

_spawnSize = _this select 1;

_debug = _this select 2;

_houseList = getPos _trig nearObjects ["House",100];

_i = 0;

{

_c = 0;

while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};

if (_c > 0) then

{

_ranNum = floor(random _c);

_loot = "WeaponHolder" createVehicle [0,0,0];

_loot addweaponcargoo ["arifle_MX_F","arifle_MX_GL_F","arifle_MX_SW_F","arifle_MXC_F","arifle_MXM_F","arifle_SDAR_F","arifle_TRG20_F","arifle_TRG21_F","arifle_TRG21_GL_F",1];

_loot setPos (_x buildingPos _ranNum);

if (_debug) then

{

_marker = format ['_marker%1',_i];

_mkr = createMarker[_marker, getPos _loot];

_marker setMarkerType 'mil_dot';

_marker setMarkerSize[1, 1];

_marker setMarkerDir 1;

_marker setMarkerColor 'ColorOrange';

_marker setMarkerText '';

_i = _i + 1;

};

};

sleep 0.123;

Edited by [FRL]Myke
Removed non-english text

Share this post


Link to post
Share on other sites

you may need to use "groundWeaponHolder" instead of "WeaponHolder"

Share this post


Link to post
Share on other sites

Hey, could you please reupload this? Ive been trying for a MONTH now and I cant anything to work! Please Help.

Share this post


Link to post
Share on other sites

I'd also like to see the upload. I've been looking for this type of loot system for a while and the upload site doesn't have it anymore.

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  

×