Adding your exports

Adding your exports

This guide details how to use and configure external scripts using the lc_utils resource in your server. It provides an approach to integrating various pre-configured and custom scripts, making easier to use different scripts such as fuel systems, inventory management, vehicle keys, and more.

⚠️

We do not own any of the scripts listed below. Support for these scripts is limited, and integration has been done by our user community.

Pre-configured script exports

Our script comes with many pre-configured exports to simplify your workflow. Below is the configuration to view and toggle the available options for each type of export.

Config.custom_scripts_compatibility = {
	['fuel'] = "default",						-- [ox_fuel|ps-fuel|sna-fuel|cdn-fuel|LegacyFuel|default|other] Fuel script Compatibility
	['inventory'] = "default",					-- [ox_inventory|qs-inventory|ps-inventory|default|other] Inventory script Compatibility
	['keys'] = "default",						-- [qs-vehiclekeys|cd_garage|jaksam|wasabi_carlock|default|other] Keys script Compatibility
	['mdt'] = "default",						-- [ps-mdt|redutzu-mdt|default|other] MDT script Compatibility (to log weapon serial)
	['target'] = "disabled",					-- [qb-target|ox_target|disabled|other] Target script Compatibility (disabled will use markers)
	['notification'] = "default",				-- [okokNotify|qbcore|default|other] Notification script Compatibility
}

Available exports list

Use the tabs below to learn more about the configuration options available for each script category:

For fuel, we have these options:

  • ox_fuel
  • ps-fuel
  • sna-fuel
  • cdn-fuel
  • LegacyFuel

Configuring new exports

To integrate a script not pre-configured, you can set its corresponding field to "other" and after that add your custom export in the respective file, as in the next steps:

Config.custom_scripts_compatibility = {
    ['fuel'] = "other",  -- Set to 'other' to use a custom script
    ...
}

Configuration examples

Below are working examples for each type of resource. Use a similar approach for the scripts you want to configure.

⚠️

The examples below are for clarification purposes only. When using other exports, refer to the documentation of the script you're trying to implement.

Fuel

Navigate to lc_utils\custom_scripts\client\fuel.lua. Below there is a working example using LegacyFuel exports:

function Utils.CustomScripts.setVehicleFuel(vehicle, plate, model, fuel)
	exports['LegacyFuel']:SetFuel(vehicle, fuel)
end

Inventory

Navigate to lc_utils\custom_scripts\server\inventory.lua. Below there is a working example using ox_inventory exports:

Pay attention to the return value. All the functions here must return true when success and false when fails.

function Utils.CustomScripts.givePlayerItem(source,item,amount,metadata)
	if exports['ox_inventory']:CanCarryItem(source, item, amount) then
		-- Must return true if the item has been added
		return exports['ox_inventory']:AddItem(source, item, amount, metadata)
	else
		-- Return false if fails to add the item
		return false
	end
end
 
function Utils.CustomScripts.givePlayerWeapon(source,item,amount,metadata)
	if exports['ox_inventory']:CanCarryItem(source, item, amount) then
		return exports['ox_inventory']:AddItem(source, item, amount, metadata)
	else
		return false
	end
end
 
function Utils.CustomScripts.getPlayerItem(source,item,amount)
	-- The export from ox_inventory already returns true if successfully removes it, and returns false if the user dont have that item.
	-- So you dont have to put any extra logic when using ox_inventory.
	return exports['ox_inventory']:RemoveItem(source, item, amount)
end
 
function Utils.CustomScripts.getPlayerWeapon(source,item,amount)
	return exports['ox_inventory']:RemoveItem(source, item, amount)
end

Keys

Navigate to lc_utils\custom_scripts\client\keys.lua. Below there is a working example using qs-vehiclekeys exports:

function Utils.CustomScripts.giveVehicleKeys(vehicle, plate, model)
	exports['qs-vehiclekeys']:GiveKeys(plate, model)
end
 
function Utils.CustomScripts.removeVehicleKeys(vehicle)
	-- Just helper functions to get the vehicle plate and model in case you need them
	local model = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle))
	local plate = Utils.Vehicles.getPlate(vehicle)
 
	exports['qs-vehiclekeys']:RemoveKeys(plate, model)
end
 
function Utils.CustomScripts.removeVehicleKeysFromPlate(plate,model)
	exports['qs-vehiclekeys']:RemoveKeys(plate, model)
end

MDTs

Navigate to lc_utils\custom_scripts\server\mdt.lua. Below there is a working example using ps-mdt exports:

function Utils.CustomScripts.createWeaponInMdt(source,item,amount,metadata)
	-- Get all the required variables to fill the weapon data in ps-mdt
	local xPlayer = QBCore.Functions.GetPlayer(source)
	local serial = tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4))
	local imageurl = ("https://cfx-nui-qb-inventory/html/images/%s.png"):format(item)
	local notes = "Purchased at Gun Club"
	local owner = xPlayer.PlayerData.charinfo.firstname .. " " .. xPlayer.PlayerData.charinfo.lastname
	local weapClass = 1
	local weapModel = QBCore.Shared.Items[item].label
	-- Update the metadata with the serial generated
	metadata = metadata or {}
	metadata.serie = serial
	-- Attempt to insert the weapon in the user inventory
	if Utils.Framework.insertWeaponInInventory(source,item,amount,metadata) then
		-- Use the ps-mdt export to create the weapon data
		exports['ps-mdt']:CreateWeaponInfo(serial, imageurl, notes, owner, weapClass, weapModel)
		TriggerClientEvent('QBCore:Notify', source, 'Weapon Registered', 'success')
		return true -- Return true if successfully inserted it in the user inventory
	end
	return false -- Return true if failed to insert it in the user inventory
end

Targets

Navigate to lc_utils\custom_scripts\client\target.lua. Below there is a working example using ox_target exports:

function Utils.CustomScripts.createTargetInCoords(location_id,x,y,z,onSelectTargetOptionCallback,labelText,icon,iconColor,zone_id,callbackData)
	exports['ox_target']:addSphereZone({
		coords = vector3(x,y,z),
		radius = 2.0,
		debug = false,
		options = {
			{
				icon = icon,
				iconColor = iconColor,
				label = labelText,
				distance = 2.5,
				onSelect = function()
					onSelectTargetOptionCallback(location_id,callbackData)
				end,
			}
		}
	})
end

Notifications

Navigate to lc_utils\custom_scripts\client\notification.lua. Below there is a working example using okokNotify exports:

function Utils.CustomScripts.notify(type,message)
	-- The type can be 4 values "success" or "error" or "warning" or "info"
	exports['okokNotify']:Alert(Utils.String.capitalizeFirst(type), message, 8000, type, false)
end

Contributing

  • If you have successfully implemented any code, please share your results on our Discord to assist other customers using the same scripts.
  • Claim your customer role in the customer dashboard then you'll unlock the snippets channel where you can post your results.
  • Join us on Discord: https://discord.gg/U5YDgbh (opens in a new tab)