Jump to content

Closing vehicles, what's wrong?


Luszeq

Recommended Posts

Hi, i write command to lock and unlock vehicle, but it's not work.

*I want to open vehicle automatical when i exiting, but its not work. When someone on map exit himself veh it unlock my car.

*/lock not work. When i locked my vehicle everybody can enter it.

It's on client side in freeroam map.

--------------------------- 
-- lock vehicle 
--------------------------- 
function lockcar() 
    local pojazd = getPedOccupiedVehicle(g_Me) 
    if pojazd then 
        if isVehicleLocked (pojazd) then  
                outputChatBox("Pojazd jest już zamknięty!") -- "Car is locked!" 
        else 
                outputChatBox("Pojazd został zamknięty.") 
                setVehicleLocked (pojazd, true ) 
        end 
    end 
end 
  
addCommandHandler('lock', lockcar) 
  
--------------------------- 
-- unlock vehicle 
--------------------------- 
function unlockcar() 
    local pojazd = getPedOccupiedVehicle(g_Me) 
    if pojazd then 
        if isVehicleLocked (pojazd) then  
                outputChatBox("Pojazd został otworzony.") 
                setVehicleLocked (pojazd, false ) 
        else 
                outputChatBox("Pojazd jest już otoworzny!") -- "car is opened!" 
        end 
    end 
end 
  
addCommandHandler('unlock', unlockcar) 
  
--------------------------- 
-- auto unlock vehicle 
--------------------------- 
  
addEventHandler("onClientVehicleStartExit", g_Root,  
function() 
    local pojazd = getPedOccupiedVehicle(g_Me)  
    if isVehicleLocked (pojazd) then  -- When player want to exit locked car it's been opened.  
            outputChatBox("Pojazd został otowrzony.") 
            setVehicleLocked (pojazd, false ) 
    end 
end 
) 

Link to comment
--------------------------- 
-- lock vehicle 
--------------------------- 
function lockcar() 
    local pojazd = getPedOccupiedVehicle(localPlayer) 
    if pojazd then 
        if isVehicleLocked (pojazd) then 
                outputChatBox("Pojazd jest już zamknięty!") -- "Car is locked!" 
        else 
                outputChatBox("Pojazd został zamknięty.") 
                setVehicleLocked (pojazd, true ) 
        end 
    end 
end 
  
addCommandHandler('lock', lockcar) 
  
--------------------------- 
-- unlock vehicle 
--------------------------- 
function unlockcar() 
    local pojazd = getPedOccupiedVehicle(localPlayer) 
    if pojazd then 
        if isVehicleLocked (pojazd) then 
                outputChatBox("Pojazd został otworzony.") 
                setVehicleLocked (pojazd, false ) 
        else 
                outputChatBox("Pojazd jest już otoworzny!") -- "car is opened!" 
        end 
    end 
end 
  
addCommandHandler('unlock', unlockcar) 
  
--------------------------- 
-- auto unlock vehicle 
--------------------------- 
  
addEventHandler("onClientVehicleStartExit", g_Root, 
function() 
    local pojazd = getPedOccupiedVehicle(localPlayer) 
    if isVehicleLocked (pojazd) then  -- When player want to exit locked car it's been opened. 
            outputChatBox("Pojazd został otowrzony.") 
            setVehicleLocked (pojazd, false ) 
    end 
end 
) 

Link to comment

It's still not work.

If on server is two players (me and someone("smn")), and i close car "smn" can still get in. Cars is closed only on my side.

This same problem applies to automatical unlock. When i close car and someone get otu of any car i see "You car has been unlocked.".

Link to comment

Did you put

g_Me = getLocalPlayer() 

at the top?

try this:

g_Me = getLocalPlayer 
g_Root = getRootElement() 
  
function lockcar() 
    local pojazd = getPedOccupiedVehicle(g_Me) 
    if pojazd then 
        if (isVehicleLocked (pojazd) == true) then 
                outputChatBox("Pojazd jest juz zamkniety!") -- "Car is locked!" 
        else 
                outputChatBox("Pojazd zostal zamkniety.") 
                setVehicleLocked (pojazd, true ) 
        end 
    end 
end 
addCommandHandler('lock', lockcar) 
  
--------------------------- 
-- unlock vehicle 
--------------------------- 
function unlockcar() 
    local pojazd = getPedOccupiedVehicle(g_Me) 
    if pojazd then 
        if (isVehicleLocked (pojazd) == true) then 
                outputChatBox("Pojazd zostal otworzony.") 
                setVehicleLocked (pojazd, false ) 
        else 
                outputChatBox("Pojazd jest juz otoworzny!") -- "car is opened!" 
        end 
    end 
end 
addCommandHandler('unlock', unlockcar) 
  
--------------------------- 
-- auto unlock vehicle 
--------------------------- 
  
addEventHandler("onClientVehicleStartExit", g_Root, 
function() 
    local pojazd = getPedOccupiedVehicle(g_Me) 
    if (isVehicleLocked (pojazd) == true) then  -- When player want to exit locked car it's been opened. 
            outputChatBox("Pojazd zostal otowrzony.") 
            setVehicleLocked (pojazd, false ) 
    end 
end 
) 

Link to comment

Wrong Jaysd1, you got missing "()" in getLocalPlayer.

The only problem with JR10's fix is that he miss g_Root = getRootElement(), but that was not needed, so he took it off, but forgot to change it in the event handler.

--------------------------- 
-- lock vehicle 
--------------------------- 
function lockcar() 
    local pojazd = getPedOccupiedVehicle(localPlayer) 
    if pojazd then 
        if isVehicleLocked (pojazd) then 
                outputChatBox("Pojazd jest juz zamkniety!") -- "Car is locked!" 
        else 
                outputChatBox("Pojazd zostal zamkniety.") 
                setVehicleLocked (pojazd, true ) 
        end 
    end 
end 
  
addCommandHandler('lock', lockcar) 
  
--------------------------- 
-- unlock vehicle 
--------------------------- 
function unlockcar() 
    local pojazd = getPedOccupiedVehicle(localPlayer) 
    if pojazd then 
        if isVehicleLocked (pojazd) then 
                outputChatBox("Pojazd zostal otworzony.") 
                setVehicleLocked (pojazd, false ) 
        else 
                outputChatBox("Pojazd jest juz otoworzny!") -- "car is opened!" 
        end 
    end 
end 
  
addCommandHandler('unlock', unlockcar) 
  
--------------------------- 
-- auto unlock vehicle 
--------------------------- 
  
addEventHandler("onClientVehicleStartExit", root, 
function() 
    local pojazd = getPedOccupiedVehicle(localPlayer) 
    if isVehicleLocked (pojazd) then  -- When player want to exit locked car it's been opened. 
            outputChatBox("Pojazd zostal otowrzony.") 
            setVehicleLocked (pojazd, false ) 
    end 
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...