Cube Scripts

Server

Every server export, with examples.

All exports below are server side. Replace cube_gang with your folder name if you renamed it.

Note

Identifiers are the framework character identifiers: xPlayer.identifier on ESX, citizenid on QBCore and Qbox, the license on standalone.

Gangs#

GetPlayerGang#

Returns the gang and the membership of a player.

Lua
local gang, member = exports.cube_gang:GetPlayerGang(source)
  • source: number
  • returns:
    • gang: table or nil
      • id: number
      • name: string - unique identifier, e.g. ballas
      • label: string - display name
      • type: string - gang, mafia, mc, cartel...
      • color: string - #RRGGBB
      • logo: string or nil
      • points: number
      • money: number - treasury balance
      • maxMembers: number
      • owner: string or nil - identifier of the owner
      • ranks: table<number, { grade, label, leader, permissions }> - indexed by grade, 1 is the lowest
      • members: table<string, { identifier, name, grade }> - indexed by identifier
    • member: table or nil
      • identifier: string
      • name: string
      • grade: number
Lua
local gang, member = exports.cube_gang:GetPlayerGang(source)

if gang then
    local rank = gang.ranks[member.grade]
    print(('%s is %s of %s'):format(member.name, rank.label, gang.label))
end

GetGang#

Lua
local gang = exports.cube_gang:GetGang(gangId)
  • gangId: number
  • returns: table or nil - same structure as GetPlayerGang

GetGangByName#

Lua
local gang = exports.cube_gang:GetGangByName('ballas')
  • name: string
  • returns: table or nil

HasPermission#

Checks a permission of the player's rank, inheritance included.

Lua
local allowed = exports.cube_gang:HasPermission(source, permission)
  • source: number
  • permission: string - see Permissions
  • returns: boolean
Lua
if not exports.cube_gang:HasPermission(source, 'garage.use') then
    return TriggerClientEvent('ox_lib:notify', source, { type = 'error', description = 'Not allowed' })
end

AddMember#

Adds a character to a gang, online or offline.

Lua
local success, err = exports.cube_gang:AddMember(gangId, identifier, name, grade)
  • gangId: number
  • identifier: string
  • name: string
  • grade?: number - defaults to the lowest rank
  • returns: boolean, string or nil - the error locale key, e.g. members.gang_full

RemoveMember#

Lua
local success, err = exports.cube_gang:RemoveMember(identifier)
  • identifier: string
  • returns: boolean, string or nil

Score#

GetPoints#

Lua
local points = exports.cube_gang:GetPoints(gangId)
  • gangId: number
  • returns: number

AddPoints#

Adds points to a gang, saves them to the history and refreshes the members' interfaces.

Lua
local total = exports.cube_gang:AddPoints(gangId, amount, reason, identifier)
  • gangId: number
  • amount: number - can be negative
  • reason: string - stored in the history, e.g. 'event'
  • identifier?: string - the member responsible, if any
  • returns: number or nil - the new total

RemovePoints#

Lua
exports.cube_gang:RemovePoints(gangId, amount, reason, identifier)

Same parameters as AddPoints, the amount is always removed.

SetPoints#

Lua
exports.cube_gang:SetPoints(gangId, value, reason, identifier)
  • value: number - the new total

AddPlayerPoints#

Adds points to the gang of a player. Does nothing if the player has no gang.

Lua
local total = exports.cube_gang:AddPlayerPoints(source, amount, reason)
  • source: number
  • amount: number
  • reason?: string - defaults to 'external'
  • returns: number or nil

Examples

Reward the gang of a player who won an event.

Lua
AddEventHandler('myevents:winner', function(source)
    exports.cube_gang:AddPlayerPoints(source, 100, 'event')
end)

Territories#

GetZone#

Lua
local zone = exports.cube_gang:GetZone(zoneId)
  • zoneId: number
  • returns: table or nil
    • id: number
    • name: string
    • label: string
    • points: { x, y, z? }[] - polygon corners
    • minZ, maxZ: number
    • owner: number or nil - gang id

GetZoneByName#

Lua
local zone = exports.cube_gang:GetZoneByName('grove_street')

GetZoneAt#

Returns the territory at a position.

Lua
local zone = exports.cube_gang:GetZoneAt(coords)
  • coords: vector3
  • returns: table or nil

GetPlayerZone#

Returns the territory the player is standing in, with its owner and drug demand.

Lua
local zone = exports.cube_gang:GetPlayerZone(source)
  • source: number
  • returns: table or nil
    • id, name, label, owner
    • ownerLabel: string or nil
    • color, logo: owner color and logo
    • drugs: { name, label, multiplier }[] - current drug demand

GetGangZones#

Lua
local zones = exports.cube_gang:GetGangZones(gangId)
print(('%d territories'):format(#zones))
  • gangId: number
  • returns: table[] - same structure as GetPlayerZone

GetZoneOwner#

Lua
local gangId = exports.cube_gang:GetZoneOwner(zone)
  • zone: number, string or vector3 - zone id, zone name or a position
  • returns: number or nil

Influence#

Influence decides who owns a territory. See Territories.

AddPlayerInfluence#

Adds influence to the gang of a player, in the territory where the player stands. The most convenient export for activity scripts.

Lua
local added = exports.cube_gang:AddPlayerInfluence(source, amount, reason)
  • source: number
  • amount: number - can be negative
  • reason?: string - passed to the influence:added event
  • returns: boolean - false if the player has no gang or is outside every territory
Lua
RegisterNetEvent('mygraffiti:painted', function()
    exports.cube_gang:AddPlayerInfluence(source, 2.5, 'graffiti')
end)

AddZoneInfluence#

Lua
exports.cube_gang:AddZoneInfluence(zone, gangId, amount, reason)
  • zone: number, string or vector3 - zone id, zone name or a position
  • gangId: number
  • amount: number
  • reason?: string
  • returns: boolean

AddInfluenceAt#

Lua
exports.cube_gang:AddInfluenceAt(coords, gangId, amount, reason)
  • coords: vector3
  • returns: boolean

AddInfluence#

Low level version, without any check or event.

Lua
exports.cube_gang:AddInfluence(zoneId, gangId, amount)

GetInfluence#

Lua
local influence = exports.cube_gang:GetInfluence(zoneId, gangId)
  • returns: number - between 0 and Config.Territories.maxInfluence

Robberies#

AddRobbery#

Rewards the gang of a robber with the influence and points configured in Config.Influence.robberies.types.

Lua
local rewarded = exports.cube_gang:AddRobbery(source, robberyType)
  • source: number
  • robberyType: string - a key of Config.Influence.robberies.types, e.g. 'store', 'bank'
  • returns: boolean
config.luaLua
robberies = {
    enabled = true,
    zoneOnly = false,
    types = {
        store = { influence = 3.0, points = 5 },
        bank = { influence = 8.0, points = 15 },
        -- add your own types
        container = { influence = 4.0, points = 6 },
    },
},

See Robberies for ready-to-paste examples.