Git Product home page Git Product logo

esx_xp's Introduction

esx_xp

Adds an XP ranking system like the one found in GTA:O. Work in progress.

Update

I've abandoned work on this resource in favour of xperience. It offers the same functionality, but is framework agnostic. It also integrates into both ESX and QBCore.

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

TOC

Demos

You can find an interactive demo here.

Increasing XP

Demo Image 1

Rank Up

Demo Image 2

Mini Leaderboard

Demo Image 3

Requirements

Download & Installation

  • Download and extract the package: https://github.com/Mobius1/esx_xp/archive/master.zip
  • Rename the esx_xp-master directory to esx_xp
  • Drop the esx_xp directory into your resources directory on your server
  • Import the esx_xp.sql file into your db
  • Add ensure esx_xp in your server.cfg
  • Edit config.lua to your liking
  • Start your server

Upgrading to 1.0.0

  • Rename the rp_level column in the users table to rp_rank

Upgrading to 1.3.0

As of 1.3.0 the ranks are now stored as nested tables instead of the previous 1D array of XP values and have been moved to ranks.lua.

Old structure

Config.Ranks = {
    0,
    800,
    2100,
    3800,
    6100,
    ...
}

New structure

Config.Ranks = {
    { XP = 0 },
    { XP = 800 },
    { XP = 2100 },
    { XP = 3800 },
    { XP = 6100 },
    ...
}

If you have your own script accessing the ranks table, you'll need to update it, e.g.

Old method:

local rank4XP = Config.Ranks[4]

New method:

local rank4XP = Config.Ranks[4].XP

Configuration

The config.lua file is set to emulate GTA:O as close as possible, but can be changed to fit your own needs.

Config.Enabled      = true  -- enable / disable the resource
Config.Locale       = 'en'  -- Current language
Config.Width        = 532   -- Sets the width of the XP bar in px
Config.Timeout      = 5000  -- Sets the interval in ms that the XP bar is shown before fading out
Config.BarSegments  = 10    -- Sets the number of segments the XP bar has. Native GTA:O is 10
Config.UIKey        = 20    -- The key that toggles the UI - default is "Z"

Config.Leaderboard = {
    Enabled     = true,     -- Enable the leaderboard
    ShowPing    = true,     -- Show player pings on the leaderboard
    Order       = "rank",   -- Order the player list by "name", "rank" or "id"
    PerPage     = 12        -- Max players to show per page    
}

The ranks.lua file contains the ranks / XP / callbacks. Each rank must have the XP key with the required XP to reach the rank as the value.

You can pass an optional callback using the Action key:

Config.Ranks = {
    { XP = 0 }, -- Rank 1
    {           -- Rank 2
        XP = 800,
        Action = function(xPlayer, rankUp, prevRank)
        
            -- Function is called when the player hits this rank

            -- xPlayer: table       - The player's ESX player data
            -- rankUp: boolean      - whether the player reached or dropped to this rank
            -- prevRank: number     - the player's previous rank

        end
    },
    { XP = 2100 }, -- Rank 3
    { XP = 3800 }, -- Rank 4
    ...
}

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()

Utils

Show the UI

ESXP_ShowUI()

-- update the leaderboard at the same time

ESXP_ShowUI(true)

Hide the UI

ESXP_HideUI()

Show the UI and hide after timeout

ESXP_TimeoutUI()

Sort the leaderboard

ESXP_SortLeaderboard("rank")

-- or

ESXP_SortLeaderboard("name")

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.

Listen for rank-up event

AddEventHandler("esx_xp:rankUp", function(newRank --[[ integer ]], previousRank --[[ integer ]])
    -- Do something when player ranks up
end)

Listen for rank-down event

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.

The leaderboard is paginated and can be navigated with arrow keys. The number of players displayed per page can be customised with the PerPage variable.

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.

Commands

Get current XP stats

/ESXP

output

You currently have xxxx XP
Your current rank is xxxx
You require xxxx XP to advance to rank yyyy

Demo Commands

These commands are for testing and will change the UI, but no data will be saved.

If these are not required, you can delete the demo.lua file and remove it's entry in the fxmanifest.lua file.

Set initial XP

/ESXP_SetInitial xp

Add XP

/ESXP_Add xp

Remove XP

/ESXP_Remove xp

Add fake player to leaderboard

/ESXP_AddFakePlayer

Add number of fake players to leaderboard

/ESXP_AddFakePlayer count

Remove all fake players from leaderboard

/ESXP_RemoveFakePlayers

Sort the leaderboard

/ESXP_SortLeaderboard order --[[ rank or name ]]

Admin Commands

This require you to set ace permissions, i.e add_ace group.admin command.esxp_give allow

Give XP to player: /esxp_give [playerId] [xp]

Take XP from player /esxp_take [playerId] [xp]

Set player's XP /esxp_set [playerId] [xp]

Set player's rank /esxp_rank [playerId] [rank]

FAQ

Does this use VenomXNL's XNLRankBar?

No. I thought about using it, but I created a HTML5 version of the GTA:O rankbar so I could have greater control / customisation. You can see the base system I created here.

How do I change the look of the UI?

With a little knowledge of HTML5, CSS3 and JS you can change all aspects of the look and layout of the bar to make it fit with your UI. The main structure is defined in html/ui.html, the main style is defined in html/css/app.css and scripting is defined in html/js/app.js.

You can find a demo of customised UI here

