📖Examples

A list of examples of how to use our exports & events.

Available Functions

All gang functions can be found open inside of server/unlocked/initialize_gang.lua. All parameters with documentation strings are unlocked and available to study. The examples below are just basic examples of frequent functions to get you going.

Manage Gang Money From Player

A common way to interact with players and gangs would be to manage a gang's money, which you would find from a player. Below you can see a very basic example of grabbing a player's gang and managing it's money. Example:

local playerId = <FETCHED PLAYER ID>
local gang = exports["zyke_gangphone"]:GetPlayerGang(playerId)
if (gang) then
    gang.functions.AddMoney(1000, nil, "server", "Robbery")
end

Trigger Events

You can easily trigger events for all members and pass in any arguments. Example:

local playerId = <FETCHED PLAYER ID>
local gang = exports["zyke_gangphone"]:GetPlayerGang(playerId)
if (gang) then
    gang.functions.TriggerClientEvent("some:event", "some argument", 500, true)
end

Get Turf

You can also grab any gang data directly without functions, such as their turf PolyZone vectors. Example:

local playerId = <FETCHED PLAYER ID>
local gang = exports["zyke_gangphone"]:GetPlayerGang(playerId)
if (gang) then
    local turf = gang.turf
end

Get All Members

Another example of grabbing the data directly, you can grab all members as is, with all their gang-related data, and then format them for a nice list. Example:

local playerId = <FETCHED PLAYER ID>
local gang = exports["zyke_gangphone"]:GetPlayerGang(playerId)
if (gang) then
    local members = gang.members
    local ranks = gang.ranks
    
    -- Perform some actions
    -- Perhaps displaying each member with their rank label
end

Get Members Online

If you want to fetch all the members that are currently online, you can do so. Example:

local playerId = <FETCHED PLAYER ID>
local gang = exports["zyke_gangphone"]:GetPlayerGang(playerId)
if (gang) then
    local members = gang.functions.GetOnlineMembers()
end

Last updated