Jump to content

Is player in vehicle?


Recommended Posts

Hi i just want to check with "/veh name" if a player is in a vehicle. If he is, you will be told.

I don't know why my scripts don't work xD I tried various options.

  
function getVehicle( thePlayer, command, name ) 
    local vehicle = getPedOccupiedVehicle( name ) 
    if ( vehicle ) then  
        outputChatBox( name.." drives this vehicle: "..vehicle, thePlayer, 0, 0, 255 ) 
    else 
        outputChatBox( name.." isn't in a vehicle.", thePlayer, 255, 0, 0 ) 
    end 
end 
addCommandHandler( "veh", getVehicle ) 
  

Link to comment
If you read the text you can see

Name = guy i want to check if hes in a vehicle

Vehicle = vehicle name

You are totaly wrong check your code. anyways try this (untested i'm using the phone)

function getVehicle(player, command, name ) 
    if player and isElement(player) then  
        if name then  
  
            -- we get the player element from the nick specified 
            local thePlayer = getPlayerFromName(name) 
             
            -- if there exists a player with that nick 
            if (not isElement(thePlayer)) then  
                outputChatBox("This player does no longer exist!",player, 255, 0, 0) 
                return 
            end 
  
            -- if he's in a vehicle 
            if isPedInVehicle(thePlayer) then  
                local vehicle = getPedOccupiedVehicle (thePlayer) 
                outputChatBox(getPlayerName(thePlayer).." drives this vehicle: "..getVehicleName (vehicle),player, 0, 0, 255 ) 
            else 
                outputChatBox(getPlayerName(thePlayer).." isn't in a vehicle.",player, 255, 0, 0 ) 
            end  
        else 
            outputChatBox("[usage] /veh ",player, 255, 0, 0 ) 
        end 
    end  
end 
addCommandHandler("veh", getVehicle) 

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