viel.kuul.10 0 Posted October 30, 2021 How to make a unit (or more units) start at a random position within a marker? I have a simple code for random select markers, but I don't have for radius, direction. this setpos (getMarkerPos (selectRandom ["marker1", "marker2"])); This code I put in a unit init. I don't like sqf. I am trying: this setpos getMarkerPos ["marker1", "marker2"] getPos [random(40), random(360). random(40) is radius. But doesn't works. Share this post Link to post Share on other sites
Harzach 2518 Posted October 30, 2021 58 minutes ago, viel.kuul.10 said: I don't like sqf. It's all .sqf. Get used to it! In unit init: nul = this spawn { _marker = (selectRandom ["marker1", "marker2"]); _pos = _marker call BIS_fnc_randomPosTrigger; _this setPos _pos; }; 2 Share this post Link to post Share on other sites
viel.kuul.10 0 Posted October 31, 2021 It works. I bow to you. I have a question: how to implant direction to this code? Random or selected? Share this post Link to post Share on other sites
Harzach 2518 Posted October 31, 2021 (edited) Random: nul = this spawn { _marker = (selectRandom ["marker1", "marker2"]); _pos = _marker call BIS_fnc_randomPosTrigger; _this setPos _pos; _dir = random 359; _this setFormDir _dir; _this setDir _dir; }; If you want a specific direction, change "random 359" to your desired heading: nul = this spawn { _marker = (selectRandom ["marker1", "marker2"]); _pos = _marker call BIS_fnc_randomPosTrigger; _this setPos _pos; _this setFormDir 175; _this setDir 175; }; Some invaluable links: The Basics - https://community.bistudio.com/wiki/SQF_Syntax https://community.bistudio.com/wiki/Introduction_to_Arma_Scripting Commands and Functions - https://community.bistudio.com/wiki/Category:Scripting_Commands https://community.bistudio.com/wiki/Category:Arma_3:_Functions Event Handlers - https://community.bistudio.com/wiki/Arma_3:_Event_Handlers https://community.bistudio.com/wiki/Arma_3:_Mission_Event_Handlers Edited November 1, 2021 by Harzach I forgot about setFormDir! 2 Share this post Link to post Share on other sites
viel.kuul.10 0 Posted October 31, 2021 Does not work. If I manually turn the soldier in the desired direction, it spawn in that direction. I am always wishful to learn scripting. Share this post Link to post Share on other sites
Harzach 2518 Posted October 31, 2021 *edit* - See @beno_83au's post, my previous reply has been fixed. Sorry! 1 Share this post Link to post Share on other sites
beno_83au 1369 Posted November 1, 2021 Being an AI, you might need to set the formation direction first: _dir = random 359; _this setFormDir _dir; _this setDir _dir; Aside from that, Harzach's example does work. 1 1 Share this post Link to post Share on other sites
Harzach 2518 Posted November 1, 2021 56 minutes ago, beno_83au said: Being an AI, you might need to set the formation direction first: Yes, I absolutely apologize, I overlooked that detail. Without first using setFormDir, units are set to the designated heading but then instantly spin around to face their original/previous heading +/- a few degrees. Thanks @beno_83au! 2 Share this post Link to post Share on other sites
viel.kuul.10 0 Posted November 1, 2021 How do that with a group, not just one AI? Along with some turret, for example: HMG? Share this post Link to post Share on other sites
Joe98 92 Posted November 1, 2021 I don't know the actual scripting but this is the sequence. Select a unit. Find a way to set the unit direction at random Find a script to read that direction. Now use that result to have the other units face that direction If you have a leader, and his direction is set at random at (say) 98, when the mission stars all the members of his team will get into formation which means they will turn and face at more or less 98. . . Share this post Link to post Share on other sites
beno_83au 1369 Posted November 2, 2021 @viel.kuul.10 You'll need to expand a bit on the code for groups, but for a turret there's no change (same as a vehicle too). Groups: Place the code in the Init field of the group leader. You'll need to account for the other AI in the group though, because the previous code will only move the leader and everyone else will have to run (potentially a long way) to get into position. Also, you need to set your random settings BEFORE going into the forEach loop, otherwise each unit will pick it's own random position/direction/etc: nul = this spawn { _marker = (selectRandom ["marker1", "marker2"]); _pos = _marker call BIS_fnc_randomPosTrigger; _dir = random 359; { _x setPos _pos; if (leader _x == _x) then { _x setFormDir _dir; }; _x setDir _dir; } forEach (units _this); }; The other units in the group will still have to run into their formation position, but it's a short run and this is a simple solution. Turrets: Place Harzach's code in the Init field of the turret itself. There's different things you could do here, like setting each unit in a group to be facing different directions or having a turret/vehicle face one direction but aim at another, and those cases are pretty easy to search for. Then you've just got to read through some forum posts and check out the command wiki and basic things like this will become pretty easy to do pretty quickly. 1 1 Share this post Link to post Share on other sites
viel.kuul.10 0 Posted November 2, 2021 Works this with a group. I gave you a trophy. Earlier I tested with a turret and a vehicle, every works with that code in the first posts. Only I would like the group to be together with the turret, not just one AI, I usually set up several more AI in the same group. To protect the turret or to replace staff if they die. I realized that any AI that is located in a turret or vehicle, spawns normally but an AI that is outside of a turret or vehicle has to run a long way to find its leader. I'm definitely still learning to scripting. Your codes can help me. I visit community.bistudio.com/wiki often to learn. Of course, I’m going to look at the other links they left here. Share this post Link to post Share on other sites