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.
Exports answer ml_ resources
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.
lua
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
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.
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)
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
Examples
open/server.lua
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
5endopen/server.lua
1function 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_.
ml_yourscript/server.lua
1local crew = exports.ml_base_building:GetCrewByCid(cid)
2if crew and exports.ml_base_building:CrewPermHas(crew.id, cid, 'canOpenStorages') then
3end