Jump to content

Vehicle AI [SIMPLE] (SAUR RPG Like)


Subtixx

Recommended Posts

Posted
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?)

Posted

It's my code -.-. But it's very basic, and i want to have a function like driveToPosition. SAUR RPG Intro like.

(No code. but Ideas.)

  • MTA Team
Posted

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

Posted
I want an example of how to realize a function driveToCoordinate.

you can make a table with the coordinates. if I understand well

Or an idea how to follow a boat to a player

i not understand

Posted

i want to make a function, like driveToCoordinate. do you know the Intro from SAUR RPG? (it's a Bot with ped that follows the player). Thats it.

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...