Cronoss Posted January 26, 2022 Share Posted January 26, 2022 I have been editing a vehicle script to make it work in a RP but I have a problem when executing the command to lock the vehicle, it locks perfectly from the outside, nobody can enter unless the owner unlocks the vehicle, but the problem is that if the owner locks inside, you can still go out. I did some research and found that something could be done with cancelEvent and "onClientVehicleStartExit", I've tried everything but nothing seems to work for me with that command, any advice? This is the code: function setPlayerVehicleLocked(player, vehicle) local vehname = vehicle:getName() if (vehicle:getData("vehicles:locked") == 1) then vehicle:setData("vehicles:locked", 0) vehicle:setLocked(false) player:outputChat("Desbloqueaste tu "..vehname..".", 214, 37, 37) connection:exec("UPDATE vehicles SET locked=? WHERE id=? AND owner=?", 0, vehicle:getData("vehicles:id"), vehicle:getData("vehicles:owner")) elseif (vehicle:getData("vehicles:locked") == 0) then vehicle:setData("vehicles:locked", 1) vehicle:setLocked(true) player:outputChat("Bloqueaste tu "..vehname..".", 141, 229, 22) connection:exec("UPDATE vehicles SET locked=? WHERE id=? AND owner=?", 1, vehicle:getData("vehicles:id"), vehicle:getData("vehicles:owner")) end end function onclientVehicleStartExit() if (vehicle:getData("vehicles:locked") == 0) then cancelEvent(onVehicleStartExit) end end ("onclientVehicleStartExit", root, onVehicleStartExit) Link to comment
βurak Posted January 26, 2022 Share Posted January 26, 2022 (edited) function blockPlayerExitIfLocked() if (source:getData("vehicles:locked") == 1) then cancelEvent() end end addEventHandler("onClientVehicleStartExit", root, blockPlayerExitIfLocked) not sure but test this Edited January 26, 2022 by Burak5312 1 Link to comment
Cronoss Posted January 26, 2022 Author Share Posted January 26, 2022 Stilll doesn't work, I don't know what I'm missing Link to comment
βurak Posted January 26, 2022 Share Posted January 26, 2022 (edited) function blockPlayerExitIfLocked() if(isVehicleLocked(source)) then cancelEvent() end end addEventHandler("onClientVehicleStartExit", root, blockPlayerExitIfLocked) can you try this if we test normally if you don't mind? Edited January 26, 2022 by Burak5312 1 Link to comment
Cronoss Posted January 26, 2022 Author Share Posted January 26, 2022 Console doesn't send me any error message, but It doesn't work (sorry for my bad English) Link to comment
βurak Posted January 26, 2022 Share Posted January 26, 2022 (edited) yes, I tested it, it didn't work. How about doing it on the server side with "onVehicleStartExit" instead? server: function blockPlayerExitIfLocked() if(isVehicleLocked(source)) then cancelEvent() end end addEventHandler("onVehicleStartExit", root, blockPlayerExitIfLocked) Edited January 26, 2022 by Burak5312 1 Link to comment
Cronoss Posted January 26, 2022 Author Share Posted January 26, 2022 It worked!! thank u so much 1 Link to comment
βurak Posted January 26, 2022 Share Posted January 26, 2022 no problem if you have any other questions, open a new thread and I will help you as much as I can 2 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