{"name":"selectBestPlaces","operator":null,"title":"selectBestPlaces","type":"command","url":"https://community.bistudio.com/wiki/selectBestPlaces","revid":377620,"updated":"2026-01-02T08:51:55Z","groups":["Mission Information"],"status":"ok","replaced_by":[],"games":[{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma2","name":"Arma 2","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Find the places with the maximum value of *expression* in the given area. Places can be on water. Results are sorted by value. Search pattern is randomised every command execution.","syntaxes":[{"syntax":"selectBestPlaces [position, radius, expression, precision, sourcesCount]","since":null,"effect":null,"exec":null,"params":[{"name":"position","type":"Object, Position3D or Position2D","optional":false,"default":null,"description":null,"types":["Object","Position3D","Position2D"],"since":null,"text":"position: Object, Position3D or Position2D"},{"name":"radius","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"radius: Number"},{"name":"expression","type":"String","optional":false,"default":null,"description":"arithmetic expression. Simple expression var names containing values from 0 to 1 depending on location (see also Ambient Parameters):\n- forest\n- trees\n- meadow\n- hills\n- houses\n- sea\n- coast\n- night\n- rain\n- windy\n- deadBody\n- waterDepth\n- camDepth","types":["String"],"since":null,"text":"expression: String - arithmetic expression. Simple expression var names containing values from 0 to 1 depending on location (see also Ambient Parameters):\n- forest\n- trees\n- meadow\n- hills\n- houses\n- sea\n- coast\n- night\n- rain\n- windy\n- deadBody\n- waterDepth\n- camDepth"},{"name":"precision","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"precision: Number"},{"name":"sourcesCount","type":"Number","optional":false,"default":null,"description":"max results to return. The maximum possible is the number of random samples, which is **n = (2 * radius / precision)^2**","types":["Number"],"since":null,"text":"sourcesCount: Number - max results to return. The maximum possible is the number of random samples, which is **n = (2 * radius / precision)^2**"}],"returns":{"type":null,"types":["Array","Position2D","Number"],"description":null,"text":"Array with [[position: Position2D, expressionResult: Number], ...]"},"form":"unary","operator":null,"left":null,"right":{"text":"[position, radius, expression, precision, sourcesCount]","types":["Array"]}}],"examples":[{"text":"```sqf\nmyPlaces = selectBestPlaces [position player, 50, \"meadow + 2*hills\", 1, 5];\n```","code":["myPlaces = selectBestPlaces [position player, 50, \"meadow + 2*hills\", 1, 5];"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["getEnvSoundController","getAllEnvSoundControllers","findEmptyPosition","isFlatEmpty","Ambient Parameters"],"notes":[{"user":"Rübe","date":"2010-07-17T18:39:00Z","text":"see http://forums.bistudio.com/showthread.php?t=93897 for some more information (though neither official, nor complete).\nThe most important information is the list of useable keywords for the expression which is: **forest, trees, meadow, hills, houses, sea, night, rain, windy** and **deadBody**.\nThe keyword will be replaced by the actual value at the given sample position and thus the expression gets evaluated.\nFor example the following expression (which returns high values in forest) *\"forest + trees - meadow - houses - (10 * sea)\"* might be transformed to *0 + 0.1 - 0.7 - 0 - (10 * 0)* which is - with it is result of -0.6 - not in the forest, though there are some tree(s) around. You get the idea.\n\nAlso note that you may aswell check such an expression value at a single position by passing a low radius and a sourceCount of 1, which is often just as useful as retrieving multiple (and already sorted) positions.\n\nAlso do not underestimate the keywords *night*, *rain* or *windy*, for if you couple them with the other keywords, you can easily get a highly dynamic system at a very low cost.\n(this, btw., is how animals \"choose\" where and when to spawn)"},{"user":"ffur2007slx2_5","date":"2014-04-03T16:10:00Z","text":"In Arma 3 ver 1.14 Two new expressions are available: **waterDepth**(0-1) and **camDepth**(0-1), along with three simple operators: **interpolate**, **randomGen** and **factor** that can be used together with expressions. E.g.\n\n```sqf\np = selectBestPlaces [\n    position player,\n    500,\n    \"(2 * (waterDepth interpolate [1,16,0,1]) * ((0.1+houses factor [0.1,0.8]) * (randomGen 1 + houses)))\",\n    1,\n    1\n];\n```\n\n**A**lgorithm randomGen:\n`randomGen A(number): randomly generate a float number from 0 - A`\n**A**lgorithm factor:\n`A(number) factor [p,q] = p< A <q: [(A -p)/(q-p)]`\n**A**lgorithm interpolate:\n`A(number) interpolate [p,q,r,s] = A <=p:r A >=q:s p< A <q: [(A -p)/(q-p)]*(s-r) +r`"},{"user":"Killzone_Kid","date":"2015-06-15T13:27:00Z","text":"*precision* seems to have range 0 - 100. At very low values the command is extremely slow. 100 makes it quite fast. It looks like *precision* is some kind of grid search size.\nLarge chunks make the search faster but less accurate.\n\nResulting array is [] if *sourcesCount* is 0 or  *expression* is \"\". In all other cases it seems that result is array of arrays of the set max count.\nThe sole indication of successful search is *expressionResult* value when it is > 0."},{"user":"Tankbuster","date":"2017-06-04T20:51:00Z","text":"Results are sorted by value, that is, the result of the expression.\nThey are sorted in descending order, so in the case of waterdepth, the deepest water will be found at the locations at the start of the returned array and the shallowest water will be found at the locations at the end."}],"categories":["Arma 2: New Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Mission Information","Introduced with Arma 2 version 1.00","Scripting Commands","Take On Helicopters: Scripting Commands"]}