Jump to content

HELP Car Lock system


Recommended Posts

Hello , can someone help me with a car lock system ? I've tried some but they check for veh owner or when you get out of the vehicle and is locked it bugs and you can't get back in. I want something for a DayZ server with what you can only lock the vehicle if you are in it and use the cancleEvent() function to cancel the onPlayerVehicleExit event if locked so you can't get out of it if its locked !

I tried to modify more scripts and put them together but didn't work.

I would apreciate if you already have a script and write it. Thanks.

Link to comment

You can try this one: https://community.multitheftauto.com/index.php?p=resources&s=details&id=8338, it's overkill for a DayZ server but it contains a lock system which uses a table with players as index and the setVehicleLocked function. Another option would be to use setElementData to assign a player as the owner of a vehicle and then validate upon enter during the onVehicleStartEnter event. If the owner doesn't match simply cancel that event and you'll have a working lock system.

Link to comment
You can try this one: https://community.multitheftauto.com/index.php?p=resources&s=details&id=8338, it's overkill for a DayZ server but it contains a lock system which uses a table with players as index and the setVehicleLocked function. Another option would be to use setElementData to assign a player as the owner of a vehicle and then validate upon enter during the onVehicleStartEnter event. If the owner doesn't match simply cancel that event and you'll have a working lock system.

Thanks ! I'll try it when i start my Pc but from what i've seen so far from the photos it has a spawn funtion ... i think i'll remove the vehicle spawn function and only let the lock part.

Link to comment

No idea to PM me about this, it's better to help more people if I'm going to help anyone, that's why I post my reply here instead, now to the solution, try this:

Find this line:

local veh = createVehicle( ... ) 

and add after:

setElementData(veh, "owner", thePlayer) 

This assign a player element as the owner of the newly created vehicle

Then you capture the onVehicleStartEnter event where you perform a check of the vehicle owner:

function enterVehicle ( player, seat, jacked ) --when a player enters a vehicle 
    if ( getElementData(source, "owner")  and player ~= getElementData(source, "owner") ) then  
        cancelEvent() 
        outputChatBox ( "You don't have the keys for this vehicle", player )  
    end 
end 
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle ) 

And there you have a lock system that limits based on players.

Link to comment
No idea to PM me about this, it's better to help more people if I'm going to help anyone, that's why I post my reply here instead, now to the solution, try this:

Find this line:

local veh = createVehicle( ... ) 

and add after:

setElementData(veh, "owner", thePlayer) 

This assign a player element as the owner of the newly created vehicle

Then you capture the onVehicleStartEnter event where you perform a check of the vehicle owner:

function enterVehicle ( player, seat, jacked ) --when a player enters a vehicle 
    if ( getElementData(source, "owner")  and player ~= getElementData(source, "owner") ) then  
        cancelEvent() 
        outputChatBox ( "You don't have the keys for this vehicle", player )  
    end 
end 
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle ) 

And there you have a lock system that limits based on players.

I've managed to make the cancelEvent if vehicle is locked and player wants to exit but ... one more problem ...

Look at this:

function playerForcedExit(thePlayer) 
    local playerVehicle = getPedOccupiedVehicle(thePlayer) 
        if playerVehicle then 
            local vehicleType = getVehicleType(playerVehicle) 
            if isVehicleLockable(playerVehicle) == true then 
                local lockedState = isVehicleLocked(playerVehicle) 
                    if lockedState == true then 
                        setVehicleLocked(playerVehicle,not lockedState) 
                    end 
            end 
        end 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), playerForcedExit ) 
addEventHandler ( "onPlayerQuit", getRootElement(), playerForcedExit ) 
  

I tried to unlock the car if player quits or dies but it checks for the vehicle after the event happes (onPlayerQuit or onPlayerWasted) and he isn't anymore in the vehicle.

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