natives.taskCarDriveToCoord: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{DISPLAYTITLE:natives.taskCarDriveToCoord}} {{ScriptItem |endpoint = client |games = iv |type = function |name = natives.taskCarDriveToCoord |usage = make the vehicle randomly drive around using internal game path data. |parameters = Ped ped, Vehicle vehicle, float x, float y, float z, float driveSpeed, int driveFlag, 0 (or model hash), int driveStyle, float stopDist, -1) |parameter1 = Ped ped The Ped to drive the Vehicle. |parameter2 = Vehicle vehicle The Vehicle to dr...") |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 20: | Line 20: | ||
|return1 = void | |return1 = void | ||
|returnFail1 = void | |returnFail1 = void | ||
| | |exampleJS = /* example code provided by DrFauli */ | ||
addCommandHandler("drivecoords", function(cmdName, params) { | addCommandHandler("drivecoords", function(cmdName, params) { | ||
// current vehicle/ped handle | |||
let thisVeh = null; | |||
let thisPed = null; | |||
// check if player is in a car | |||
if (!localPlayer.vehicle) { | |||
natives.requestModel(-956048545) // Taxi | |||
natives.requestModel(8772846); // Taxi Driver | |||
natives.loadAllObjectsNow(); | |||
// spawn the car | |||
thisVeh = createVehicle2(-956048545, localPlayer.position, true); | |||
thisVeh.heading = localPlayer.heading; | |||
// spawn the driver | |||
thisPed = natives.createCharInsideCar(thisVeh, 1, 8772846); | |||
// prevent ped from leaving the car screaming by marking it as mission_char first | |||
natives.setCharAsMissionChar(thisPed, true); | |||
natives.setCharStayInCarWhenJacked(thisPed, true); | |||
// warp player into passenger seat | // warp player into passenger seat | ||
natives.warpCharIntoCarAsPassenger(localPlayer, thisVeh, 0); | |||
} else { | } else { | ||
thisVeh = localPlayer.vehicle; | |||
thisPed = thisVeh.getOccupant(0); | |||
} | } | ||
// get speed and driveStyle/driveFlag from params | |||
let splitParams = params.split(" "); | |||
let stopDist = 50; | |||
let driveSpeed = Number(splitParams[0]); // default is 20 | |||
let driveStyle = Number(splitParams[1]); | |||
let driveFlag = Number(splitParams[2]); // default is 0 | |||
// let this car drive to coords (0,0,0) | |||
// [syntax]: pedHandle, carHandle, x, y, z, driveSpeed, driveFlag, (0 or model hash?), driveStyle, stop distance, unknown(-1) | |||
natives.taskCarDriveToCoord(thisPed, thisVeh, 0, 0, 0, driveSpeed, driveFlag, 0, driveStyle, stopDist, -1); | |||
return true; | |||
}); | }); | ||
}} | }} | ||
== | == Driving Flag Behavior == | ||
{|class="wikitable" | {|class="wikitable" | ||
!| | !| | ||
| Line 72: | Line 72: | ||
|- | |- | ||
|0 | |0 | ||
| | |Normal driving | ||
|used | |used | ||
|- | |- | ||
|1 | |1 | ||
| | |Get to coord as fast as possible | ||
| | |Ignored | ||
|- | |- | ||
|2 | |2 | ||
| | |Driving in Reverse | ||
| | |Used (while reversing) | ||
|- | |- | ||
|3 | |3 | ||
| | |Drive Wander (ignore coords) | ||
| | |Used | ||
|} | |} | ||
== | == Driving Style Behavior== | ||
{|class="wikitable" | {|class="wikitable" | ||
!| | !| | ||
!| | !|Traffic lights | ||
!| | !|Other cars | ||
!| | !|Pedestrians | ||
!| | !|Blinkers | ||
!| | !|When stuck | ||
|- | |- | ||
|0 | |0 | ||
| | |Ignore | ||
| | |Drive around | ||
| | |Drive around | ||
| | |Not used | ||
| | |Reverse | ||
|- | |- | ||
|1 | |1 | ||
| | |Stop on red | ||
| | |Stay behind | ||
| | |Stop and honk | ||
| | |Used on intersections | ||
| | |Wait | ||
|- | |- | ||
|2 | |2 | ||
| | |Ignore | ||
| | |Drive around | ||
| | |Drive around | ||
| | |Not used | ||
| | |Reverse | ||
|- | |- | ||
|3 | |3 | ||
| | |Ignore | ||
| | |Ignore | ||
| | |Ignore | ||
| | |Not used | ||
| | |Reverse | ||
|- | |- | ||
|4 | |4 | ||
| | |Ignore | ||
| | |Stay behind | ||
| | |Stop and honk | ||
| | |Not used | ||
| | |Wait | ||
|- | |- | ||
|5 | |5 | ||
| | |Stop on red | ||
| | |Drive around | ||
| | |Drive around | ||
| | |Not used | ||
| | |Reverse | ||
|- | |- | ||
|6 | |6 | ||
| | |Stop+reversing | ||
| | |Drive around | ||
| | |Drive around | ||
| | |Not used | ||
| | |Reverse | ||
|- | |- | ||
|7 | |7 | ||
| | |Stop on red | ||
| | |Stay behind | ||
| | |Stop and honk | ||
| | |Used on intersections | ||
| | |Wait | ||
|} | |} | ||
== | ==Notes== | ||
* | *Driving styles '''0 and 2''' seem to be identical. | ||
* | *Driving styles '''1 and 7''' seem to be identical. | ||
* | *Using values '''< 0''' or '''> 7''' will behave like '''3''' | ||
* | *The AI will slow down for corners and intersections, but won't break for "drive around" obstacles. | ||
There '''could be''' small distance and/or speed differences when "drive around" is used.<br/> | There '''could be''' small distance and/or speed differences when "drive around" is used.<br/> | ||
It is also unclear if the AI drivers are able to see objects like light poles or traffic lights while evading. | It is also unclear if the AI drivers are able to see objects like light poles or traffic lights while evading. | ||
Latest revision as of 19:15, 12 November 2025
Function Client Only ![]()
Online and Offline
Available since Client 1.0.0
void natives.taskCarDriveToCoord(Ped ped, Vehicle vehicle, float x, float y, float z, float driveSpeed, int driveFlag, 0 (or model hash), int driveStyle, float stopDist, -1))
The natives.taskCarDriveToCoord function is used to make the vehicle randomly drive around using internal game path data.
Parameters
| 1) | Ped | ped | The Ped to drive the Vehicle. |
| 2) | Vehicle | vehicle | The Vehicle to drive with. |
| 3) | float | x | The x position to drive to. |
| 4) | float | y | The y position to drive to. |
| 5) | float | z | The z position to drive to. |
| 6) | float | driveSpeed | The speed of driving in meters per second. (default = 20). |
| 7) | int | driveFlag | The AI driving behavior/flag to use. (0-4, see details below). |
| 8) | int | hash | (unknown) 0 or model hash of the vehicle used in parameter 2. |
| 9) | int | driveStyle | The AI driving style (behavior) to use. (0-7, see details below). |
| 10) | float | stopDist | Radius around the given coords. Vehicle will stop when inside radius. |
| 11) | int | unknown | (unknown) always -1. |
Return
| void | This function doesn't return a value. |
Notes
There aren't any notes for this function.
Examples
Example 1 - JavaScript:
/* example code provided by DrFauli */ addCommandHandler("drivecoords", function(cmdName, params) {
// current vehicle/ped handle let thisVeh = null; let thisPed = null;
// check if player is in a car
if (!localPlayer.vehicle) {
natives.requestModel(-956048545) // Taxi
natives.requestModel(8772846); // Taxi Driver
natives.loadAllObjectsNow();
// spawn the car
thisVeh = createVehicle2(-956048545, localPlayer.position, true);
thisVeh.heading = localPlayer.heading;
// spawn the driver
thisPed = natives.createCharInsideCar(thisVeh, 1, 8772846);
// prevent ped from leaving the car screaming by marking it as mission_char first
natives.setCharAsMissionChar(thisPed, true);
natives.setCharStayInCarWhenJacked(thisPed, true);
// warp player into passenger seat
natives.warpCharIntoCarAsPassenger(localPlayer, thisVeh, 0);
} else {
thisVeh = localPlayer.vehicle;
thisPed = thisVeh.getOccupant(0);
}
// get speed and driveStyle/driveFlag from params
let splitParams = params.split(" ");
let stopDist = 50;
let driveSpeed = Number(splitParams[0]); // default is 20
let driveStyle = Number(splitParams[1]);
let driveFlag = Number(splitParams[2]); // default is 0
// let this car drive to coords (0,0,0) // [syntax]: pedHandle, carHandle, x, y, z, driveSpeed, driveFlag, (0 or model hash?), driveStyle, stop distance, unknown(-1) natives.taskCarDriveToCoord(thisPed, thisVeh, 0, 0, 0, driveSpeed, driveFlag, 0, driveStyle, stopDist, -1); return true;
});
Compatibility
There isn't any compatibility information for this function.
Driving Flag Behavior
| behavior | parameter9 (driving style) | |
|---|---|---|
| 0 | Normal driving | used |
| 1 | Get to coord as fast as possible | Ignored |
| 2 | Driving in Reverse | Used (while reversing) |
| 3 | Drive Wander (ignore coords) | Used |
Driving Style Behavior
| Traffic lights | Other cars | Pedestrians | Blinkers | When stuck | |
|---|---|---|---|---|---|
| 0 | Ignore | Drive around | Drive around | Not used | Reverse |
| 1 | Stop on red | Stay behind | Stop and honk | Used on intersections | Wait |
| 2 | Ignore | Drive around | Drive around | Not used | Reverse |
| 3 | Ignore | Ignore | Ignore | Not used | Reverse |
| 4 | Ignore | Stay behind | Stop and honk | Not used | Wait |
| 5 | Stop on red | Drive around | Drive around | Not used | Reverse |
| 6 | Stop+reversing | Drive around | Drive around | Not used | Reverse |
| 7 | Stop on red | Stay behind | Stop and honk | Used on intersections | Wait |
Notes
- Driving styles 0 and 2 seem to be identical.
- Driving styles 1 and 7 seem to be identical.
- Using values < 0 or > 7 will behave like 3
- The AI will slow down for corners and intersections, but won't break for "drive around" obstacles.
There could be small distance and/or speed differences when "drive around" is used.
It is also unclear if the AI drivers are able to see objects like light poles or traffic lights while evading.