Developer
Overview
Scripts that load @ml_bridge/init.lua call the Bridge table directly, such as Bridge.GiveItem(source, 'bread', 1). Other resources call the same functions as exports: exports.ml_bridge:GiveItem(source, 'bread', 1).
fxmanifest.lua
1shared_scripts {
2 '@ox_lib/init.lua',
3 '@ml_bridge/init.lua',
4}Server Functions
System
Bridge.IsReady():trueonce detection has finishedBridge.GetFramework():'qbox','qbcore','esx','oxcore'or'standalone'Bridge.GetInventorySystem(): detected inventory, such as'ox'or'qb'Bridge.SupportsMetadata():truewhen the inventory stores item metadataBridge.HasTargetSystem(),Bridge.GetTargetSystem(): whether a target resource runs, and which oneBridge.GetPlayers(): sources of every online player
Identity
Bridge.HasPermission(src, permission?):truefor admins listed inConfig.AdminPermissions, or for one specific permissionBridge.GetPlayer(src): framework player objectBridge.GetPlayerId(src): character ID (citizenid or identifier)Bridge.GetPlayerName(src): FiveM player nameBridge.GetLicense(src): license identifier,license2firstBridge.GetDiscord(src): Discord mention (<@id>) or'Not Linked'Bridge.GetSteam(src): Steam identifier or'Unknown'Bridge.GetPlayerIdentifiers(src): every identifier of the player except the IP
Jobs and Gangs
Bridge.GetJob(src):{ name, grade, label }Bridge.SetJob(src, jobName, grade): sets the jobBridge.HasJob(src, jobName, minGrade?):truewhen the player has the jobBridge.GetDuty(src),Bridge.SetDuty(src, status): reads or sets dutyBridge.GetPlayersByJob(jobName): sources of every player with that jobBridge.GetFrameworkJobs(): every job registered in the frameworkBridge.GetGang(src),Bridge.GetGangGrade(src): gang name and gradeBridge.HasGang(src, gangName, minGrade?):truewhen the player is in the gangBridge.HasGroup(src, groupName, minGrade?):truewhen the name matches the job or the gangBridge.GetGroupContext(src):{ job, jobGrade, gang, gangGrade }in one callBridge.MatchesAnyGroup(src, list, ctx?):truewhen the player is in any job or gang of the list. An empty list allows everyone
Inventory
Bridge.HasItem(src, item, amount?):truewhen the player holds at leastamount(default 1)Bridge.GetItemCount(src, item): amount heldBridge.GetItem(src, item): item dataBridge.GetItems(src): every item, each with name, count, slot and metadata on any inventoryBridge.GiveItem(src, item, amount, meta?): gives an item. Returnstrueon successBridge.GiveItemToFit(src, item, amount, meta?): gives as many as fit. Returnssuccess, givenBridge.GiveItemOrDrop(src, item, amount, meta?, coords?): gives what fits and drops the rest on the ground. Returns the amount given, the amount dropped and the amount that could not be placedBridge.DropItem(coords, items, options?): creates a ground drop with a list of itemsBridge.RemoveItem(src, item, amount): removes an item. Returnstrueon successBridge.GetSlot(src, slot),Bridge.RemoveSlot(src, slot, count?): reads or empties a slotBridge.SetItemMeta(src, slot, metadata): replaces the metadata of a slotBridge.ResolveMetadata(meta): resolves random metadata values (mathRandom,listRandom,probabilityRandom) into final values. Every give and drop function above already calls itBridge.CanCarry(src, item, count):truewhen the amount fitsBridge.CanExchangeItems(),Bridge.ExchangeItems(src, removals, additions): removes and adds items in one step, all or nothing. ML Inventory onlyBridge.ClearInventory(src): empties the inventoryBridge.ConfiscateInventory(src),Bridge.RestoreInventory(src, items?): takes the inventory away and gives it backBridge.GetRegisteredItems(): every item registered in the inventoryBridge.BindUsableItem(item, callback),Bridge.UnbindUsableItem(item): adds or removes a usable item handlerBridge.DegradeItem(src, slot, amount): lowers durability of a slotBridge.DrainWeaponDurability(src, weaponHash, amount): lowers durability of a weaponBridge.GetEquippedWeaponSlot(src): inventory slot of the weapon in hand, ornil
Stashes
Bridge.RegisterStash(id, label, slots, weight, props?): registers a stashBridge.OpenStash(src, id, label, slots, weight, items?, props?): opens a stash, filled withitemswhen givenBridge.OpenPersistentStash(src, id, label, slots, weight, props?): opens a stash that keeps its contentBridge.OpenPlayerStash(src, targetSrc, slots, weight): opens another player's inventoryBridge.GetStash(id),Bridge.IsStashEmpty(id),Bridge.ClearStash(id): reads, checks or empties a stashBridge.RegisterInventoryHook(hookType, callback, options?): hooks inventory events such asswapItemsorbuyItem
Money
Bridge.GetMoney(src, account?): balance,'cash'by defaultBridge.AddMoney(src, account, amount),Bridge.RemoveMoney(src, account, amount): changes a balance
Character
Bridge.GetMeta(src, key),Bridge.SetMeta(src, key, value): player metadataBridge.GetDob(src),Bridge.GetPhone(src): date of birth and phone numberBridge.GetHunger(src),Bridge.AddHunger(src, amount),Bridge.SetHunger(src, value)Bridge.GetThirst(src),Bridge.AddThirst(src, amount),Bridge.SetThirst(src, value)Bridge.GetStress(src),Bridge.AddStress(src, amount),Bridge.RemoveStress(src, amount)Bridge.Login(src, data),Bridge.Logout(src): character login and logoutBridge.IsPlayerDead(src):truewhen dead. Export aliasIsDeadBridge.Revive(src): revives the player
Vehicles
Bridge.GetOwnedVehicles(src): vehicles owned by the playerBridge.GetVehicleModelsByPlates(plates): model of each owned plate in the listBridge.SetVehicleFuel(vehicle, amount): sets fuel on a server entityBridge.SetVehicleLockProtected(vehicle, protected): blocks lockpicking of a vehicle. ml_vehiclekeys only
World
Bridge.GetWeather(),Bridge.GetGameTime(): current weather and in-game hour and minute from the detected weather script
Notifications and Logs
Bridge.NotifyPlayer(src, type, message, duration?):'info','success','error'or'warning'Bridge.Log(opts): sends a log. See Logs below
Callbacks
Bridge.OnServerRequest(name, callback, secure?): registers a callback that clients call withBridge.RequestServer. Withsecure = true, only the resource that registered it can use it
lua
1Bridge.OnServerRequest('myScript:getData', function(src, param1)
2 return { result = 'ok', value = param1 }
3end, true)Client Functions
System
Bridge.IsReady(),Bridge.GetFramework(),Bridge.GetInventorySystem(),Bridge.SupportsMetadata(): same as on the serverBridge.IsPlayerLoaded():trueonce the character is loadedBridge.HasTargetSystem(),Bridge.GetTargetSystem(): whether a target resource runs, and which one
Inventory
Bridge.HasItem(item, amount?),Bridge.GetItem(item),Bridge.GetItems(): local inventoryBridge.GetItemLabel(item): display labelBridge.GetItemDefinitions(): every registered itemBridge.GetInventoryImagePath(),Bridge.GetInventoryImageExt(): where item images liveBridge.OpenInventory(),Bridge.CloseInventory()Bridge.OpenStash(stashId, onClose?): opens a stash, with a callback on closeBridge.OnInventoryChange(callback): runs when the inventory changesBridge.SearchItems(item): searches the inventoryBridge.RegisterItemUse(item, callback): client usable item handlerBridge.DisplayMetadata(data): metadata labels shown in the inventory
Weapons
Bridge.GetCurrentWeapon():{ hash, name, slot, durability, melee }ornilBridge.HasWeaponEquipped():truewith a weapon in hand
Player
Bridge.GetJob():{ name, grade, label }Bridge.MatchesAnyGroup(list):truewhen the local player is in any job or gang of the listBridge.GetPlayerStatus(): hunger and thirstBridge.IsPlayerDead():truewhen dead
Vehicles
Bridge.GiveVehicleKey(plate),Bridge.RemoveVehicleKey(plate)Bridge.GetVehicleFuel(vehicle),Bridge.SetVehicleFuel(vehicle, amount)Bridge.GetVehicleFuelType(vehicle): fuel type, with ml_fuel
World
Bridge.GetWeather(),Bridge.GetGameTime(): weather and in-game time
UI
Bridge.Notify(message, type?, duration?): notification. Duration in ms, 3000 by defaultBridge.ShowTextUI(text, options?),Bridge.HideTextUI(): help textBridge.Progress(options),Bridge.ProgressCircle(options): progress bar. Returnstruewhen completedBridge.CancelProgress(): stops the active progress barBridge.InputDialog(title, inputs): input dialog. Returns the valuesBridge.ContextMenu(options),Bridge.ShowMenu(options),Bridge.HideMenu(): menus
Dispatch
Bridge.AlertDispatch(data): police alert through the detected dispatch. Without one, a map blip lasts 2 minutes and the job gets a notification
lua
1Bridge.AlertDispatch({
2 message = 'Store Robbery',
3 description = 'Armed robbery in progress',
4 coords = GetEntityCoords(cache.ped),
5 jobs = { 'police', 'sheriff' },
6 code = '10-31',
7 blip = {
8 sprite = 58,
9 scale = 1.0,
10 color = 1,
11 flash = true,
12 text = 'Robbery',
13 },
14})Target
Works with ox_target, qb-target, sleepless_interact, or a press-E prompt when none runs.
Bridge.AddEntityTarget(entity, options),Bridge.RemoveEntityTarget(entity, options?)Bridge.AddNetEntityTarget(netId, options),Bridge.RemoveNetEntityTarget(netId, options?)Bridge.AddModelTarget(model, options),Bridge.RemoveModelTarget(model, options?)Bridge.AddPlayerTarget(options),Bridge.RemovePlayerTarget(options?)Bridge.AddVehicleTarget(options),Bridge.RemoveVehicleTarget(options?)Bridge.AddPedTarget(options),Bridge.RemovePedTarget(options?)Bridge.AddZoneTarget(options),Bridge.RemoveZoneTarget(name): box zone. Also asAddTargetZoneandRemoveTargetZoneBridge.AddTargetSphereZone(options),Bridge.RemoveTargetSphereZone(name): sphere zoneBridge.DisableTargeting(disabled): turns targeting off or on
lua
1Bridge.AddEntityTarget(entity, {
2 label = 'Search',
3 icon = 'fas fa-search',
4 distance = 2.0,
5 onSelect = function()
6 print('Searched')
7 end,
8})Callbacks
Bridge.RequestServer(name, ...): calls a server callback and waits for the answer, up to 10 seconds. Call it inside a thread
lua
1CreateThread(function()
2 local data = Bridge.RequestServer('myScript:getData', 'hello')
3 print(data.result)
4end)Logs
Bridge.Log sends to Discord, ox_lib or FiveManage depending on Config.LogProvider.
lua
1Bridge.Log({
2 webhook = 'https://discord.com/api/webhooks/...',
3 title = 'Item Looted',
4 description = 'Player picked up an AK-47',
5 color = 'green',
6 player = source,
7 target = targetSource,
8 fields = {
9 { name = 'Item', value = 'AK-47', inline = true },
10 { name = 'Zone', value = 'Military Base', inline = true },
11 },
12})webhook: Discord webhook.falseskips the logtitle,description: text of the entrycolor:'blue','green','yellow','orange','red','purple'or'white'player,target: sources. Name, character name, character ID, job, license, Discord and Steam are added for eachfields: extra fieldsprovider: destination for this log onlydataset: FiveManage dataset for this log only
Server Events
ml_bridge:server:playerLoaded: a player finished loading, on any frameworkml_bridge:server:playerUnloaded: a player logged out or left
Spatial
Spatial is a client global available to scripts that load @ml_bridge/init.lua. It splits the map into 200 meter sectors and only checks points near the player, so many points cost little.
Spatial.Track(id, target, distance, onEnter?, onExit?): tracks avec3or an entity.onEnterandonExitrun when the player crossesdistanceSpatial.Remove(id): stops tracking
lua
1Spatial.Track('mySpot', vec3(200, 300, 30), 5.0,
2 function(self) print('Entered') end,
3 function(self) print('Left') end
4)
5
6Spatial.Remove('mySpot')