Exports
Server-side exports for Possible Territories.
The resource folder must be named possible-territories on the server. If it is renamed, these exports will not resolve.
These are the server exports you can call from other resources. Resource name is possible-territories.
Gameplay exports first, then the MDT / zone-management ones.
GetPlayerTerritory
Returns the territory the player is currently standing in, based on their ped state bag.
exports['possible-territories']:GetPlayerTerritory(playerId)Parameters
| Name | Type | Required | Description |
|---|---|---|---|
playerId | number | ✅ | Player server id (source) |
Returns
| Type | Description |
|---|---|
table|nil | Territory info, or nil if they are not inside a zone |
{ name = "LSIA", -- territory / zone name owner = "ballas", -- owning gang, or nil if unowned gangColor = 7 -- blip color index for the owner}Example
local territory = exports['possible-territories']:GetPlayerTerritory(source)if territory then print(('In %s (owner: %s)'):format(territory.name, territory.owner or 'none'))endlocal territory = exports['possible-territories']:GetPlayerTerritory(source)if territory then print(('In %s (owner: %s)'):format(territory.name, territory.owner or 'none'))endlocal territory = exports['possible-territories']:GetPlayerTerritory(source)if territory then print(('In %s (owner: %s)'):format(territory.name, territory.owner or 'none'))endUpdateInfluenceForGangInTerritory
Adds influence for a gang in a territory. At 100 influence that gang takes ownership.
exports['possible-territories']:UpdateInfluenceForGangInTerritory(territoryName, gangID, influence, peaceful)Parameters
| Name | Type | Required | Description |
|---|---|---|---|
territoryName | string|number | ✅ | Territory name, or a player source — if you pass a number, the player's current zone is used |
gangID | string | ✅ | Gang name from config.Gangs |
influence | number | ✅ | Influence to add |
peaceful | boolean | ❌ | If true, forces that gang peaceful in the territory instead of adding influence |
Example
local Player = exports.qbx_core:GetPlayer(source)local gangID = Player.PlayerData.gang.name
-- Current territory the player is standing inexports['possible-territories']:UpdateInfluenceForGangInTerritory(source, gangID, 2)
-- Or target a territory by nameexports['possible-territories']:UpdateInfluenceForGangInTerritory('LSIA', 'ballas', 5)local QBCore = exports['qb-core']:GetCoreObject()local Player = QBCore.Functions.GetPlayer(source)local gangID = Player.PlayerData.gang.name
exports['possible-territories']:UpdateInfluenceForGangInTerritory(source, gangID, 2)exports['possible-territories']:UpdateInfluenceForGangInTerritory('LSIA', 'ballas', 5)local xPlayer = ESX.GetPlayerFromId(source)local gangID = xPlayer.getJob().name
exports['possible-territories']:UpdateInfluenceForGangInTerritory(source, gangID, 2)exports['possible-territories']:UpdateInfluenceForGangInTerritory('LSIA', 'ballas', 5)AddItemToStash
Adds an item to the territory stash for the zone the player is currently in. Only the owning gang can open that stash in-game.
exports['possible-territories']:AddItemToStash(playerId, rewardItem, amount)Parameters
| Name | Type | Required | Description |
|---|---|---|---|
playerId | number | ✅ | Player server id — used to resolve their current territory |
rewardItem | string | ✅ | ox_inventory item name |
amount | number | ✅ | How many to add |
Example
exports['possible-territories']:AddItemToStash(source, 'black_money', 500)exports['possible-territories']:AddItemToStash(source, 'black_money', 500)exports['possible-territories']:AddItemToStash(source, 'black_money', 500)SetGangPeacefulStatus
Sets a gang peaceful or unpeaceful in a territory. Useful if another script needs to control hostility.
exports['possible-territories']:SetGangPeacefulStatus(territoryName, gangId, isPeaceful, callback, playerSource)Parameters
| Name | Type | Required | Description |
|---|---|---|---|
territoryName | string | ✅ | Territory name |
gangId | string | ✅ | Gang name from config.Gangs |
isPeaceful | boolean | ✅ | true = peaceful, false = unpeaceful |
callback | function | ❌ | Called with { success = boolean, error? = string } when the DB write finishes |
playerSource | number | ❌ | Optional player who triggered the change (for logging / context) |
Returns
Returns immediately with { success = "pending" } because the DB write is async. Prefer the callback for the real result.
Example
exports['possible-territories']:SetGangPeacefulStatus('LSIA', 'ballas', true, function(result) if result.success == true then print('Ballas are now peaceful in LSIA') else print('Failed:', result.error) endend)exports['possible-territories']:SetGangPeacefulStatus('LSIA', 'ballas', true, function(result) if result.success == true then print('Ballas are now peaceful in LSIA') else print('Failed:', result.error) endend)exports['possible-territories']:SetGangPeacefulStatus('LSIA', 'ballas', true, function(result) if result.success == true then print('Ballas are now peaceful in LSIA') else print('Failed:', result.error) endend)GetGangPeacefulStatus
exports['possible-territories']:GetGangPeacefulStatus(territoryName, gangId)Parameters
| Name | Type | Required | Description |
|---|---|---|---|
territoryName | string | ✅ | Territory name |
gangId | string | ✅ | Gang name |
Returns
| Type | Description |
|---|---|
boolean | true if peaceful, false if not |
NotifyGangsAboutPeacefulStatus
Sends ox_lib notifications to online members of the gangs in gangList when a gang goes peaceful / unpeaceful.
exports['possible-territories']:NotifyGangsAboutPeacefulStatus(gangList, sourceName, territoryName, isPeaceful)Parameters
| Name | Type | Required | Description |
|---|---|---|---|
gangList | table | ✅ | Array of gang names to notify |
sourceName | string | ✅ | Gang that changed status (shown in the message) |
territoryName | string | ✅ | Territory name |
isPeaceful | boolean | ✅ | Whether they went peaceful |
Example
exports['possible-territories']:NotifyGangsAboutPeacefulStatus( { 'ballas', 'families' }, 'ballas', 'LSIA', true)InvalidateExternalCaches
Fires possible-territories:cacheInvalidated so other resources (e.g. Gang MDT) can drop cached territory data.
exports['possible-territories']:InvalidateExternalCaches(territoryName, gangId)Parameters
| Name | Type | Required | Description |
|---|---|---|---|
territoryName | string|nil | ❌ | Territory to invalidate, or omit / nil for all |
gangId | string|nil | ❌ | Gang to invalidate, or omit / nil for all |
Listen from another resource:
AddEventHandler('possible-territories:cacheInvalidated', function(territoryName, gangId) -- clear your own cache hereend)Zone management (MDT / admin tools)
These need TerritoryLocations.AllowMdtManagement = true and TerritoryLocations.Mode = 'database' in shared/config.lua. Permission checks are your responsibility (Gang MDT handles that when using its admin UI).
After the first seed from config.Zones, set SeedFromConfigOnStart = false. Leaving it on can put deleted territories back on resource restart. See Configuration.
ListTerritories
exports['possible-territories']:ListTerritories()Returns an array of:
{ name = "LSIA", label = "LSIA", owner = "ballas", -- or nil zoneType = "poly",}GetTerritory
Full detail for one territory (edit forms, etc.).
exports['possible-territories']:GetTerritory(territoryName)| Name | Type | Required | Description |
|---|---|---|---|
territoryName | string | ✅ | Territory name or label (spaces are normalised to underscores) |
Returns nil if not found, otherwise name, label, owner, zone geometry, prop/stash settings, gangInfluence, and polygonCoords.
GetTerritoriesForMap
Map-ready list for Leaflet / NUI (same shape as the built-in territory map).
exports['possible-territories']:GetTerritoriesForMap()Each entry includes name, label, owner, zoneType, color, and polygon as [y, x] pairs.
CreateTerritory
local ok, err = exports['possible-territories']:CreateTerritory({ label = 'West Dock', zoneType = 'poly', poly = { points = { vec3(-649.24, -3797.73, 50.0), vec3(-659.09, -2898.86, 50.0), vec3(-503.03, -2336.36, 50.0), }, thickness = 500.0, }, propModel = 'prop_ld_int_safe_01', propLocation = vector4(-939.03, -2705.15, 12.96, 331.5), stashSlots = 50, stashWeight = 0, debug = false,})Required: label, zoneType, geometry for that type, propModel, propLocation.
Returns success (boolean), error (string|nil).
UpdateTerritory
Partial update — only send fields you want to change.
local ok, err = exports['possible-territories']:UpdateTerritory('West_Dock', { poly = { points = newPoints, thickness = 500.0 }, propLocation = vector4(x, y, z, w),})| Name | Type | Required | Description |
|---|---|---|---|
territoryName | string | ✅ | Existing territory name |
data | table | ✅ | Fields to patch |
DeleteTerritory
local ok, err, deletedName = exports['possible-territories']:DeleteTerritory('West_Dock')| Name | Type | Required | Description |
|---|---|---|---|
territoryName | string | ✅ | Name or label of the territory |
Returns success, error, and deletedName (canonical DB name when successful). Reloads zones for all clients.
ReloadTerritoryZones
Force a hot-reload of zones from the database (usually called for you after create/update/delete).
exports['possible-territories']:ReloadTerritoryZones() -- everyoneexports['possible-territories']:ReloadTerritoryZones(src) -- one player