[RELEASE] XNLRankBar ('Fully' working original GTA Rankbar / XP Bar NATIVELY! - with original GTA Levels!)

i can’t make it work

Error running system event handling function for resource es_extended: citizen:/scripting/lua/scheduler.lua:41: Failed to execute thread: @es_extended/server/common.lua:101: attempt to index a nil value (local ‘xPlayer’)
stack traceback:
@es_extended/server/common.lua:101: in upvalue ‘handler’
citizen:/scripting/lua/scheduler.lua:219: in function citizen:/scripting/lua/scheduler.lua:218
stack traceback:
[C]: in function ‘error’
citizen:/scripting/lua/scheduler.lua:41: in field ‘CreateThreadNow’
citizen:/scripting/lua/scheduler.lua:218: in function citizen:/scripting/lua/scheduler.lua:182

How to modify save to mysql ?:upside_down_face:

when i added that, it’s work, but it just gives me the value from my database

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

AddEventHandler('esx:playerLoaded', function(source)
	local _source        = source
	local xPlayer        = ESX.GetPlayerFromId(_source)

	MySQL.Async.fetchAll('SELECT `xp` FROM users WHERE identifier = @identifier', {
		['@identifier'] = xPlayer.identifier
	}, function(result)

			local xpbd = {}

			if result[1].xp ~= nil then
				xpbd = json.decode(result[1].xp)
			end
			   Wait(0)
    TriggerClientEvent('XNL_NET:AddPlayerXP', _source , xpbd)

	end)
end)

when I add this in my common.lua , I get an error

RegisterServerEvent('AddXp')
AddEventHandler('AddXp',function(value)
	
	local _source = source
	local xPlayer  = ESX.GetPlayerFromId(_source)
	MySQL.Async.fetchAll('SELECT `xp` FROM users WHERE identifier = @identifier', {
		['@identifier'] = xPlayer.identifier
	}, function(result)
        -- print(result[1].rank)
	   local xpbd = result[1].xp
   	   wait(0)
	MySQL.Async.fetchAll("UPDATE users SET xp = @xp WHERE identifier = @identifier",{
                 ['@identifier'] = xPlayer.identifier,
				 ['@xp'] = xpbd + (value)
                }
			)
	 end)
end)

how can i make XP transfer to the database while playing

Totally depends on your own database use/style and/or which framework you’re using, unfortunately (for the release) i don’t use any of the ‘popular frameworks’ like ESX, vRP or any other since i’m making my 100% from scratch server.

Due to that i can’t leave my own database saving portions in the release (since it will be of no use for others).

So for that part i unfortunately can’t help you sorry :frowning:
Although there are some examples by others for use with ESX for example which have been posted in this same thread, BUT… i can’t confirm if they work or not since i don’t run those frameworks.

Which is also the reason that this release is more like a ‘development resource’/plugin to incorporate in own gamemodes for example :slight_smile:

bro can you help me I have pasted the same code and I keep getting 0 when loading the game … and in the database it has 1000

the examples given for ESX should not only be saved when am coming back into the game gives you 0 there is some basic problem xD

Is possible to make reward for example lvl 10-20-30 and etc?

Sorry, but for the rankbar script, i have no problems at all, my framework loads it perfectly from my databases and then uses the rankbar system without any problems.

HOWEVER, what CAN be the issue (atleast some others here locally (whom are also working on my server at my workplace), if you have other scripts that interface with the “standard GTA HUD Overlay’s” it MIGHT happen that the rankbar needs to be re-initialized (this is however not a bug in the rankbar, but how the game handles drawing the bar).

So then you can use initialize (everytime) right before adding xp or showing xp.

As for ESX and it working or not: I don’t know, and i won’t know sorry :wink: i don’t use nor ever plan on using ESX (or any other ‘ready to use framework’ for that matter).

Yes it is, you can just build that into your own game/script/framework :), all you would need to do is check on level up if the player has reached a level where he/she will receive an reward :slight_smile:

However (don’t know if you meant that though), it will not be a part of this script/resource, since this is just the resource which provides access and use to the native GTA V rankbar system (it does NOT manage saving levels, ranks, XP or any of that kind). This is because it’s intended to be used in frameworks or gamemodes which can all have their own XP and ranking system/style.

:slight_smile:

solved now save in the database but when I log for the first time it gives me 0 then I move out and I log the second time it gives me the saved points you know by chance something that I have forgotten function etc?
if I solve this problem and the creator of the script gives me public permission on the complete server side

