# Examples how to use

Add keys to Player (In this Example the Player will get the Keys to a Car with the plate "ABC123")&#x20;

```lua
local plate = "ABC123"	
exports['usw_carlock']:giveKeys(plate)
```

Remove Keys from Player (In this Example the keys of the car with the plate  "ABC123" will be removed from the Player)

```lua
local plate = "ABC123"
exports['usw_carlock']:takeKeys(plate)
```

Check if the Player owns the Car (In this example we look if the Player owns the Car with the plate "ABC123")

```lua
ESX.TriggerServerCallback('usw_carlock:isVehicleOwner', function(owner)
    if owner then
        --DO SOMETHING IF PLAYER OWNS CAR
    end
end, plate)
```

Check if a number plate is availabe or if its already in use (In this example we check if the plate "ABC123" is already in use or not)

```lua
local plate = "ABC123"
ESX.TriggerServerCallback('usw_carlock:isPlateAvailable', function(available)
 if available then
   --DO SOMETHING IF PLATE IS AVAILABLE
 end
end, plate)
```

Get the Name of the Player who owns a specific Vehicle (In this example we look if the what the name of the owner of the vehicle with the plate "ABC123" is)

```lua
    local plate = "ABC123"
    ESX.TriggerServerCallback('usw_carlock:getname', function(name)
        print(name) -- NAME IS THE FIRST AND LASTNAME OF THE OWNER OF THE CAR
    end, plate)
```

Now that you had an example of all functions, lets give you some examples how to get the plate of a Vehicle:

This is how you can get the Plate of the Vehicle in that the player is sitting right now. I use the match function in the end, because on my tests, was this the best option to also go good with plates that contains spaces.

<pre class="language-lua"><code class="lang-lua">local ped = PlayerPedId()
<strong>local plate = GetVehicleNumberPlateText(GetVehiclePedIsIn(ped, false)):match( "^%s*(.-)%s*$" )
</strong></code></pre>

Get the plate of the closest Vehicle in a 5.0 radius:

```lua
local coords = GetEntityCoords(GetPlayerPed(-1))
local nearestVehicle = GetClosestVehicle(coords['x'],  coords['y'],  coords['z'],  5.0,  0,  71)
local plate = GetVehicleNumberPlateText(nearestVehicle)
```
