esx_xp
Adds an XP ranking system like the one found in GTA:O.
NOTE: I’m no longer working on this resource. You can find my alternative system here. It is fully standalone, but also has ESX and QBCore integration built-in.
Features
- Designed to emulate the native GTA:O system
- Saves and loads players XP / rank
- Add / remove XP from your own script / job
- Allows you listen for rank changes to reward players
- Fully customisable UI
- Integrated leaderboard
Demos
You can find an interactive demo here.
Increasing XP
Rank Up
Leaderboard
Requirements
Download & Installation
- Download and extract the package: https://github.com/Mobius1/esx_xp/archive/master.zip
- Rename the
esx_xp-master
directory toesx_xp
- Drop the
esx_xp
directory into yourresources
directory on your server - Import the
esx_xp.sql
file into your db - Add
ensure esx_xp
in yourserver.cfg
- Edit
config.lua
to your liking - Start your server
Functions
Setters
Set initial XP rank for player
exports.esx_xp:ESXP_SetInitial(xp --[[ integer ]])
Set Rank for player. This will add the required XP to advance the player to the given rank.
exports.esx_xp:ESXP_SetRank(rank --[[ integer ]])
Give player XP
exports.esx_xp:ESXP_Add(xp --[[ integer ]])
Remove XP from player
exports.esx_xp:ESXP_Remove(xp --[[ integer ]])
Getters
Get player’s current XP
exports.esx_xp:ESXP_GetXP()
Get player’s current rank
-- Get rank from current XP
exports.esx_xp:ESXP_GetRank()
-- or
-- Get rank from given XP
exports.esx_xp:ESXP_GetRank(xp --[[ integer ]])
Get XP required to advance the player to the next rank
exports.esx_xp:ESXP_GetXPToNextRank()
Get XP required to advance the player to the given rank
exports.esx_xp:ESXP_GetXPToRank(rank --[[ integer ]])
Get max attainable XP
exports.esx_xp:ESXP_GetMaxXP()
Get max attainable rank
exports.esx_xp:ESXP_GetMaxRank()
Get player XP and Rank from other ESX resources
If you want to access the players xp and / or rank in other ESX
resources:
Client
local xPlayer = ESX.GetPlayerData()
local playerXP = xPlayer.xp
local playerRank = xPlayer.rank
Server
local xPlayer = ESX.GetPlayerFromId(source)
local playerXP = xPlayer.get("xp")
local playerRank = xPlayer.get("rank")
Client Event Listeners
Wait for esx_xp
to be ready for use
AddEventHandler("esx_xp:ready", function(data --[[ table ]])
local currentXP = data.xp
local currentRank = data.rank
local xPlayer = data.player
-- esx_xp is ready for use
end)
Listen for rank change events. These can be used to reward / punish the player for changing rank.
AddEventHandler("esx_xp:rankUp", function(newRank --[[ integer ]], previousRank --[[ integer ]])
-- Do something when player ranks up
end)
AddEventHandler("esx_xp:rankDown", function(newRank --[[ integer ]], previousRank --[[ integer ]])
-- Do something when player drops a rank
end)
UI
The UI can be toggled with the Z
key by default. The UI will fade out after the interval defined by Config.Timeout
or you can close it immediately with the Z
key.
You can customise the UI key with Config.UIKey
in config.lua
.
The data in the leaderboard is refreshed whenever it is opened so you get up-to-date information.
Further documentation available on the GitHub page.