How do I lock a weapon / vehicle / unlockable to a rank?

To lock something to a rank you can listen for the esx_xp:rankUp or esx_xp:rankDown events:

Example of unlocking the minigun at rank 10:

AddEventHandler("esx_xp:rankUp", function(newRank, previousRank)
    if newRank == 10 then
        GiveWeaponToPed(PlayerPedId(), GetHashKey("WEAPON_MINIGUN"), 100, false, false)
    end
end)

If player ranks down then you can remove it:

AddEventHandler("esx_xp:rankDown", function(newRank, previousRank)
    if newRank < 10 then
        local player = PlayerPedId()
        local weapon = GetHashKey("WEAPON_MINIGUN")
        
        if HasPedGotWeapon(player, weapon, false) then
            RemoveWeaponFromPed(player, weapon)
        end
    end
end)

Contributing

Pull requests welcome.

Legal

License

esx_xp - FiveM XP System

Copyright (C) 2020 Karl Saunders

This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.

This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details.

You should have received a copy Of the GNU General Public License along with this program. If Not, see http://www.gnu.org/licenses/.

esx_xp's People

Contributors

mobius1 avatar scareddonut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

esx_xp's Issues

Leaderboard not updating

The leaderboard is not updating itself automatically, it only updates itself after I refresh my database

Level Up Bug

When my player level Up, then i restart server.
My player rank will been reset or down rank.
Please help me solve this problem. TQ

help!

how can i link the script with esx_jobs and esx_scoreboard
plz

level for weapon

How can I block weapons by level? For example, to buy a gun you have to be level 10 , to buy a knife you have to be level 7 …

Level Reward System

Hi, do you have any example on a leveling reward system? Or a template for me to follow?

Invalid ID

Hi im getting invalid ID error when trying to add exp manually....what is it about?
Nice script i hope to get support with that

[HELP] Detach Leaderboard from EXP bar

Hi,
I would like to separate the leaderboard display from the exp bar when I gain level or exp.
I want to see only the exp bar when I level up or gain exp and when I press the Z key the two appear simultaneously.
How could I modify the code to make this happen?

Thanks.

sloved- closed

hello
i want help for esx_vehicleshop

how to lock and unlock vehicles with ranks
for example

if i have [rank 20] i can unlock models for buy it and there some cars i have to get [rank 30] to unlock

it's possible if its possible how ?

I wish you a happy and fulfilling day <3

Hamood

screeen issue

it’s working fine , but it’s never appears on the screen why ?

Leaderboard - Different Problems

Hi! First of all, your script in really nice. However, I found 3 problems, while testing it, both problems are related to the scoreboard.

  1. The first problem is that, when there are more than 30 players, the scoreboard looks kinda bad, here is a example:

image

  1. The second problem is that, when I am alone on the server, I don't show up on the leaderboard. Here is the proof:

image

  1. The third problem is that after typing the commands (ESXP_RemoveFakePlayers / ESXP_AddFakePlayer), it gives me errors in the F8.

image

Database

When im trying to add rewords for each lvl im getting printed in DB: event "event name" was not safe for net

Found problem for leaderboard not showing players.

Hi! I have found the problem with the leaderboard not showing up players.

In my database, I use Rockstar License to store players, but in the GetOnlinePlayers() function , the GetPlayerIdentifier(), gets the steam license.

Level Not Up

hi..
I'm Already Follow That Install
Put On Resource and Start esx_xp On server.cfg
when i start the server...Script Working fine...but level not up or working..
how to make sure level working perfectly?..
need add something in other resource?..
thank guys..

get xp with job

i need to Add experience whenever a player sells. and I like to give each job Different experience. I don’t know how I can with esx_jobs because if I write the “TriggerClientEvent('esx_xp:Add', xPlayer.source, 10)” command above "xPlayer.addMoney (v.price)" gives everyone the same experience

and sorry for my english

leaderboard busted

im running the last esx v1 and my database saves identifiers as just the number with the fivem License, either "license:" needs to be added onto the esx db stuff or you need to strip it off when you grab it with GetPlayerLicense(playerId)..... i took the easy way for now to fix it

if license == v.license or license == "license:"..v.identifier then

Level not load property

Some players are reporting failure to reload their level. I've been going through the code and I'm assuming it's PlayerSpawned's initial function that may be causing the problem but I'm not sure. There are no errors in the F8.

xp for killing AI and other players

how would I go about getting XP to be given when killing AI and how would I do it for killing players plus removing xp from the player that was killed

2 of 30 users I have don't work with the system

Hi I have 2 of my 30 users they have the problem the esx_xp has stoped to work.They said the users table is missing but is here and work for 30 players but not for 2 players.

The 2 players that don't work has try:

Delete the users in the users table
Delete Fivem and reinstall
Delete gta and reinstall
unknown (1)

esx_jobs

dear

how to config xp for each esx_jobs ?
ex: slaughter job > when deliver packaged chicken get for each piece 10xp

what should i do exactly in server & client lua

How can player get 2xp for playing 1 minute?

Hello, I need code, that would add 2 XP to player when his playtime will be 1minute, I need this loop.

Im playing 1 minute I will get 2 XP, I play another minute I will get again 2 XP.

It's like SA-MP, can u help me?

Nice script

nice script, why are there no updates? Some problems when the player rises in the pagerank and we run the server back to level 0 and there is no update for this problem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.