JacobJ 10 Posted February 22, 2012 (edited) Hey all I am currently playing around with Shuko's script that randomly puts objects inside a marker. It all works fine, but I would like to tweak it a bit. I have a trigger that covers 30 blufor soldiers. I have made a list of all those soldier which are in the variable "hul". I use SHK_pos script to find a random position for all those soldiers in the list and it works very well. BUT: I would like to only position those soldiers on rooftops, cranes, silos and so on. I have thought of making an if statement, that checks if the individual soldiers height above sealevel is more than 2 meter, if not, then run the SHK_pos script again for that soldier. But the problem with this is, that it seems a bit to stupid. The script has to run untill all players are more than 2 meter above sealevel, that could take ages if I ramp up the number of soldiers. I would like to hear suggestion to alternative solutions for this. Hope you all can help me. /Jacob Btw. Ive found this thread: http://forums.bistudio.com/showthread.php?96497-setPos-height-snap-to-non-terrain-surface&highlight=setpos+roofs It could be a part of the solution, but it still doesnt help me position the soldiers over buildings only... Edited February 22, 2012 by JacobJ forgot.. Share this post Link to post Share on other sites
sxp2high 23 Posted February 22, 2012 (edited) Hi, I have a simple, yet not very beautiful solution to this. I used this in a mission of mine and it works just fine. It will place enemies on rooftops, even if those rooftops are not possible to reach under normal circumstances. First I search for "Building". This includes cranes, silos and even cargo containers and such. Run this code only once at the very beginning of the mission: hul_buildings = nearestObjects [(getMarkerPos "myCenter"), ["Building"], 500]; "myCenter" is a marker in the area where you want to have the units placed. 500 is obviously the radius around the marker. Now run the rest of the code to place them: { _building = (hul_buildings call BIS_fnc_selectRandom); // Select a random building from the array hul_buildings = (hul_buildings - [_building]); // Delete the building from the array, so it wont get used again _x setPosATL [(getPosATL _building select 0), (getPosATL _building select 1), 50]; // Set the unit pos to 50 Above Terrain level, he will fall down onto the building _x spawn { _this allowDamage false; sleep 10; _this allowDamage true; }; // Prevent falling damage _x setUnitPos (["Up", "Middle"] call BIS_fnc_selectRandom); // Make him stand or kneel, because lying enemies on rooftops wont be visible and often cannot engage } forEach hul; I tested this on Fallujah many many times, and it works great! You could, for example run this in your init.sqf: [] spawn { // Make a new thread, so it doesn't slow down the init.sqf hul_buildings = nearestObjects [(getMarkerPos "myCenter"), ["Building"], 500]; waitUntil {!(isNil "hul_buildings")}; // Make sure the nearestObejcts search is completed { _building = (hul_buildings call BIS_fnc_selectRandom); hul_buildings = (hul_buildings - [_building]); _x setPosATL [(getPosATL _building select 0), (getPosATL _building select 1), 50]; _x spawn { _this allowDamage false; sleep 10; _this allowDamage true; }; _x setUnitPos (["Up", "Middle"] call BIS_fnc_selectRandom); } forEach hul; }; P.s. I know this is a nightmare for the scheduled arma engine, with all the spawns. It may need to be partly rewritten for large missions with lots of scripts running. Edited February 22, 2012 by sxp2high Share this post Link to post Share on other sites
shuko 59 Posted February 22, 2012 Not perfect, but better than nothing: http://derfel.org/arma2/scripts/SHK_buildingpos.sqf Share this post Link to post Share on other sites
JacobJ 10 Posted February 22, 2012 Okay, that is awesome! Just what I needed. I was partly on to that nearestObjects command, but Ive never would have figured all this out by myself. Thank you very much! ---------- Post added at 01:46 PM ---------- Previous post was at 01:21 PM ---------- Hmm can't seem to get it working. If I run it in a script.sqf and start it manually via addaction menu. Then it places them in the buttom left corner, but outside the map. I comes with an error: Error in expression <ngs = (hul_buildings - [_building]); _x setPosATL [(getPosATL _building select 0> Error position: <setPosATL [(getPosATL _building select 0> Error Type Any, expected Number File C:\Users\Jacco\Documents\ArmA 2\missions\3onFAllu.fallujah\findBuildingsAndRandomPosHUL.sqf, line 8 Whats the problem you think? Share this post Link to post Share on other sites
sxp2high 23 Posted February 22, 2012 Where and how do you add the units to the hul array? You may have to add this line: waitUntil {!(isNil "hul") && (count hul > 0)}; // Wait until the units are added to the array before or after this: waitUntil {!(isNil "hul_buildings")}; // Make sure the nearestObjects search is completed Here's a small demo mission: http://server.arma2.co/Files/BTK/rooftop.fallujah.rar Share this post Link to post Share on other sites
JacobJ 10 Posted February 22, 2012 I now know what the error is. Its because there are no buildings left to place the units on. Lets say you have 30 buildings and 40 soldiers, then you get that error. BUT: the units still spawn in the buttom left corner by me... Share this post Link to post Share on other sites
sxp2high 23 Posted February 22, 2012 We could check for that. What do you want to do with them if there are no more buildings? Share this post Link to post Share on other sites
JacobJ 10 Posted February 22, 2012 Shuko, your script works somehow. It seems it only can handle so, and so many units. If I ramp the numbers up it doesnt seem to be able to place them all. Only around 15-25 gets placed... How can that be? Ive found out what was wrong with my units that spawned in the buttom left corner.. Somehow the marker I was using put them down there.. Ive made a new one and now it works.. It seems like the units doesnt spawn all the way up in cranes and stuff like that, is that true or is it just coincidens? Shuko's script with the rooftop feature enabled put all units on the very highest points, which would be nice to have a more diversity, but maybe it possible and I just havnt figured out how. If there is no more buildings left, then just place them on those buildings already used. More people on the same roof isnt to any harm:D Share this post Link to post Share on other sites
sxp2high 23 Posted February 22, 2012 (edited) You can just "refill" the array in that case. if (count hul_buildings < 1) then { hul_buildings = nearestObjects [(getMarkerPos "myCenter"), ["Building"], 500]; }; { if (count hul_buildings < 1) then { hul_buildings = nearestObjects [(getMarkerPos "myCenter"), ["Building"], 500]; }; // Check if buildings left in the array _building = (hul_buildings call BIS_fnc_selectRandom); hul_buildings = (hul_buildings - [_building]); _x setPosATL [(getPosATL _building select 0), (getPosATL _building select 1), 50]; _x spawn { _this allowDamage false; sleep 10; _this allowDamage true; }; _x setUnitPos (["Up", "Middle"] call BIS_fnc_selectRandom); } forEach hul; Cranes should work usually. For me it did anyway. But you can increase the ATL value to 100 or so. _x setPosATL [(getPosATL _building select 0), (getPosATL _building select 1), 50]; > _x setPosATL [(getPosATL _building select 0), (getPosATL _building select 1), 100]; Keep in mind, that sometimes, with my "fallen angels" method, they glitch of the edges and fall to the ground. But all in all it does the job pretty well. Edited February 22, 2012 by sxp2high Share this post Link to post Share on other sites
JacobJ 10 Posted March 1, 2012 Shuko, any possibility to take out the buildings already used in your script? It seems they are stacking up at a few buildings only. I have 5 men which position themselfs on only two buildings. It would be nice to spread them out a bit. Maybe a limit parameter for each buildingpos would be nice. Just a suggestion if you plan on upgrading it. Share this post Link to post Share on other sites