Jump to content

Vehicle AI [SIMPLE] (SAUR RPG Like)


Subtixx

Recommended Posts

local coreveh = createVehicle(411,0,0,5) 
setVehicleDamageProof(coreveh,true) 
local coreped = createPed(252,0,0,0) 
warpPedIntoVehicle(coreped,coreveh,0) 
local blip = createBlipAttachedTo(coreveh,20) 
  
local px, py, pz = getElementPosition(getPlayerFromName("PLAYERNAME")) 
local rx, ry, rz = getElementRotation(getPlayerFromName("PLAYERNAME")) 
local abstand = 7 
local newX = px + math.cos(math.rad(rz + 90)) * abstand 
local newY = py + math.sin(math.rad(rz + 90)) * abstand 
setElementPosition(coreveh,newX,newY,pz) 
  
function botAI(player) 
    local veh = getPedOccupiedVehicle(player) 
    if veh then 
        local x,y,z = getElementVelocity(veh) 
        setElementVelocity(coreveh,x,y,z) 
         
        local rx, ry, rz = getElementRotation(veh) 
        setElementRotation(coreveh,rx,ry,rz) 
  
    else 
        local x,y,z = getElementVelocity(player) 
        setElementVelocity(coreveh,x,y,z) 
         
        local rx, ry, rz = getElementRotation(player) 
        setElementRotation(coreveh,rx,ry,rz) 
    end 
    setTimer(botAI,100,1,player) 
end 
botAI(getPlayerFromName("PLAYERNAME")) 

It's veeeeeeeeeeeeeeerryy basic... Can someone help me with the code? (driveToPosition - like function?)

Link to comment

function driveVehicle(veh, x,y,z, velocity=0.1, gpsmode=false)

check if x y and z are numbers, check veh is element

if gpsmode try and use an export using the gps resource to get the road map to drive and use velocity variable for setting velo.

if not gpsmode, or no export then just rotate veh and drive directly, which in that case probably hit a wall

end

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...