Rosso777 22 Posted February 23, 2021 I am trying to modify a script that spawn an AI assistant. The original code spawns the AI directly on your position, but I want the AI to spawn about 200 meters from the current player position. Here is the original line: _unit = group player createUnit [_unitList select (round(random ((count _unitList) - 1))), getPos player, [], 0, "FORM"]; Here was my version that did not work: _unit = group player createUnit [_unitList select (round(random ((count _unitList) - 1))), [getPos player + 200], [], 0, "FORM"]; I've tried digging around the BIKI but there wasn't much available on the getPos page. I also found this, but not sure if it's a completely different aspect: ((getPos player) vectorAdd [((random 400)-200),((random 400)-200),0]) Can anyone offer some insight? Share this post Link to post Share on other sites
pierremgi 4634 Posted February 23, 2021 forget [getpos player + 200] for: player getPos [200,getDir player] or even : player getPos [100 + random 100, random 360] by the way: _unitList select (round(random ((count _unitList) - 1))) selectRandom _unitList 1 Share this post Link to post Share on other sites
Rosso777 22 Posted February 23, 2021 2 hours ago, pierremgi said: player getPos [100 + random 100, random 360] Thanks for your help, Pierre, I tested it and it works like a charm. 2 hours ago, pierremgi said: by the way: selectRandom _unitList Is this for the script to randomize the AI that it spawns? 1 Share this post Link to post Share on other sites
pierremgi 4634 Posted February 24, 2021 selectRandom is able to select an element of an array at random. _unitList must be an array of existing classes (strings) of units. So same thing as your code, but clearer. See also selectRandomWeighted is you want to spawn more units of some types than others. 2 1 Share this post Link to post Share on other sites
Rosso777 22 Posted February 24, 2021 7 hours ago, pierremgi said: selectRandom is able to select an element of an array at random. _unitList must be an array of existing classes (strings) of units. So same thing as your code, but clearer. See also selectRandomWeighted is you want to spawn more units of some types than others. Understood. I will give this a go and post my results as to help future similar issues. Thanks! 1 Share this post Link to post Share on other sites
AZCoder 919 Posted February 24, 2021 12 hours ago, pierremgi said: See also selectRandomWeighted is you want to spawn more units of some types than others. I needed this command for something else. Thanks! Over a decade in SQF and still learning commands.... 2 Share this post Link to post Share on other sites