Server
Every server export, with examples.
All exports below are server side. Replace cube_gang with your folder name if you renamed it.
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.
local gang, member = exports.cube_gang:GetPlayerGang(source)- source:
number - returns:
- gang:
tableornilid:numbername:string- unique identifier, e.g.ballaslabel:string- display nametype:string-gang,mafia,mc,cartel...color:string-#RRGGBBlogo:stringornilpoints:numbermoney:number- treasury balancemaxMembers:numberowner:stringornil- identifier of the ownerranks:table<number, { grade, label, leader, permissions }>- indexed by grade,1is the lowestmembers:table<string, { identifier, name, grade }>- indexed by identifier
- member:
tableornilidentifier:stringname:stringgrade:number
- gang:
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))
endGetGang#
local gang = exports.cube_gang:GetGang(gangId)- gangId:
number - returns:
tableornil- same structure asGetPlayerGang
GetGangByName#
local gang = exports.cube_gang:GetGangByName('ballas')- name:
string - returns:
tableornil
HasPermission#
Checks a permission of the player's rank, inheritance included.
local allowed = exports.cube_gang:HasPermission(source, permission)- source:
number - permission:
string- see Permissions - returns:
boolean
if not exports.cube_gang:HasPermission(source, 'garage.use') then
return TriggerClientEvent('ox_lib:notify', source, { type = 'error', description = 'Not allowed' })
endAddMember#
Adds a character to a gang, online or offline.
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,stringornil- the error locale key, e.g.members.gang_full
RemoveMember#
local success, err = exports.cube_gang:RemoveMember(identifier)- identifier:
string - returns:
boolean,stringornil
Score#
GetPoints#
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.
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:
numberornil- the new total
RemovePoints#
exports.cube_gang:RemovePoints(gangId, amount, reason, identifier)Same parameters as AddPoints, the amount is always removed.
SetPoints#
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.
local total = exports.cube_gang:AddPlayerPoints(source, amount, reason)- source:
number - amount:
number - reason?:
string- defaults to'external' - returns:
numberornil
Examples
Reward the gang of a player who won an event.
AddEventHandler('myevents:winner', function(source)
exports.cube_gang:AddPlayerPoints(source, 100, 'event')
end)Remove points when a gang member goes to jail.
AddEventHandler('myjail:jailed', function(source)
local gang, member = exports.cube_gang:GetPlayerGang(source)
if not gang then return end
exports.cube_gang:RemovePoints(gang.id, 10, 'arrest', member.identifier)
end)Territories#
GetZone#
local zone = exports.cube_gang:GetZone(zoneId)- zoneId:
number - returns:
tableornilid:numbername:stringlabel:stringpoints:{ x, y, z? }[]- polygon cornersminZ,maxZ:numberowner:numberornil- gang id
GetZoneByName#
local zone = exports.cube_gang:GetZoneByName('grove_street')GetZoneAt#
Returns the territory at a position.
local zone = exports.cube_gang:GetZoneAt(coords)- coords:
vector3 - returns:
tableornil
GetPlayerZone#
Returns the territory the player is standing in, with its owner and drug demand.
local zone = exports.cube_gang:GetPlayerZone(source)- source:
number - returns:
tableornilid,name,label,ownerownerLabel:stringornilcolor,logo: owner color and logodrugs:{ name, label, multiplier }[]- current drug demand
GetGangZones#
local zones = exports.cube_gang:GetGangZones(gangId)
print(('%d territories'):format(#zones))- gangId:
number - returns:
table[]- same structure asGetPlayerZone
GetZoneOwner#
local gangId = exports.cube_gang:GetZoneOwner(zone)- zone:
number,stringorvector3- zone id, zone name or a position - returns:
numberornil
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.
local added = exports.cube_gang:AddPlayerInfluence(source, amount, reason)- source:
number - amount:
number- can be negative - reason?:
string- passed to theinfluence:addedevent - returns:
boolean-falseif the player has no gang or is outside every territory
RegisterNetEvent('mygraffiti:painted', function()
exports.cube_gang:AddPlayerInfluence(source, 2.5, 'graffiti')
end)AddZoneInfluence#
exports.cube_gang:AddZoneInfluence(zone, gangId, amount, reason)- zone:
number,stringorvector3- zone id, zone name or a position - gangId:
number - amount:
number - reason?:
string - returns:
boolean
AddInfluenceAt#
exports.cube_gang:AddInfluenceAt(coords, gangId, amount, reason)- coords:
vector3 - returns:
boolean
AddInfluence#
Low level version, without any check or event.
exports.cube_gang:AddInfluence(zoneId, gangId, amount)GetInfluence#
local influence = exports.cube_gang:GetInfluence(zoneId, gangId)- returns:
number- between0andConfig.Territories.maxInfluence
Robberies#
AddRobbery#
Rewards the gang of a robber with the influence and points configured in Config.Influence.robberies.types.
local rewarded = exports.cube_gang:AddRobbery(source, robberyType)- source:
number - robberyType:
string- a key ofConfig.Influence.robberies.types, e.g.'store','bank' - returns:
boolean
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.