Jump to content

Setting players seat in vehicle


sadasdas

Recommended Posts

Ok so I'm trying to make it so when the user jumps in a car if there is a driver loop through all other seats to see if there is a seat available if it is get in to that seat and not actually jack the car.

Heres what I was thinking of doing but I noticed warpplayer is now being made redundant and couldn't find a similar command. Any ideas?

Thanks,

Carl

function enterVehicle (  vehicle, seat, jacked ) --when a player enters a vehicle 
        local occupants = getVehicleOccupants(vehicle) -- Get all vehicle occupants 
        local seats = getVehicleMaxPassengers(vehicle) -- Get the amount of passenger seats 
         
        for seat = 0, seats do 
            local occupant = occupants[seat] 
             
            if occupant and getElementType(occupant)=="player" then -- If the seat is occupied by a player... 
                occupant = getPlayerName(occupant) -- ... get his name 
                outputConsole("Seat "..seat..": "..occupant,player) -- Print who's in the seat 
            else 
                warpPlayerIntoVehicle ( source, vehicle, seat) 
            end 
        end 
end 

addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle )

Link to comment

I not understand what you mean.

Explain better.

Try

function enterVehicle (  vehicle, seat, jacked ) --when a player enters a vehicle 
    local occupants = getVehicleOccupants( vehicle ) -- Get all vehicle occupants 
    local seats = getVehicleMaxPassengers( vehicle ) -- Get the amount of passenger seats 
         
    for seat = 0, seats do 
        local occupant = occupants[ seat ] 
            
        if occupant and getElementType( occupant ) == "player" then -- If the seat is occupied by a player... 
            outputConsole("Seat "..tostring( seat )..": "..getPlayerName( occupant ),source ) -- Print who's in the seat 
        else 
            warpPedIntoVehicle ( source, vehicle, seat ) 
        end 
    end 
end 
addEventHandler ( "onPlayerVehicleEnter", root, enterVehicle ) 

Link to comment

u can use warpPedIntoVehicle still :)

i would think ul need to use onVehicleStartEnter since this is triggered before the player even enters it...

u can do ur checks here too, then if all requirements are not met, u can cancel the event, or if all are ok,

u can warp him into the seat u need.

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