QuiveringT 11 Posted February 9, 2018 (edited) I have written a script called carPatrol.sqf which is supposed to select a random 6 point patrol route out of 6 possible locations. At each location, there is a move waypoint and a dismount waypoint in which the infantry dismount their vehicle and hang out for a bit before jumping back in their vehicle and proceeding to the next location. I have written code which randomizes the possible locations, and then includes a function which assigns the waypoints per location to the group. This is where it gets interesting. Everything works as intended: except the group gets the cycle waypoint after 3 locations instead of 6. How do I get the group to get the cycle waypoint after 6 locations instead of 3? Spoiler waypoint1 = ["carstop1","dismountwp1"]; waypoint2 = ["carstop2","dismountwp2"]; waypoint3 = ["carstop3","dismountwp3"]; waypoint4 = ["carstop4","dismountwp4"]; waypoint5 = ["carstop5","dismountwp5"]; waypoint6 = ["carstop6","dismountwp6"]; waypointsTotal = [waypoint1,waypoint2,waypoint3,waypoint4,waypoint5,waypoint6]; assignWps = { _selection = selectRandom waypointsTotal; waypointsTotal = waypointsTotal-_selection; _parameterOne = _selection select 0; _parameterTwo = _selection select 1; _wp = carPatrol addWaypoint [getMarkerPos _parameterOne,0]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn false"]; _wp = carPatrol addWaypoint [getMarkerPos _parameterTwo,0]; _wp setWaypointTimeout[5,10,15]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn true"]; if (count waypointsTotal == 0) then { _wp = carPatrol addWaypoint [getMarkerPos _parameterTwo,0]; _wp setWaypointType "CYLCE"; } ; } ; call assignWps; call assignWps; call assignWps; call assignWps; call assignWps; call assignWps; Additional details: To replicate my exact scenario, name one unit carPatrolLeader, another carPatrolDude, assign their group to carPatrol, assign one as Driver, and the other as Cargo. Also create markers for each one of the values listed at the beginning of the script, with each carstop and dismount pair being close together. This script is called from the init.sqf. Edited February 9, 2018 by QuiveringT Clarity Share this post Link to post Share on other sites
QuiveringT 11 Posted February 9, 2018 (edited) Update: I just tested this same code except in a non nice-looking version (i.e. all code executed outside of a function but 6x the code) and it still hangs up after the 3rd set of waypoints (6 total including drive there and dismounts). At this point I'm pointing to some kind of engine problem that is disallowing me to continue, because I cannot see how this code will not work for the remaining three times. It is quite literally, the same code. Code for reference: Spoiler _waypoint1 = ["carstop1","dismountwp1"]; _waypoint2 = ["carstop2","dismountwp2"]; _waypoint3 = ["carstop3","dismountwp3"]; _waypoint4 = ["carstop4","dismountwp4"]; _waypoint5 = ["carstop5","dismountwp5"]; _waypoint6 = ["carstop6","dismountwp6"]; _waypointsTotal = [_waypoint1,_waypoint2,_waypoint3,_waypoint4,_waypoint5,_waypoint6]; //First _selection = selectRandom _waypointsTotal; _waypointsTotal = _waypointsTotal-_selection; _parameterOne = _selection select 0; _parameterTwo = _selection select 1; _wp = carPatrol addWaypoint [getMarkerPos _parameterOne,0]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn false"]; _wp = carPatrol addWaypoint [getMarkerPos _parameterTwo,0]; _wp setWaypointTimeout[5,10,15]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn true"]; //Second _selection = selectRandom _waypointsTotal; _waypointsTotal = _waypointsTotal-_selection; _parameterOne = _selection select 0; _parameterTwo = _selection select 1; _wp = carPatrol addWaypoint [getMarkerPos _parameterOne,0]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn false"]; _wp = carPatrol addWaypoint [getMarkerPos _parameterTwo,0]; _wp setWaypointTimeout[5,10,15]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn true"]; //Third _selection = selectRandom _waypointsTotal; _waypointsTotal = _waypointsTotal-_selection; _parameterOne = _selection select 0; _parameterTwo = _selection select 1; _wp = carPatrol addWaypoint [getMarkerPos _parameterOne,0]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn false"]; _wp = carPatrol addWaypoint [getMarkerPos _parameterTwo,0]; _wp setWaypointTimeout[5,10,15]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn true"]; //Fourth _selection = selectRandom _waypointsTotal; _waypointsTotal = _waypointsTotal-_selection; _parameterOne = _selection select 0; _parameterTwo = _selection select 1; _wp = carPatrol addWaypoint [getMarkerPos _parameterOne,0]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn false"]; _wp = carPatrol addWaypoint [getMarkerPos _parameterTwo,0]; _wp setWaypointTimeout[5,10,15]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn true"]; //Fifth _selection = selectRandom _waypointsTotal; _waypointsTotal = _waypointsTotal-_selection; _parameterOne = _selection select 0; _parameterTwo = _selection select 1; _wp = carPatrol addWaypoint [getMarkerPos _parameterOne,0]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn false"]; _wp = carPatrol addWaypoint [getMarkerPos _parameterTwo,0]; _wp setWaypointTimeout[5,10,15]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn true"]; //Sixth _selection = selectRandom _waypointsTotal; _waypointsTotal = _waypointsTotal-_selection; _parameterOne = _selection select 0; _parameterTwo = _selection select 1; _wp = carPatrol addWaypoint [getMarkerPos _parameterOne,0]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn false"]; _wp = carPatrol addWaypoint [getMarkerPos _parameterTwo,0]; _wp setWaypointTimeout[5,10,15]; _wp setWaypointStatements ["true","[carPatrolLeader, carPatrolDude] orderGetIn true"]; _wp = carPatrol addWaypoint [getMarkerPos _parameterTwo,0]; _wp setWaypointType "CYCLE"; Further update: I just removed the cycle section of the code and the motorized patrol returns to a previous waypoint after the 3rd waypoint, and then stops entirely, staying in their vehicle. Edited February 9, 2018 by QuiveringT New update, didnt want to triple post Share this post Link to post Share on other sites
Grumpy Old Man 3549 Posted February 9, 2018 Didn't go through your examples in detail but from what I'm guessing, you randomly pick 3 out of 6, without removing the picked locations from the locations to choose from, that way it's very likely to end up with picking the same location multiple times: _test = ["Apples","Bananas","Oranges","Tomatoes","Potatoes","Phil"]; _result = []; for "_i" from 1 to 3 do {_result pushBack (selectRandom _test)}; systemchat str _result; copyToClipboard str _result; //stuff like this WILL happen: ["Apples","Apples","Apples"] Here's a simple snippet that makes a group move through all markers, either in order or randomized, the last waypoint will execute that function with same input parameters again to randomize all waypoints again and get a different outcome every time the group has completed all previous waypoints: GOM_fnc_patrolWaypoints = { params ["_group","_waypoints","_randomWPs"]; //save input as variable on group for later use _group setVariable ["GOM_fnc_patrolParams",_this,true]; if (_randomWPs) then {_waypoints = _waypoints call BIS_fnc_arrayShuffle}; _wp = []; { _wp = _group addWaypoint [getMarkerPos _x,0]; _wp setWaypointStatements ["true",format ["this globalChat 'Arrived at patrol marker %1'",_x]]; } forEach _waypoints; //grab last added WP and add the function so the patrol repeats _wp setWaypointStatements ["true",format ["this globalChat 'Arrived at patrol marker %1';this globalChat 'Patrol finished, starting over!';_loop = (group this getVariable 'GOM_fnc_patrolParams') call GOM_fnc_patrolWaypoints",_x]]; }; _group = patrolGroup; _markers = ["patrolMarker1","patrolMarker2","patrolMarker3","patrolMarker4","patrolMarker5","patrolMarker6"]; _randomizeWPs = true; _test = [patrolGroup,_markers,_randomizeWPs] call GOM_fnc_patrolWaypoints; Cheers 1 Share this post Link to post Share on other sites
QuiveringT 11 Posted February 9, 2018 Thanks for the reply @Grumpy Old Man, but as the title states, I am looking for something a little more specific than that. I want the patrol route to be randomized once, not every time the patrol starts over. In addition, all 6 waypoints must be included. There are also additional waypoints and functionality I need assigned (as stated in master post) - although by looking at your code, it should be possibly to easily add that in. Yet another question remains: Why does my code work, but only for the first three waypoints assigned? I mean, that shit's god damn beautiful, if I may say so myself. Share this post Link to post Share on other sites