Jump to content

Car doors automatically closes.


Kamtar

Recommended Posts

Hello everyone !

I script for my french server but i have a little problem.

I want that if a player enter on vehicle, all doors whether automatically closes.

I have a bases, but i'm not very good on lua..

So, if u can say me a solution, thanks :)

 

  
function enterVehicle ( player, seat, jacked ) 
    local vehicle = getPedOccupiedVehicle ( player ) 
    if vehicle then 
        for i=0,5 do 
            setVehicleDoorOpenRatio ( vehicle, i, 0 - getVehicleDoorOpenRatio ( vehicle, i ), 2500 ) 
        end 
    end 
end 
  

Edited by Guest
Link to comment

--- ServerSide

addEventHandler ( 'onVehicleEnter', resourceRoot, 
function ( player ) 
 local nVehicle = getPedOccupiedVehicle ( player ) 
    if ( nVehicle ) then 
    setVehicleLocked ( nVehicle, true ) 
    outputChatBox ( ' Vehilce is Locked', player, 255, 255, 0 ) 
 end 
end 
) 
Edited by Guest
Link to comment

 

  
addEventHandler ( 'onVehicleEnter', resourceRoot, 
function enterVehicle ( player ) 
    local vehicle = getPedOccupiedVehicle ( player ) 
    if vehicle then 
        for i=0,5 do 
            setVehicleDoorOpenRatio ( vehicle, i, 0, 2500 ) 
        end 
    end 
end 
) 

Link to comment

My bad Max, i just want all door is close, no lock. I have a script for lock, but i have a bug in my server:

If player enter on car, the door right is automatically open.

So i want, if player enter on car, all doors automatically close.

Link to comment

Well , i tryed to make it work with the vehicles event from server / client but it didn't i think it's some kind of bug ,

but it worked with command

type Max to open it , type max again to close it , you can add check if the doors open then close else / open

--ClientSide

addCommandHandler ( 'Max',  
function ( ) 
    local vehicle = getPedOccupiedVehicle ( localPlayer ) 
    if vehicle then 
        for i=0,5 do 
            setVehicleDoorOpenRatio ( vehicle, i, 1 - getVehicleDoorOpenRatio ( vehicle, i ), 2500 ) 
        end 
    end 
end ) 

or you cant try using

addEvent('Something'), true ) 
addEventHandler('Something', root, 
function ( ) 
    local vehicle = getPedOccupiedVehicle ( localPlayer ) 
    if vehicle then 
        for i=0,5 do 
            setVehicleDoorOpenRatio ( vehicle, i, 1 - getVehicleDoorOpenRatio ( vehicle, i ), 2500 ) 
        end 
    end 
end ) 
  

and

setTimer  

to trigger it

triggerClientEvent ( 'Something', source, 'Somthing' )  
Link to comment

-- # Server Side ! 
addEventHandler ( "onVehicleEnter", root, function ( ) 
        setTimer ( function ( vehicle ) 
                for i = 0, 5 do 
                        setVehicleDoorOpenRatio ( vehicle, i, 0 - getVehicleDoorOpenRatio ( vehicle, i ), 2500 ) 
                end 
        end, 250, 1, source ) 
end ) 
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...