Luszeq Posted September 11, 2011 Posted September 11, 2011 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 )
JR10 Posted September 11, 2011 Posted September 11, 2011 --------------------------- -- 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 )
Luszeq Posted September 11, 2011 Author Posted September 11, 2011 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.".
Jaysds1 Posted September 11, 2011 Posted September 11, 2011 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 )
Castillo Posted September 12, 2011 Posted September 12, 2011 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 )
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now