Jump to content

Give Car Script

Recommended Posts

Hey, I just wanted to program a give-car-script. Here's my code

function givevehicle1 (commandname, target, vehicleid) 
local targetp = getPlayerFromName (target) 
local x, y, z = getElementPosition ( targetp ) 
local givenvehicle = createVehicle ( vehicleid, x, y, z) 
warpPedIntoVehicle (target, givenvehicle) 
addCommandHandler ( "givevehicle1", givevehicle1 ) 

What am I doing wrong?


Link to comment
function givevehicle1 ( thePlayer, commandname, target, vehicleid ) -- You had missing the first argument. 
    local targetp = getPlayerFromName ( target ) 
    if ( targetp ) then -- If the player exists .. 
        local x, y, z = getElementPosition ( targetp ) -- Get his/her position. 
        local givenvehicle = createVehicle ( tonumber ( vehicleid ), x, y, z ) -- Attempt to create a vehicle with the given ID. 
        if ( givenvehicle ) then -- If the vehicle was created .. 
            warpPedIntoVehicle ( target, givenvehicle ) -- Warp the player to the vehicle 
addCommandHandler ( "givevehicle1", givevehicle1 ) 

Read comments.

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