Society Account

Instruction and guide on how to setup your society account for T1GER resources

Introduction

T1GER Resources supports compatibility with society accounts handled by esx_addonaccount, qb-banking or qb-management.

You can also use a custom society-/shared account resource, however you need to implement the functionality yourself.

Config.SocietyAccount

Config.SocietyAccount = 'esx_addonaccount' -- Set the society account system

Specifies the society account system in use. Update this based on your selected society system.

Setup

This guide will help you setup society account functionality with T1GER Resources.

ESX

esx_addonaccount

Setting up functionality to create shared account in runtime is very simple; all you need to is download and install latest esx_addonaccount from here: https://github.com/esx-framework/esx_addonaccount.

Only do the following if you CANNOT download and install latest version and you are required/force to do the changes manually!!

If you prefer to keep your current esx_addonaccount resource for some weird reason, you can also manually implement the functionality.

  1. Navigate to esx_addonaccount/server/main.lua

  2. Find this function:

function GetSharedAccount(name)
  1. Add this export code below the function

exports("GetSharedAccount", GetSharedAccount)
  1. Now in the same file, find this function:

function AddSharedAccount(society, amount)
  1. If the function exists, replace the whole function, if it doesn't exist, the insert - in both cases it's the same code:

function AddSharedAccount(society, amount)
    -- society.name = job_name/society_name
    -- society.label = label for the job/account
    -- amount = if the shared account should start with x amount
    if type(society) ~= 'table' or not society?.name or not society?.label then return end

    -- check if account already exist?
    if SharedAccounts[society.name] ~= nil then return SharedAccounts[society.name] end

    -- addon account:
    local account = MySQL.insert.await('INSERT INTO `addon_account` (name, label, shared) VALUES (?, ?, ?)', {
        society.name, society.label, 1
    })
    if not account then return end

    -- if addon account inserted, insert addon account data:
    local account_data = MySQL.insert.await('INSERT INTO `addon_account_data` (account_name, money) VALUES (?, ?)', {
        society.name, (amount or 0)
    })
    if not account_data then return end
	
    -- if all data inserted successfully to sql:
    SharedAccounts[society.name] = CreateAddonAccount(society.name, nil, (amount or 0))
	return SharedAccounts[society.name]
end
exports("AddSharedAccount", AddSharedAccount)
  1. You have succesfully set up esx_addonaccount to allow for automatic society account creation in runtime. All you need to do is restart the server!

QB Core

qb-banking

Setting up functionality to create shared account in runtime is very simple; all you need to is download and install latest qb-banking from here: https://github.com/qbcore-framework/qb-banking.

qb-management

Only do the following if you are using qb-management:

  1. Navigate to qb-management/server/sv_boss.lua

  2. Scroll down all the way to the bottom and insert the following code:

-- ## T1GER Integrations:
function CreateManagementAccount(job_name, amount)
	local findRow = MySQL.query.await('SELECT * FROM management_funds WHERE type = @type AND job_name = @job_name', {
		['@job_name'] = job_name,
		['@type'] = 'boss'
	})
	if not findRow[1] then 
		MySQL.insert('INSERT INTO management_funds (job_name, amount, type) VALUES (@job_name, @amount, @type)', {
			['@job_name'] = job_name,
			['@amount'] = amount or 0,
			['@type'] = 'boss'
		})
		Accounts[job_name] = amount or 0
	end
end
exports("CreateManagementAccount", CreateManagementAccount)
  1. Restart your server and you will now be able to create society accounts in runtime!

Functions

These are the functions used in our T1GER resources.

These are also the functions you want to modify in case you want to integrate your custom society/shared account resource. Simply use 'custom' in Config.SocietyAccount and integrate your export/functions in the if/else statements for 'custom'.

GetSharedAccount

GetSharedAccount(society)
-- parameters: society(string)
-- returns account(table or integer (based on resource return value))

CreateSharedAccount

CreateSharedAccount(society, startBalance)
-- parameters: society(string), startBalance(integer)
-- returns account(table/integer)

GetSharedAccountBalance

GetSharedAccountBalance(society)
-- parameters: society(string)
-- returns balance(integer)

AddSharedAccountMoney

AddSharedAccountMoney(society, m)
-- parameters: society(string), m(integer)
-- void: adds m amount to shared account with society/job name

RemoveSharedAccountMoney

RemoveSharedAccountMoney(society, m)
-- parameters: society(string), m(integer)
-- void: removes m amount from shared account with society/job name

SetSharedAccountMoney

SetSharedAccountMoney(society, m)
-- parameters: society(string), m(integer)
-- void: sets m amount to shared account with society/job name

Last updated