The resource works out of the box with ESX and QBCore, but you can include your own framework. Also, the resource detects automatically if you are using ESX or QBCore.
Manual framework set up
Navigate to configs/sh_config.lua.
There you will find the following lua code:
Framework = { ESX ='esx', QBCore ='qbcore', Custom ='custom',}CONFIG.Framework = Framework.ESX -- ESX or QBCore or Custom
You can find the client framework stuff inside client/api/framework/bridge.lua. In the client you will find a function like this for each framework with every method or event required inside:
localfunctionloadESX() ESX = exports['es_extended']:getSharedObject() FRAMEWORK.GetPlayerName=function()return ESX.GetPlayerData().fistNameend FRAMEWORK.GetPlayerLastname=function()return ESX.GetPlayerData().lastNameend FRAMEWORK.GetPlayerJob=function()if ESX.GetPlayerData().job ==nilthenreturnnilendreturn ESX.GetPlayerData().job.nameend FRAMEWORK.GetPlayerJobGrade=function()return ESX.GetPlayerData().job.gradeendRegisterNetEvent('esx:playerLogout') -- When a player logs out (multicharacter), reset their dataAddEventHandler('esx:playerLogout', function()TriggerServerEvent('rcore_dispatch:server:removePlayer')end)end
Here you can modify each method to your needs.
Server Side
You can find the server framework stuff inside server/api/framework.lua. In the server you will find a function like this for each framework with every method or event required inside:
localfunctionloadESX() ESX = exports['es_extended']:getSharedObject()ifnot ESX thenreturn dbg.error('[rcore_dispatch] [error] Are you sure that you are using ESX?') endGetPlayerFromId=function(source) dbg.info('GetPlayerFromId: ' .. source)local xPlayer = {}local xplayer = ESX.GetPlayerFromId(source) xPlayer.addMoney=function(money)return xplayer.addMoney(money)end xPlayer.removeMoney=function(money)return xplayer.removeMoney(money)end xPlayer.getMoney=function(money)ifnot xplayer thenreturnnilendreturn xplayer.getMoney()end xPlayer.getRank=function()ifnot xplayer thenreturnnilendlocal jobData = xplayer.getJob()return jobData.grade, jobData.grade_labelend xPlayer.getJob=function()ifnot xplayer thenreturnnilendlocal jobData = xplayer.getJob()return jobData.name, jobData.labelend xPlayer.getSurname=function()ifnot xplayer thenreturnnilendlocal name = xplayer.getName()local surname =string.match(name, '%S+%s(%S+)')return surnameendreturn xPlayerend--- Event that loads the player into the dispatchRegisterNetEvent('esx:playerLoaded')AddEventHandler('esx:playerLoaded', function(playerId,xPlayer)local job = xPlayer.getJob().nameifnot job thenreturn dbg.critical('No job detected in player with id ' .. xPlayer.source) endif CONFIG.JOBS[job] thenLoadPlayer(xPlayer.source, job)endend)RegisterNetEvent('esx:setJob') -- The stored data does not sync with the framework unless we tell it toAddEventHandler('esx:setJob', function(playerId,job)if job thenif CONFIG.JOBS[job.name] thenLoadPlayer(playerId, job.name)elseUnloadPlayer(playerId, job.name)endendend)end
Here you can modify each method to your needs.
Custom Framework
To use a custom framework, follow these steps:
Create your own framework methods or events.
Inside the client-side code (client/api/framework/bridge.lua), create a new function for your custom framework and define the required methods and events. It is required to follow the structure of the functions for the traditional frameworks, an example for client would be:
localfunctionloadESX() RCORE = exports['rcore']:getSharedObject() FRAMEWORK.GetPlayerName=function()return RCORE.GetPlayerData().fistNameend FRAMEWORK.GetPlayerLastname=function()return RCORE.GetPlayerData().lastNameend FRAMEWORK.GetPlayerJob=function()if RCORE.GetPlayerData().job ==nilthenreturnnilendreturn RCORE.GetPlayerData().job.nameend FRAMEWORK.GetPlayerJobGrade=function()return RCORE.GetPlayerData().job.gradeendRegisterNetEvent('rcore:playerLogout') -- When a player logs out (multicharacter), reset their dataAddEventHandler('rcor:playerLogout', function()TriggerServerEvent('rcore_dispatch:server:removePlayer')end)end
Inside the server-side code (server/api/framework.lua), create a new function for your custom framework and define the required methods and events. We recommend copying the function for a traditional framework and replace the events and function for your own custom framework methods.
Modify the framework setup in configs/sh_config.lua: