Cube Scripts

Client

Every client export and state bag, with examples.

All exports below are client side.

Gang#

GetGang#

Returns the gang of the local player.

Lua
local gang = exports.cube_gang:GetGang()
  • returns: table or nil
    • id: number
    • name: string
    • label: string
    • type: string
    • color: string - #RRGGBB
    • logo: string or nil
    • points: number
    • money: number
    • grade: number - rank of the player, 1 is the lowest
    • rank: string - rank label
    • leader: boolean - the player has the highest rank
    • owner: boolean - the player owns the gang
    • permissions: table<string, boolean> - every permission of the player, inheritance included
Lua
local gang = exports.cube_gang:GetGang()

if gang then
    print(('%s - %s'):format(gang.label, gang.rank))
end

HasPermission#

Lua
local allowed = exports.cube_gang:HasPermission(permission)
  • permission: string
  • returns: boolean
Warning

Client checks are for display only. Always check permissions again on the server before doing anything.

State bag#

The gang of every player is replicated in a state bag, readable by any resource without calling an export.

Lua
local gang = LocalPlayer.state.gang

From the server, or for another player:

Lua
local gang = Player(playerId).state.gang
  • id: number
  • name: string
  • label: string
  • color: string
  • grade: number

The value is nil when the player has no gang. React to changes with a state bag handler:

Lua
AddStateBagChangeHandler('gang', ('player:%s'):format(cache.serverId), function(_, _, value)
    print('gang changed', value and value.label)
end)

Color the name of a player with the color of their gang.

Lua
local gang = Player(GetPlayerServerId(player)).state.gang
local color = gang and gang.color or '#FFFFFF'

Territories#

GetCurrentZone#

Returns the territory the local player is standing in.

Lua
local zone = exports.cube_gang:GetCurrentZone()
  • returns: table or nil
    • id: number
    • name: string
    • label: string
    • owner: number or nil - gang id
    • ownerLabel: string or nil
    • color, logo: owner color and logo
    • drugs: { name, label, multiplier }[] - current drug demand
    • points: { x, y, z? }[]
Lua
local zone = exports.cube_gang:GetCurrentZone()
local gang = exports.cube_gang:GetGang()

if zone and gang and zone.owner == gang.id then
    print('You are home')
end

GetZone#

Lua
local zone = exports.cube_gang:GetZone(zoneId)
  • zoneId: number
  • returns: table or nil - same structure as GetCurrentZone

Map#

GetHoveredZone#

Returns the territory under the cursor of the pause map.

Lua
local zone = exports.cube_gang:GetHoveredZone()
  • returns: table or nil

IsMapZonesHidden#

Lua
local hidden = exports.cube_gang:IsMapZonesHidden()

SetMapZonesHidden#

Hides or shows every territory on the minimap and the pause map, for the local player. The choice is remembered.

Lua
exports.cube_gang:SetMapZonesHidden(true)
  • state: boolean

ToggleMapZones#

Lua
exports.cube_gang:ToggleMapZones()

Hide the territories during a cinematic, then bring them back:

Lua
exports.cube_gang:SetMapZonesHidden(true)
-- ... cutscene ...
exports.cube_gang:SetMapZonesHidden(false)