{"name":"deleteWaypoint","operator":null,"title":"deleteWaypoint","type":"command","url":"https://community.bistudio.com/wiki/deleteWaypoint","revid":339202,"updated":"2023-04-27T17:09:15Z","groups":["Waypoints"],"status":"ok","replaced_by":[],"games":[{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"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":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":"global","effect":"global","server_exec":false},"exec":null,"description":"Removes the specified waypoint.\n\n> [!NOTE]\n> - When a waypoint is deleted, all other group waypoints are immediately re-indexed. See #Example 2 for a deletion of all group's waypoints.\n> - Deleting a group's current waypoint will *not* stop the group on its tracks.","syntaxes":[{"syntax":"deleteWaypoint [group, index]","since":null,"effect":null,"exec":null,"params":[{"name":"group","type":"Group","optional":false,"default":null,"description":null,"types":["Group"],"since":null,"text":"group: Group"},{"name":"index","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"index: Number"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"unary","operator":null,"left":null,"right":{"text":"[group, index]","types":["Array"]}}],"examples":[{"text":"```sqf\ndeleteWaypoint [_grp, 2];\n```","code":["deleteWaypoint [_grp, 2];"]},{"text":"Because waypoints get immediately re-indexed when one gets deleted, delete them from last to first:\n\n```sqf\nprivate _group = group _unit;\nfor \"_i\" from (count waypoints _group - 1) to 0 step -1 do\n{\n    deleteWaypoint [_group, _i];\n};\n```\n\nor always delete the first one (if you want to delete them all)\n\n```sqf\nprivate _group = group _unit;\nfor \"_i\" from 0 to (count waypoints _group - 1) do\n{\n    deleteWaypoint [_group, 0];\n};\n```\n\nor use forEachReversed:\n\n```sqf\n{ deleteWaypoint _x } forEachReversed waypoints _group; // Arma 3 v2.14+ only\n```","code":["private _group = group _unit;\nfor \"_i\" from (count waypoints _group - 1) to 0 step -1 do\n{\n\tdeleteWaypoint [_group, _i];\n};","private _group = group _unit;\nfor \"_i\" from 0 to (count waypoints _group - 1) do\n{\n\tdeleteWaypoint [_group, 0];\n};","{ deleteWaypoint _x } forEachReversed waypoints _group; // Arma 3 v2.14+ only"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["waypoints","setCurrentWaypoint","setWaypointPosition","setWaypointScript","setWaypointStatements","setWaypointType","addWaypoint"],"notes":[{"user":"Saintolaf","date":"2008-01-01T07:48:00Z","text":"In order to change the behavior of a unit currently following some waypoints, it is not enough to use deleteWaypoint.\nTo achieve the wanted effect, you should rather use setWPPos to the unit's current position (thereby stopping the unit), and (after a small delay) use deleteWaypoint to remove the next waypoints."},{"user":"VictorFarbau","date":"2008-11-15T13:37:00Z","text":"Another (more foolproof) method to avoid the problem of non-deleteable waypoints is to introduce another group (createGroup) and join all units of the present group. A new group will start without any preset waypoints so you can start setting new WPs all over again.\nOld group is \"_combatGroup\", new group is \"_combatGroup2\"\n\n```sqf\n_combatGroup2 = createGroup east;\n{ [_x] joinSilent _combatGroup2 } forEach (units _combatGroup);\n_combatGroup2 addWaypoint [getPos player, 25];\n```"},{"user":"Mr H.","date":"2019-11-17T16:52:00Z","text":"To have the unit stop on the spot you need to set its current waypoint where it is and add a little delay, as stated above by Saintolaf so:\n\n```sqf\ngroup _unit spawn\n{\n    [_this, currentWaypoint _this] setWaypointPosition [getPosASL ((units _this) select 0), -1];\n    sleep 0.1;\n    for \"_i\" from count waypoints _this - 1 to 0 step -1 do \n    {\n        deleteWaypoint [_this, _i];\n    };\n};\n```\n\nWill stop the group where it is and delete its waypoints."}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Waypoints","Introduced with Operation Flashpoint: Elite version 1.00","Operation Flashpoint: Elite: New Scripting Commands","Operation Flashpoint: Elite: Scripting Commands","Scripting Commands","Scripting Commands: Global Effect","Take On Helicopters: Scripting Commands"]}