natives.taskCarDriveToCoord: Difference between revisions

Jump to navigation Jump to search
no edit summary
(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
Line 20: Line 20:
|return1 = void
|return1 = void
|returnFail1 = void
|returnFail1 = void
|exampleJSCS = /* example code provided by DrFauli */
|exampleJS = /* example code provided by DrFauli */
addCommandHandler("drivecoords", function(cmdName, params) {
addCommandHandler("drivecoords", function(cmdName, params) {
// current vehicle/ped handle
    // current vehicle/ped handle
let thisVeh = null;
    let thisVeh = null;
let thisPed = 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(-956048545) // Taxi
natives.requestModel(8772846); // Taxi Driver
        natives.requestModel(8772846); // Taxi Driver
natives.loadAllObjectsNow();
        natives.loadAllObjectsNow();


// spawn the car
        // spawn the car
thisVeh = createVehicle2(-956048545, localPlayer.position, true);
        thisVeh = createVehicle2(-956048545, localPlayer.position, true);
thisVeh.heading = localPlayer.heading;
        thisVeh.heading = localPlayer.heading;
 
       
// spawn the driver
        // spawn the driver
thisPed = natives.createCharInsideCar(thisVeh, 1, 8772846);
thisPed = natives.createCharInsideCar(thisVeh, 1, 8772846);


// prevent ped from leaving the car screaming by marking it as mission_char first
// prevent ped from leaving the car screaming by marking it as mission_char first
natives.setCharAsMissionChar(thisPed, true);
        natives.setCharAsMissionChar(thisPed, true);
natives.setCharStayInCarWhenJacked(thisPed, true);
        natives.setCharStayInCarWhenJacked(thisPed, true);


// warp player into passenger seat
// warp player into passenger seat
natives.warpCharIntoCarAsPassenger(localPlayer, thisVeh, 0);
        natives.warpCharIntoCarAsPassenger(localPlayer, thisVeh, 0);
} else {
} else {
thisVeh = localPlayer.vehicle;
        thisVeh = localPlayer.vehicle;
thisPed = thisVeh.getOccupant(0);
        thisPed = thisVeh.getOccupant(0);
}
}


// get speed and driveStyle/driveFlag from params
    // get speed and driveStyle/driveFlag from params
let splitParams = params.split(" ");
    let splitParams = params.split(" ");
let stopDist = 50;
    let stopDist = 50;
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 driveFlag  = Number(splitParams[2]); // default is 0
    let driveFlag  = Number(splitParams[2]); // default is 0


// let this car drive to coords (0,0,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)
    // [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);
    natives.taskCarDriveToCoord(thisPed, thisVeh, 0, 0, 0, driveSpeed, driveFlag, 0, driveStyle, stopDist, -1);
 
   
return true;
    return true;
});
});
}}
}}


== driving flag behavior ==
== Driving Flag Behavior ==
{|class="wikitable"
{|class="wikitable"
!|
!|
Line 72: Line 72:
|-
|-
|0
|0
|normal driving
|Normal driving
|used  
|used  
|-
|-
|1
|1
|get to coord as fast as possible
|Get to coord as fast as possible
|ignored
|Ignored
|-
|-
|2
|2
|driving in reverse
|Driving in Reverse
|used (while reversing)
|Used (while reversing)
|-
|-
|3
|3
|drive wander (ignore coords)
|Drive Wander (ignore coords)
|used
|Used
|}
|}


==driving style behavior==
== Driving Style Behavior==
{|class="wikitable"
{|class="wikitable"
!|
!|
!|traffic lights
!|Traffic lights
!|other cars
!|Other cars
!|pedestrians
!|Pedestrians
!|blinkers
!|Blinkers
!|when stuck
!|When stuck
|-
|-
|0
|0
|ignore
|Ignore
|drive around
|Drive around
|drive around
|Drive around
|not used
|Not used
|reverse
|Reverse
|-
|-
|1
|1
|stop on red
|Stop on red
|stay behind
|Stay behind
|stop and honk
|Stop and honk
|used on intersections
|Used on intersections
|wait
|Wait
|-
|-
|2
|2
|ignore
|Ignore
|drive around
|Drive around
|drive around
|Drive around
|not used
|Not used
|reverse
|Reverse
|-
|-
|3
|3
|ignore
|Ignore
|ignore
|Ignore
|ignore
|Ignore
|not used
|Not used
|reverse
|Reverse
|-
|-
|4
|4
|ignore
|Ignore
|stay behind
|Stay behind
|stop and honk
|Stop and honk
|not used
|Not used
|wait
|Wait
|-
|-
|5
|5
|stop on red
|Stop on red
|drive around
|Drive around
|drive around
|Drive around
|not used
|Not used
|reverse
|Reverse
|-
|-
|6
|6
|stop+reversing
|Stop+reversing
|drive around
|Drive around
|drive around
|Drive around
|not used
|Not used
|reverse
|Reverse
|-
|-
|7
|7
|stop on red
|Stop on red
|stay behind
|Stay behind
|stop and honk
|Stop and honk
|used on intersections
|Used on intersections
|wait
|Wait
|}
|}


==notes==
==notes==
*driving styles '''0 and 2''' seem to be identical.
*Driving styles '''0 and 2''' seem to be identical.
*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.
*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.
2,793

edits

Navigation menu