Developer
Overview
Other resources integrate through server exports and the hooks in open/server.lua, open/client.lua and open/shared.lua. Hooks receive live data: treat propData and prop as read-only and return quickly.
Most server exports answer only resources whose name starts with ml_ and return nil, false or {} to any other caller. IsReady, GetTotalCount, CountPropsByModel, GetGeneratorData and the machine registration exports answer every resource.
1local apiVersion = exports.ml_base_building:GetOpenApiVersion()Server Exports
Pieces
IsReady():trueonce bases are loadedGetActiveProps(),GetTotalCount(): all placed pieces and their countCountPropsByModel(model): pieces of one modelGetPropsByOwner(cid),GetOwnerCount(cid): pieces of one character and their countIsPropListComplete():truewhen every piece has loaded
Flags and placement
GetFlagAtCoords(coords, bucket?),GetFlagsAtCoordsBatch(list): the flag that covers a positionGetFlagInfo(flagId),FlagExists(flagId),IsFlagUnderRaid(flagId)CanBuildAt(cid, coords, bucket?): whether a character can build thereGetPlacementInfo(cid, coords, bucket?, permission?): flag, owner and permission result at a positionCanPlaceAt(cid, coords, bucket?, policy?),CanPlaceAtSrc(src, coords, policy?): placement check for your own placeable objects
Crews
GetCrewByCid(cid): the crew of a character,{ id, name }IsCrewMember(crewId, cid),GetCrewMemberCids(crewId)CrewPermHas(crewId, cid, permName): checks a permission fromshared/data/permissions.lua, such as'canBuild'GetCrewRaidLockUntil(crewId): end of the raid lock of a crew
Generators and machines
GetGeneratorData(propId),AddGeneratorFuel(propId, amount, fuelType)RegisterMachine(spec),RegisterMachineVeto(fn),SetMachineOffered(kind, offered),PublishMachineCatalogue(list),ReadoptMachines(): let another resource add its own machines as base piecesCanUseMachine(src, propId),IsMachinePowered(propId),GetMachineLife(propId),RepairMachine(src, propId, amount),GetMachineProps(),MachineCapabilities()
Beds
GetPlayerBeds(cid),ResolveBedSpawn(cid, bedId),ClaimRespawn(claim): base bed respawns for your death or spawn script
Stations
CanUseStation(src, propId, family?):truewhile the player may use that station right now. Call it before committing each craft, repair or recycle action. A past opening does not authorize later actions.
Tree Platforms
RegisterTreeAnchors(catalogue): adds a tree catalogue for the calling resource. Returnstrue, countorfalse, reason. See Custom Tree Maps on the Structures pageRemoveTreeAnchors(): removes that resource's catalogue
Client Exports
IsBuildEntity(entity):truewhen the entity is a base pieceisSheltered():truewhile the player stands under a base roofMLAdminOpen(),MLAdminPanel(): open the admin panel, and its label and icon for a staff menu
Server Hooks
Located in open/server.lua.
1function MLBB.Hooks.CanPlace(src, model, coords, flagId)
2end
3
4function MLBB.Hooks.CanDamage(attackerSrc, propData, damage, damageContext)
5endCanPlace: returnfalse, localeKeyto refuse a placement.nilkeeps the normal checks. An error or a first value that is not a boolean also refusesCanDamage: returnfalseto refuse damage, ortrue, newDamageto replace it
Notification hooks, called after the action:
OnServerReady()OnPropPlaced(src, propData),OnPropRemoved(src, propData, reason)OnPropDamaged(attackerSrc, propData, damage, lifeAfter, damageContext)OnDoorToggled(src, propData, isOpen),OnStorageOpened(src, propData)OnGeneratorRefueled(src, propId, litres, fuelType, fuelAfter),OnPowerChanged(propId, powered)OnExplosivePlanted(src, propData, itemName)OnFlagCreated(flagId, propId, ownerCid),OnFlagRemoved(flagId)
src can be nil for decay, server removals and offline attackers.
Providers, return nil to keep the default:
GetGameHour(): game hour from 0 to 23, for solar output andraidScheduleGetWeather(): GTA weather name, for solar outputGetWindSpeed(propId, coords): wind speed for a turbine in m/s, 0 to 1000, from a trusted server weather resource. Output is speed divided byratedSpeed
Client Hooks
Located in open/client.lua.
OnClientReady()OnPropEnterRange(prop, entity),OnPropExitRange(prop)OnPowerStateChanged(propId, powered),OnDoorStateChanged(propId, isOpen)OnPlacementStarted(model),OnPlacementConfirmed(model, propId),OnPlacementEnded(model)
Shared Hooks
Located in open/shared.lua.
OnSharedReady(): runs on both sides once the shared hooks are loaded
Server Events
ml_base_building:server:generatorNoise: fired on the server for each running generator whileConfig.Generator.noiseEnabledis on, with{ propId, coords, radius, bucket }. A zombie or AI resource can listen to it
Stations
MLBB.StationBindings in open/shared.lua links imported stations to a crafting resource. Keys are workbench, chemistry, repair, recycler and stove, or a model name to override one family. false leaves a station unconfigured.
1MLBB.StationBindings.workbench = {
2 adapter = 'server_export',
3 resource = 'my_crafting',
4 name = 'OpenBaseStation',
5 args = { recipeSet = 'workbench' },
6}The export receives (src, context, args) and returns true once its interface is open, or false to refuse. context holds propId, kind, model, stationId, ownerCid, flagId, bucket, coords and rotation.
Other adapters: ox_inventory for an existing bench (stationId, index), client_export, client_event, and server_hook, which calls MLBB.Hooks.OpenStation(src, context, args) in open/server.lua. A client event only confirms dispatch, so use an export or hook when the result matters.
Recycling stations need power. Set requireFire = true on a cooking binding to require a lit stove.
More Server Events
ml_base_building:server:ready: bases are loadedml_base_building:server:crewMemberAdded:crewId, cidml_base_building:server:crewMemberRemoved:crewId, cid, reason, where reason iskicked,leftoradmin_kickedml_base_building:server:crewPermsChanged:crewId, cid, permsml_base_building:server:crewDisbanded:crewIdml_base_building:server:flagRemoved:flagIdml_base_building:server:stationRemoved:propIdml_base_building:server:machinePlaced,machineRemoved,machineToggle,machinePower,machineReadopt: for resources usingRegisterMachine, each with a table payload
Examples
1function MLBB.Hooks.CanPlace(src, model, coords, flagId)
2 if #(coords - vec3(298.0, -584.0, 43.0)) < 150.0 then
3 return false, 'placement_disabled_zone'
4 end
5end1function MLBB.Hooks.CanDamage(attackerSrc, propData, damage, damageContext)
2 local hour = Bridge.GetGameTime() or 12
3 if hour >= 22 or hour < 6 then
4 return true, damage * 0.5
5 end
6endThe calling resource name must start with ml_.
1local crew = exports.ml_base_building:GetCrewByCid(cid)
2if crew and exports.ml_base_building:CrewPermHas(crew.id, cid, 'canOpenStorages') then
3end