How could i use this? I’ve only installed pre-made databases for esx, but don’t know how to put together this resource.

Anyone have a complete tutorial?

Thanks guys

where do I have to insert this?

anyone got a esx tutorial that works?

If anyone got an ESX working version of this, Please let me know!

Ok guys so i want to share the way we got this working.

Ok first make sure you add the table into the SQL file and add it into your database

ALTER TABLE users ADD COLUMN xp INT DEFAULT 0;

================================================
Ok you will need to add this into es_extended - server - main.lua

RegisterServerEvent(‘AddXp’)
AddEventHandler(‘AddXp’,function(value)

local _source = source
local xPlayer  = ESX.GetPlayerFromId(_source)
MySQL.Async.fetchAll('SELECT `xp` FROM users WHERE identifier = @identifier', {
	['@identifier'] = xPlayer.identifier
}, function(result)
    -- print(result[1].rank)
   local xpbd = result[1].xp

MySQL.Async.fetchAll("UPDATE users SET xp = @xp WHERE identifier = @identifier",
            {
             ['@identifier'] = xPlayer.identifier,
			 ['@xp'] = xpbd + (value)
            }
            )
 end)

end)

RegisterServerEvent(‘RemoveXp’)
AddEventHandler(‘RemoveXp’,function(value)

local _source = source
local xPlayer  = ESX.GetPlayerFromId(_source)
MySQL.Async.fetchAll('SELECT `xp` FROM users WHERE identifier = @identifier', {
	['@identifier'] = xPlayer.identifier
}, function(result)
    -- print(result[1].rank)
   local xpbd = result[1].xp

MySQL.Async.fetchAll("UPDATE users SET xp = @xp WHERE identifier = @identifier",
            {
             ['@identifier'] = xPlayer.identifier,
			 ['@xp'] = xpbd - (value)
            }
            )
 end)

end)

=====================================================================

Now make a server.lua in the XNLRankBar file and add this

ESX = nil

TriggerEvent(‘esx:getSharedObject’, function(obj) ESX = obj end)

AddEventHandler(‘esx:playerLoaded’, function(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)

MySQL.Async.fetchAll('SELECT `xp` FROM users WHERE identifier = @identifier', {
    ['@identifier'] = xPlayer.identifier
}, function(result)

        local xpbd = {}

        if result[1].xp ~= nil then
            xpbd = json.decode(result[1].xp)
        end
           Wait(0)
TriggerClientEvent('XNL_NET:AddPlayerXP', _source , xpbd)

    end
)

end)

RegisterServerEvent(‘AddXp’)
AddEventHandler(‘AddXp’,function(value)

local _source = source
local xPlayer  = ESX.GetPlayerFromId(_source)
MySQL.Async.fetchAll('SELECT `xp` FROM users WHERE identifier = @identifier', {
	['@identifier'] = xPlayer.identifier
}, function(result)
    -- print(result[1].rank)
   local xpbd = result[1].xp

MySQL.Async.fetchAll("UPDATE users SET xp = @xp WHERE identifier = @identifier",
            {
             ['@identifier'] = xPlayer.identifier,
			 ['@xp'] = xpbd + (value)
            }
            )
 end)

end)

RegisterServerEvent(‘RemoveXp’)
AddEventHandler(‘RemoveXp’,function(value)

local _source = source
local xPlayer  = ESX.GetPlayerFromId(_source)
MySQL.Async.fetchAll('SELECT `xp` FROM users WHERE identifier = @identifier', {
	['@identifier'] = xPlayer.identifier
}, function(result)
    -- print(result[1].rank)
   local xpbd = result[1].xp

MySQL.Async.fetchAll("UPDATE users SET xp = @xp WHERE identifier = @identifier",
            {
             ['@identifier'] = xPlayer.identifier,
			 ['@xp'] = xpbd - (value)
            }
            )
 end)

end)

Now start your server and there you go

Hmm, this line seems to give entire server the XP bar increase. Ideas to just give it to one player? Im trying to get it to work with killing npcs, gives xp.

