Jump to content

Closing vehicles, what's wrong?


Luszeq

Recommended Posts

Posted

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 
) 

Posted
--------------------------- 
-- 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 
) 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

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

Posted

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 
) 

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

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 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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