# API

## Client side exports / events

#### Event: `rcore_radiocar:API:OpenPlayerUI`

* Description
  * This event will open the radio UI if the vehicle meets the requirements to open the radio.

Example:

```lua
RegisterCommand("openradio", function(source, args, raw)
	TriggerEvent("rcore_radiocar:API:OpenPlayerUI")
end)

-- can be called from server-side as well
-- assuming this is a server-side command
RegisterCommand("openradioserver", function(source, args, raw)
	TriggerClientEvent("rcore_radiocar:API:OpenPlayerUI", source)
end)
```

#### Export: OpenPlayerUI

* Description
  * This event will open the radio UI if the vehicle meets the requirements to open the radio.

Example:

```lua
RegisterCommand("test", function(source, args, raw)
	exports.rcore_radiocar:OpenPlayerUI()
end)
```

## Server side exports

if you want to use any of these exports you need to enable them in config.lua So go to your config.lua look for this\
\
`Config.OnlyCarWhoHaveRadio`

And set it to true

This function will allow to the specific plate vehicle to use radio

```lua
-- All types can be find in config.lua
-- Look for Config.RadioStyle
GiveRadioToCar(LicensePlate, typeRadio)
```

Example:

```lua
function GetVehPlate(source)
	return GetVehicleNumberPlateText(GetVehiclePedIsIn(GetPlayerPed(source)))
end

function IsPedInAnyVehicle(source)
	return GetVehiclePedIsIn(GetPlayerPed(source), false) ~= 0
end

RegisterNetEvent("rcore_itemradio:sendLicensePlate", function()
	if not IsPedInAnyVehicle(source) then
		return
	end
	local plate = GetVehPlate(source)

	exports.rcore_radiocar:GiveRadioToCar(plate, 2)
end)
```

Simple function that will return true/false if the plate owns radio

```lua
HasCarRadio(LicensePlate)
```

If you need to check specific type then use this export

```lua
HasCarRadioType(LicensePlate, radioType)
```

Example:

```lua
function GetVehPlate(source)
	return GetVehicleNumberPlateText(GetVehiclePedIsIn(GetPlayerPed(source)))
end

function IsPedInAnyVehicle(source)
	return GetVehiclePedIsIn(GetPlayerPed(source), false) ~= 0
end

RegisterNetEvent("rcore_itemradio:sendLicensePlate", function()
	if not IsPedInAnyVehicle(source) then
		return
	end
	local plate = GetVehPlate(source)

	if exports.rcore_radiocar:HasCarRadio(plate) then
		print("this plate", plate, "does have already the radio")
	else
		print("this plate", plate, "sadly doesnt have radio!")
	end
end)
```

This function will remove access to the radio for the specific plate

```lua
RemoveRadioFromCar(LicensePlate)
```

Example:

```lua
function GetVehPlate(source)
	return GetVehicleNumberPlateText(GetVehiclePedIsIn(GetPlayerPed(source)))
end

function IsPedInAnyVehicle(source)
	return GetVehiclePedIsIn(GetPlayerPed(source), false) ~= 0
end

RegisterNetEvent("rcore_itemradio:sendLicensePlate", function()
	if not IsPedInAnyVehicle(source) then
		return
	end
	local plate = GetVehPlate(source)

	exports.rcore_radiocar:RemoveRadioFromCar(plate)
end)
```
