Client/Natives/IV/taskCarDriveWander: Difference between revisions

m
switched script example driver to civilian AI instead of localPlayer
m (added endpoint (client only))
m (switched script example driver to civilian AI instead of localPlayer)
Line 14: Line 14:
|returnFail1 = void
|returnFail1 = void
|exampleJSCS = /* example code provided by DrFauli */
|exampleJSCS = /* example code provided by DrFauli */
addCommandHandler("drivestyle", function(cmdName, params)
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(-1685021548) // sabre GT
natives.requestModel(8772846); // Taxi Driver
natives.loadAllObjectsNow();
natives.loadAllObjectsNow();


// spawn the car
// spawn the car
thisVeh = createVehicle2(-1685021548, localPlayer.position, true);
thisVeh = createVehicle2(-956048545, localPlayer.position, true);
thisVeh.heading = localPlayer.heading;
thisVeh.heading = localPlayer.heading;


// warp player into driver seat
// spawn the driver
natives.taskWarpCharIntoCarAsDriver(localPlayer, thisVeh);
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 40: 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]); // default is 1 (normal driving)
let driveStyle = Number(splitParams[1]);


// let the localPlayer drive around with this car
// let this car randomly drive around
natives.taskCarDriveWander(localPlayer, thisVeh, driveSpeed, driveStyle);
// [syntax]: pedHandle, carHandle, driveSpeed, driveStyle
natives.taskCarDriveWander(thisPed, thisVeh, driveSpeed, driveStyle);


return true;
return true;
Line 119: 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.
21

edits