# Vehicle Lock/Unlock Custom

## 🚗 Integrating the Vehicle Lock/Unlock Function with a Different Script

> If you are using a **different vehicle script** and want to integrate its lock/unlock functionality, you only need to edit the section highlighted below.

📌 **File Path:**\
`templates.lua`

📌 **Line:**\
`373`

📌 **Function:**

```lua
Templates.Action["Vehicle lock/unlock"] = function()

    local playerPed = PlayerPedId()
    local playerCoords = GetEntityCoords(playerPed)
    local vehicle = GetClosestVehicle(playerCoords, 5.0, 0, 71)

    if vehicle then
        local lockStatus = GetVehicleDoorLockStatus(vehicle)

        if lockStatus == 2 then
            SetVehicleDoorsLocked(vehicle, 1)
            SetVehicleDoorsLockedForAllPlayers(vehicle, false)
            Notify("Vehicle unlocked", "success", 5000)

            local plate = GetVehicleNumberPlateText(vehicle)
            TriggerEvent('qb-vehiclekeys:client:AddKeys', plate)

            -- 🔧 INSERT YOUR CUSTOM SCRIPT FUNCTIONS HERE
            -- Example:
            -- exports["s4-vehiclekeys"]:unlockVehicle(vehicle)

        else
            SetVehicleDoorsLocked(vehicle, 2)
            SetVehicleDoorsLockedForAllPlayers(vehicle, true)
            Notify("Vehicle locked", "error", 5000)
        end
    end

end
```

💡 **Notes:**

* After the line `TriggerEvent('qb-vehiclekeys:client:AddKeys', plate)`, you can insert your own `TriggerEvent` or `exports` call to integrate your custom lock/unlock system.
* This allows the locking and unlocking feature to work seamlessly with your own vehicle script.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.0resmon.org/0resmon/s4-resources/s4-flipper-hack-tool/vehicle-lock-unlock-custom.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
