Client/Natives/IV/taskCarDriveWander: Difference between revisions

no edit summary
(Created page with "{{DISPLAYTITLE:natives.taskCarDriveWander}} void natives.taskCarDriveWander(Ped ped, Vehicle veh, float driveSpeed, int driveStyle) ==parameters== *parameter1 = The Ped to d...")
 
No edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:natives.taskCarDriveWander}}
{{DISPLAYTITLE:natives.taskCarDriveWander}}
void natives.taskCarDriveWander(Ped ped, Vehicle veh, float driveSpeed, int driveStyle)
{{ScriptItem
|endpoint = client
|games = iv
|type = function
|name = natives.taskCarDriveWander
|usage = make the vehicle randomly drive around using internal game path data.
|parameters = Ped ped, Vehicle vehicle, float driveSpeed, int driveStyle
|parameter1 = Ped ped The Ped to drive the Vehicle.
|parameter2 = Vehicle vehicle The Vehicle to drive with.
|parameter3 = float driveSpeed The speed of driving in meters per second. '''(default = 20)'''
|parameter4 = int driveStyle The AI driving style (behavior) to use. (0-7, ''see details below'')
|return1 = void
|returnFail1 = void
|exampleJSCS = /* 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;


==parameters==
// spawn the driver
*parameter1 = The Ped to drive the Vehicle.
thisPed = natives.createCharInsideCar(thisVeh, 1, 8772846);
*parameter2 = The Vehicle to drive with.
*parameter3 = The speed of driving in meters per second. '''(default = 20)'''
*parameter4 = The AI driving style (behavior) to use. (0-7)


==used for==
// prevent ped from leaving the car screaming by marking it as mission_char first
Make the vehicle randomly drive around using internal game path data.
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;
});
}}


==driving style behavior==
==driving style behavior==
Line 31: Line 77:
|stay behind
|stay behind
|stop and honk
|stop and honk
|used on crossings
|used on intersections
|wait
|wait
|-
|-
Line 73: Line 119:
|stay behind
|stay behind
|stop and honk
|stop and honk
|used on crossings
|used on intersections
|wait
|wait
|}
|}
Line 81: 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 light poles (objects) while evading.
It is also unclear if the AI drivers are able to see objects like light poles or traffic lights while evading.


==example code (javascript)==
<nowiki>/* example code provided by DrFauli */
addCommandHandler("drivestyle", 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(-1685021548) // sabre GT
natives.requestModel(1424670436); // french tom
natives.loadAllObjectsNow();
// spawn the car
thisVeh = createVehicle2(-1685021548, localPlayer.position, true);
thisVeh.heading = localPlayer.heading;
// spawn the driver
thisPed = natives.createCharInsideCar(thisVeh, 1, 1424670436);
// 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
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]]
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]) || 20); // default is 20
let driveStyle = (Number(splitParams[1]) || 2);
 
// let this car drive around
natives.taskCarDriveWander(thisPed, thisVeh, driveSpeed, driveStyle);
 
return true;
});</nowiki>
2,591

edits