AddEventHandler(“onClientMapStart”, function()
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)

        if IsControlJustPressed(1, 73) then
  		TriggerServerEvent('GetUserMoney')
        end
        
  	PopulatePedIndex()
        ResetIndexOnDeath()
        
        for k,v in pairs(pedindex) do
            if DoesEntityExist(k) then
  			veh = GetVehiclePedIsIn(k, false)
  			if not IsPedInVehicle(k, veh, true) then
  				if IsEntityDead(k) then
  				    exports.XNLRankBar:Exp_XNL_AddPlayerXP(10)  --- Shows xp bar for all in server... Fixed by xPlayer...
  					SpawnMoneyWithRandomValue(k,5,13)
  					pedindex[k] = nil						
                        TriggerServerEvent('AddXp', 10)	
  				end
  			end
            end
        end
        
        for k,v in pairs(objval) do
            if DoesEntityExist(k) then
                dist = DistanceBetweenCoords(PlayerPedId(-1), k)
                if (dist.x < 0.4) and (dist.y < 0.4) and (dist.z < 1) then
  				TriggerServerEvent('moneydrop')
                    DeleteObject(k)
  				PlaySoundFrontend(-1, "PICK_UP", "HUD_FRONTEND_DEFAULT_SOUNDSET")
                    objval[k] = nil
                end
            end
        end
    end
end)

end)

Would love your help.

XNLRANKBar
Create a server.lua

Server.lua

ESX               = nil


TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

AddEventHandler('esx:playerLoaded', function(source)
	local _source        = source
	local xPlayer        = ESX.GetPlayerFromId(_source)

	MySQL.Async.fetchAll('SELECT `xp` FROM users WHERE identifier = @identifier', {
		['@identifier'] = xPlayer.identifier
	}, function(result)

			local xpbd = {}

			if result[1].xp ~= nil then
				xpbd = json.decode(result[1].xp)
			end
			   Wait(0)
    TriggerClientEvent('XNL_NET:AddPlayerXP', _source , xpbd)

		end
	)

end)

		
RegisterServerEvent('AddXp')
AddEventHandler('AddXp',function(value)
	
	local _source = source
	local xPlayer  = ESX.GetPlayerFromId(_source)
	MySQL.Async.fetchAll('SELECT `xp` FROM users WHERE identifier = @identifier', {
		['@identifier'] = xPlayer.identifier
	}, function(result)
        -- print(result[1].rank)
       local xpbd = result[1].xp
   
	
	MySQL.Async.fetchAll("UPDATE users SET xp = @xp WHERE identifier = @identifier",
                {
                 ['@identifier'] = xPlayer.identifier,
				 ['@xp'] = xpbd + (value)
                }
                )
	
	
	 end)
end)


RegisterServerEvent('RemoveXp')
AddEventHandler('RemoveXp',function(value)
	
	local _source = source
	local xPlayer  = ESX.GetPlayerFromId(_source)
	MySQL.Async.fetchAll('SELECT `xp` FROM users WHERE identifier = @identifier', {
		['@identifier'] = xPlayer.identifier
	}, function(result)
        -- print(result[1].rank)
       local xpbd = result[1].xp
   
	if xpbd >= (value) then
	MySQL.Async.fetchAll("UPDATE users SET xp = @xp WHERE identifier = @identifier",
                {
                 ['@identifier'] = xPlayer.identifier,
				 ['@xp'] = xpbd - (value)
                }
                )
	
	else 
	MySQL.Async.fetchAll("UPDATE users SET xp = @xp WHERE identifier = @identifier",
                {
                 ['@identifier'] = xPlayer.identifier,
				 ['@xp'] = 0
                }
                )
				end
	 end)
end)

Modify __resource.lua:

resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'

client_scripts {
  'client.lua'
}

server_scripts {
  '@mysql-async/lib/MySQL.lua',
  'server.lua'
}


export 'Exp_XNL_SetInitialXPLevels'
export 'Exp_XNL_AddPlayerXP'
export 'Exp_XNL_RemovePlayerXP'
export 'Exp_XNL_GetCurrentPlayerXP'
export 'Exp_XNL_GetLevelFromXP'
export 'Exp_XNL_GetCurrentPlayer'
export 'Exp_XNL_GetCurrentPlayerLevel'

Add ‘xp’ column in your ‘users’ database…

After this…
You have to add those line where you want too add XP…
Exemple:

 exports.XNLRankBar:Exp_XNL_AddPlayerXP(50) 
 TriggerServerEvent('AddXp', 50)

With those line you add 50xp in the database but also visualy in game
edit 50 to whatever you want.

You have to add those line where you want too remove XP…
Exemple:

exports.XNLRankBar:Exp_XNL_RemovePlayerXP(500)
 TriggerServerEvent('RemoveXp', 500)

Cheers
Let me know if i forget something.

3 Likes

it doesnt seem to show xp in levelbar :frowning:

1 Like

do i need to do anything in common.lua?