Jump to content

Need help with carlock system


Cronoss

Recommended Posts

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
function blockPlayerExitIfLocked()
   if (source:getData("vehicles:locked") == 1) then
       cancelEvent()
   end
end
addEventHandler("onClientVehicleStartExit", root, blockPlayerExitIfLocked)

 

not sure but test this

Edited by Burak5312
  • Like 1
Link to comment
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 by Burak5312
  • Like 1
Link to comment

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 by Burak5312
  • Like 1
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...