Client/Natives/IV/taskCarDriveWander: Difference between revisions
(used template for formatting) |
No edit summary |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:natives.taskCarDriveWander}} | {{DISPLAYTITLE:natives.taskCarDriveWander}} | ||
{{ScriptItem | {{ScriptItem | ||
|endpoint = client | |||
|games = iv | |games = iv | ||
|type = function | |type = function | ||
Line 13: | Line 14: | ||
|returnFail1 = void | |returnFail1 = void | ||
|exampleJSCS = /* example code provided by DrFauli */ | |exampleJSCS = /* example code provided by DrFauli */ | ||
addCommandHandler(" | addCommandHandler("drivewander", function(cmdName, params) { | ||
{ | // current vehicle/ped handle | ||
// current vehicle handle | |||
let thisVeh = null; | let thisVeh = null; | ||
let thisPed = null; | |||
// check if player is in a car | // check if player is in a car | ||
if (!localPlayer.vehicle) | if (!localPlayer.vehicle) { | ||
natives.requestModel(-956048545) // Taxi | |||
natives.requestModel(- | natives.requestModel(8772846); // Taxi Driver | ||
natives.loadAllObjectsNow(); | natives.loadAllObjectsNow(); | ||
// spawn the car | // spawn the car | ||
thisVeh = createVehicle2(- | thisVeh = createVehicle2(-956048545, localPlayer.position, true); | ||
thisVeh.heading = localPlayer.heading; | thisVeh.heading = localPlayer.heading; | ||
// warp player into driver | // spawn the driver | ||
natives. | 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 id 0 (next to driver) | |||
natives.warpCharIntoCarAsPassenger(localPlayer, thisVeh, 0); | |||
} | } | ||
else | else { | ||
thisVeh = localPlayer.vehicle; | thisVeh = localPlayer.vehicle; | ||
thisPed = thisVeh.getOccupant(0); | |||
} | } | ||
Line 39: | Line 47: | ||
let splitParams = params.split(" "); | let splitParams = params.split(" "); | ||
let driveSpeed = Number(splitParams[0]); // default is 20 | let driveSpeed = Number(splitParams[0]); // default is 20 | ||
let driveStyle = Number(splitParams[1]); | let driveStyle = Number(splitParams[1]); | ||
// let | // let this car randomly drive around | ||
natives.taskCarDriveWander( | // [syntax]: pedHandle, carHandle, driveSpeed, driveStyle | ||
natives.taskCarDriveWander(thisPed, thisVeh, driveSpeed, driveStyle); | |||
return true; | return true; | ||
Line 118: | Line 127: | ||
*driving styles '''1 and 7''' seem to be identical. | *driving styles '''1 and 7''' seem to be identical. | ||
*using values '''< 0''' or '''> 7''' will behave like '''3''' | *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. | ||
The [[vehicle.carWanderRandomly|vehicle.carWanderRandomly]] function has the same functionality in the 3D universe games (GTA III, Vice City, and San Andreas). The extra driving parameters for those games can be set with [[vehicle.setDrivingStyle|vehicle.setDrivingStyle]] and [[vehicle.setCarCruiseSpeed|vehicle.setCarCruiseSpeed]] |
Latest revision as of 12:42, 8 August 2021
Function
Client Only
Online and Offline
void natives.taskCarDriveWander(Ped ped, Vehicle vehicle, float driveSpeed, int driveStyle)
Parameters
1) | Ped | ped | The Ped to drive the Vehicle. |
2) | Vehicle | vehicle | The Vehicle to drive with. |
3) | float | driveSpeed | The speed of driving in meters per second. (default = 20). |
4) | int | driveStyle | The AI driving style (behavior) to use. (0-7, see details below). |
Return
void | This function doesn't return a value. |
Notes
There aren't any notes for this function.
Examples
Example 1 - JavaScript - Client-Side:
/* example code provided by DrFauli */ addCommandHandler("drivewander", 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 id 0 (next to driver) natives.warpCharIntoCarAsPassenger(localPlayer, thisVeh, 0); } else { thisVeh = localPlayer.vehicle; thisPed = thisVeh.getOccupant(0); }
// get speed and driveStyle from params let splitParams = params.split(" "); let driveSpeed = Number(splitParams[0]); // default is 20 let driveStyle = Number(splitParams[1]);
// let this car randomly drive around // [syntax]: pedHandle, carHandle, driveSpeed, driveStyle natives.taskCarDriveWander(thisPed, thisVeh, driveSpeed, driveStyle);
return true; });
Compatibility
There isn't any compatibility information for this function.
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.
The vehicle.carWanderRandomly function has the same functionality in the 3D universe games (GTA III, Vice City, and San Andreas). The extra driving parameters for those games can be set with vehicle.setDrivingStyle and vehicle.setCarCruiseSpeed