Karuzo

check if seat is empty and driver is driving

Recommended Posts

Hey Guys,

I need to know how i can ask if the driver is sitting in a car and the player who wants to enter the car is not going to sit in the drivers seat.

With this code i can enter the vehicle as a passenger when nobody is driving the car. But i can't enter the vehicle as a passenger if a driver is sitting in the car. Obviously it's because of the drv == false statement, how can i fix this ?

addEventHandler("onVehicleStartEnter",root, 
    function(plr) 
        local username = getElementData(plr,"username") 
        local seat = getPedOccupiedVehicleSeat(plr) 
        local drv = getVehicleOccupant(source,0) 
        local owner = getElementData(source,"Owner") 
        if owner == username then 
            outputChatBox("Press 'X' for Engine and 'L' for the Lights",plr,0,180,0,false) 
            bindKey(plr,"x","down",Engine) 
            bindKey(plr,"l","down",Light) 
        elseif seat ~= 0 and drv == false then 
            return true 
        else 
            cancelEvent() 
            outputChatBox("This is not your car! This car belongs to: "..owner.." .If you already have one use /getmycar !",plr,180,0,0,false) 
        end 
    end 
) 

Thanks.

Share this post


Link to post

onVehicleStartEnter has four function variables (as wiki says):

enteringPlayer: A player element representing the player who is starting to enter a vehicle

seat: An integer representing the seat in which the player is entering

jacked: A player element representing who is going to be jacked

door: An integer of which door the player used (0-3). 0 is driver side door, 1 is front passenger, 2 is back left, 3 is back right.

Make a check for the door, if the door = 0 then check for it if not return true.

More information:

https://wiki.multitheftauto.com/wiki/On ... StartEnter

Share this post


Link to post
onVehicleStartEnter has four function variables (as wiki says):

enteringPlayer: A player element representing the player who is starting to enter a vehicle

seat: An integer representing the seat in which the player is entering

jacked: A player element representing who is going to be jacked

door: An integer of which door the player used (0-3). 0 is driver side door, 1 is front passenger, 2 is back left, 3 is back right.

Make a check for the door, if the door = 0 then check for it if not return true.

More information:

https://wiki.multitheftauto.com/wiki/On ... StartEnter

Thanks this worked out for me.

Share this post


Link to post

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.