myonlake Posted October 29, 2012 Share Posted October 29, 2012 (edited) Hey, For some reason the below code doesn't work like how I want it to. I have done this many times and this time it doesn't really work with me. Probably a silly typo or something in the script. Client-side bindKey("K", "down", function() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then if getVehicleController(vehicle) == localPlayer then setVehicleLocked(vehicle, not isVehicleLocked(vehicle)) outputChatBox("Vehicle " .. (isVehicleLocked(vehicle) and "" or "un") .. "locked.", 255, 180, 0, false) end end end ) Server-side addEventHandler("onVehicleStartExit", root, function(player, seat, jacked, door) if isVehicleLocked(source) then cancelEvent() outputChatBox("The door is locked.", player, 255, 0, 0, false) end end ) addEventHandler("onVehicleEnter", root, function(player, seat, jacked) if not isVehicleLocked(source) then if tonumber(getElementData(source, "vehicle.owner")) == 0 then outputChatBox("This " .. getVehicleName(source) .. " is a civilian vehicle.", player, 255, 180, 0, false) elseif not tonumber(getElementData(source, "vehicle.owner")) then outputChatBox("This " .. getVehicleName(source) .. " belongs to " .. getElementData(source, "vehicle.owner"):gsub("_", " ") .. ".", player, 255, 180, 0, false) end else local x, y, z = getElementPosition(player) removePedFromVehicle(player) setElementPosition(player, x, y, z + 2) end end ) Edited May 30, 2019 by myonlake Link to comment
Anderl Posted October 29, 2012 Share Posted October 29, 2012 Saying it doesn't work like you want doesn't tell us anything. You might want to tell us what's not working properly. Link to comment
TAPL Posted October 29, 2012 Share Posted October 29, 2012 i guess that because the vehicle locked client side and isVehicleLocked server side won't tell you that the vehicle is locked. Link to comment
Renkon Posted October 29, 2012 Share Posted October 29, 2012 Try this c: bindKey("K", "down", function() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then if getVehicleController(vehicle) == localPlayer then triggerServerEvent("lockCar", localPlayer, vehicle) end end end ) s: addEventHandler("onVehicleStartExit", root, function(player, seat, jacked, door) if isVehicleLocked(source) then cancelEvent() outputChatBox("The door is locked.", player, 255, 0, 0, false) end end ) addEventHandler("onVehicleEnter", root, function(player, seat, jacked) if not isVehicleLocked(source) then if tonumber(getElementData(source, "vehicle.owner")) == 0 then outputChatBox("This " .. getVehicleName(source) .. " is a civilian vehicle.", player, 255, 180, 0, false) elseif not tonumber(getElementData(source, "vehicle.owner")) then outputChatBox("This " .. getVehicleName(source) .. " belongs to " .. getElementData(source, "vehicle.owner"):gsub("_", " ") .. ".", player, 255, 180, 0, false) end else local x, y, z = getElementPosition(player) removePedFromVehicle(player) setElementPosition(player, x, y, z + 2) end end ) addEvent("lockCar", true) addEventHandler("lockCar", root, function(c) setVehicleLocked(c, not isVehicleLocked(c)) outputChatBox("Vehicle " .. (isVehicleLocked(c) and "" or "un") .. "locked.", source, 255, 180, 0, false) end ) Link to comment
myonlake Posted October 29, 2012 Author Share Posted October 29, 2012 Hmm, interesting how client-side and server-side can both cause a lot of trouble sometimes I will test triggering it server-side tomorrow. EDIT: It is working. Cheers! Link to comment
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