tophe 69 Posted February 24, 2007 As some of you have noticed I have been writing about the command buildingPos the last days. I am now working on a script that should be able to put a unit at a random position of any building. But first I need the script to find out how many positions there are in the specific building. My idea is to have something like this... (the syntax is probably all messed up but I think you get the idea) x=0 #LOOP gameLogic setPos (house buildingpos x); logicPos = getpos gameLogic; ? logicPos (select 0) == 0 and logicPos (select 1) == 0 goto END# x = x + 1; goto #LOOP #END unit setPos (house buildingPos (random x)); This way the loop should place a gamelogic (named gameLogic) first at buildingPos 0 (since x is 0) then it would increase the buildingPos by 1 and move the gameLogic there. When a unit is placed at a buildingPos that does not exist ArmA moves it to (0,0,0). So every loop I check if the first two position axis = 0. If they do the gameLogic has now been placed at one buildingPos above what is available for the specific building. So the loop now sends us to #END where a unit is placed at a random number between 0 and X in the specific building. Thus X should be the highest buildingPos available (well... +1. But random starts at 0 so the X is acctually -1 here) That is my idea.. I hope you followed me. Is this possible? Or is there an easier way to do it? Any ideas on the script before a dig my teeth in it? Regards. Tophe, Östgöta Ops. Share this post Link to post Share on other sites
kronzky 5 Posted February 24, 2007 The concept is right, but you don't actually need to place anything on those positions to read them. If you read hptst=house buildingPos x, then hptst will return a 3D-position array (which is [0,0,0] if the position doesn't exist). So in your loop just read those incrementing positions, and once one element in the position array is zero (you really only need to check one of them) then you know how many positions there are. Share this post Link to post Share on other sites
baddo 0 Posted February 24, 2007 Hi, Once upon a time I wrote a function called buildingPosCount for OFP which returns the number of indexed positions in a building. I will put the function up here too in addition to the link, just in case something happens for OFPEC: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// ************************************************* // buildingPosCount.sqf // Returns number of indexed positions in a building. // These positions can be used with the buildingPos function. // When using indexed positions from a script, // take in notice that 1st position has index number 0, // 2nd has index number 1 and so on. So if a building // has 8 positions, you can use them as 0...7 from a script // with the buildingPos function. // USAGE: // init: buildingPosCount = preprocessFile "buildingPosCount.sqf" // calling: <building> call buildingPosCount // returns: <integer> // example: _posses = nearestBuilding player call buildingPosCount // Baddo 2005 // You can contact me through www.ofpec.com // ************************************************* private "_i"; _i = 0; while { format ["%1", _this buildingPos _i] != "[0,0,0]" } do { _i = _i + 1; }; _i By the way, I noticed that nearestBuilding isn't detecting buildings which are placed in a script or in the editor. I recall that in OFP it worked but not so anymore in ArmA. You will want to use the other functions starting with near if you want to query for the buildings in a script. Regards, Baddo. Share this post Link to post Share on other sites
VanhA 10 Posted February 24, 2007 I found out this by accident: I placed a unit near bulding and added a waypoint into bulding. When in waypoint mode it shows off all building positions available. Some of them might be behind closed doors though but it helps a bit.... Share this post Link to post Share on other sites
baddo 0 Posted February 24, 2007 I found out this by accident: I placed a unit near bulding and added a waypoint into bulding. When in waypoint mode it shows off all building positions available. Some of them might be behind closed doors though but it helps a bit.... Yes that's true, it worked in OFP too. But what if you can't do it with the pre-determined waypoints... then it involves scripting. Cheers, Baddo. Share this post Link to post Share on other sites
tophe 69 Posted February 24, 2007 Thank you guys for your help! This is how I solved it: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> x = 0; while { format ["%1", house buildingPos x] != "[0,0,0]" } do {x = x + 1}; hint format ["%2: 0 - %1", x-1, "Available positions"]; p1 setPos (house buildingPos (random x)); Pretty much Baddo's idea. I updated my little tutorial with this script at this thread: http://www.flashpoint1985.com/cgi-bin....t=58402 Share this post Link to post Share on other sites