Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

Commit

Permalink
v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobius1 committed Oct 8, 2020
1 parent 6f1303c commit ef7f34e
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 259 deletions.
118 changes: 88 additions & 30 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@ CurrentXP = 0
CurrentRank = 0
Leaderboard = nil
Players = {}
Player = nil
UIActive = true


------------------------------------------------------------
-- READY --
------------------------------------------------------------

TriggerServerEvent("XpM:ready")


------------------------------------------------------------
-- MAIN EVENTS --
------------------------------------------------------------

RegisterNetEvent("XpM:init")
AddEventHandler("XpM:init", function(_xp, _rank, players)

Expand All @@ -19,33 +30,30 @@ AddEventHandler("XpM:init", function(_xp, _rank, players)
local data = {
xpm_init = true,
xpm_config = Config,
currentID = false,
currentID = GetPlayerServerId(PlayerId()),
xp = CurrentXP
}

if Config.Leaderboard.Enabled and players then
data.players = players
data.showPing = Config.Leaderboard.ShowPing

for k, v in pairs(players) do
if GetPlayerServerId(PlayerId()) == tonumber(v.id) then
data.currentID = tonumber(v.id)
if v.current then
Player = v
end
end

-- Sort the leaderboard
SortLeaderboard(players)
end

Players = players
end

-- Update UI
SendNUIMessage(data)

-- Native stats
StatSetInt("MPPLY_GLOBALXP", CurrentXP, 1)
else
print(_('err_lvls_check', #Ranks, 'Config.Ranks'))
TriggerEvent("XpM:print", _('err_lvls_check', #Ranks, 'Config.Ranks'))
end
end)

Expand Down Expand Up @@ -89,10 +97,11 @@ if Config.Leaderboard.Enabled then
else
Players[active] = v
end
end

-- Sort the leaderboard
SortLeaderboard(Players)
if v.current then
Player = v
end
end

-- Update leaderboard
SendNUIMessage({
Expand All @@ -102,6 +111,14 @@ if Config.Leaderboard.Enabled then
end)
end

-- Error Printing
RegisterNetEvent("XpM:print")
AddEventHandler("XpM:print", function(message)
local s = string.rep("=", string.len(message))
print(s)
print(message)
print(s)
end)

------------------------------------------------------------
-- FUNCTIONS --
Expand Down Expand Up @@ -142,7 +159,7 @@ function XPM_SetInitial(XPInit)
local GoalXP = tonumber(XPInit)
-- Check for valid XP
if not GoalXP or (GoalXP < 0 or GoalXP > XPM_GetMaxXP()) then
print(_('err_xp_update', XPInit, "XPM_SetInitial"))
TriggerEvent("XpM:print", _('err_xp_update', XPInit, "XPM_SetInitial"))
return
end
UpdateXP(tonumber(GoalXP), true)
Expand All @@ -158,7 +175,7 @@ function XPM_SetRank(Rank)
local GoalRank = tonumber(Rank)

if not GoalRank then
print(_('err_lvl_update', Rank, "XPM_SetRank"))
TriggerEvent("XpM:print", _('err_lvl_update', Rank, "XPM_SetRank"))
return
end

Expand All @@ -176,7 +193,7 @@ end
function XPM_Add(XPAdd)
-- Check for valid XP
if not tonumber(XPAdd) then
print(_('err_xp_update', XPAdd, "XPM_Add"))
TriggerEvent("XpM:print", _('err_xp_update', XPAdd, "XPM_Add"))
return
end
UpdateXP(tonumber(XPAdd))
Expand All @@ -191,7 +208,7 @@ end
function XPM_Remove(XPRemove)
-- Check for valid XP
if not tonumber(XPRemove) then
print(_('err_xp_update', XPRemove, "XPM_Remove"))
TriggerEvent("XpM:print", _('err_xp_update', XPRemove, "XPM_Remove"))
return
end
UpdateXP(-(tonumber(XPRemove)))
Expand Down Expand Up @@ -242,7 +259,7 @@ function XPM_GetXPToRank(Rank)
local GoalRank = tonumber(Rank)
-- Check for valid rank
if not GoalRank or (GoalRank < 1 or GoalRank > #Config.Ranks) then
print(_('err_lvl_update', Rank, "XPM_GetXPToRank"))
TriggerEvent("XpM:print", _('err_lvl_update', Rank, "XPM_GetXPToRank"))
return
end

Expand Down Expand Up @@ -308,13 +325,23 @@ function XPM_HideUI()
})
end

function XPM_SortLeaderboard(type)
if type == nil then
type = "rank"
function XPM_TimeoutUI(update)
UIActive = true

if update ~= nil then
TriggerServerEvent("XpM:getPlayerData")
end

SendNUIMessage({
xpm_sortleaderboard = type
})
xpm_display = true
})
end

function XPM_SortLeaderboard(type)
SendNUIMessage({
xpm_lb_sort = true,
xpm_lb_order = type or "rank"
})
end

------------------------------------------------------------
Expand All @@ -325,23 +352,38 @@ Citizen.CreateThread(function()
while true do
if IsControlJustReleased(0, Config.UIKey) then
UIActive = not UIActive

if UIActive then
TriggerServerEvent("XpM:getPlayerData")
SendNUIMessage({
xpm_show = true
})
else
SendNUIMessage({
xpm_hide = true
})
end
elseif IsControlJustPressed(0, 174) then
if UIActive then
SendNUIMessage({
xpm_lb_prev = true
})
end
elseif IsControlJustPressed(0, 175) then
if UIActive then
SendNUIMessage({
xpm_lb_next = true
})
end

SendNUIMessage({
xpm_display = true
})

end

Citizen.Wait(1)
end
end)


------------------------------------------------------------
-- EVENTS --
-- MAIN --
------------------------------------------------------------

RegisterNetEvent("XpM:updateUI")
Expand Down Expand Up @@ -382,6 +424,10 @@ RegisterNUICallback('xpm_uichange', function(data)
UIActive = false
end)

RegisterNUICallback('xpm_lbchange', function(data)
LBActive = false
end)


------------------------------------------------------------
-- EXPORTS --
Expand Down Expand Up @@ -417,6 +463,18 @@ exports('XPM_GetMaxXP', XPM_GetMaxXP)
-- GET MAX RANK
exports('XPM_GetMaxRank', XPM_GetMaxRank)

-- SHOW UI
exports('XPM_ShowUI', XPM_ShowUI)

-- HIDE UI
exports('XPM_HideUI', XPM_HideUI)

-- TIMEOUT UI
exports('XPM_TimeoutUI', XPM_TimeoutUI)

-- SORT LEADERBOARD
exports('XPM_SortLeaderboard', XPM_SortLeaderboard)


------------------------------------------------------------
-- COMMANDS --
Expand Down
5 changes: 3 additions & 2 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ Config = {}
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 = 10000 -- Sets the interval in ms that the XP bar is shown before fading out
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"
Order = "rank", -- Order the player list by "name", "rank" or "id"
PerPage = 12 -- Max players to show per page
}

-- Based on the native GTA:O XP ranks
Expand Down
21 changes: 6 additions & 15 deletions demo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,27 @@ RegisterCommand('XPM_AddFakePlayer', function(source, args)

XPM_ShowUI(true)

exports.FeedM:ShowNotification("~b~XPM: ~g~" .. count .. " ~w~players added")
ShowNotification("~b~XPM: ~g~" .. count .. " ~w~players added")
end)

RegisterCommand('XPM_RemoveFakePlayers', function(source, args)
for i=#Players,1,-1 do
if Players[i].fake then
if Players[i].fake ~= nil then
table.remove(Players, i)
end
end

exports.FeedM:ShowNotification("~b~XPM: ~w~Fake players removed")
ShowNotification("~b~XPM: ~w~Fake players removed")

XPM_ShowUI(true)
XPM_ShowUI(true)
end)

RegisterCommand('XPM_SortLeaderboard', function(source, args)
local order = args[1] or "rank"

XPM_ShowUI()

-- Sort the leaderboard
SortLeaderboard(Players, order)

-- Update leaderboard
SendNUIMessage({
xpm_updateleaderboard = true,
xpm_players = Players
})
XPM_SortLeaderboard(order)

exports.FeedM:ShowNotification("~b~XPM: ~w~Leaderboard ordered by ~g~" .. order)
ShowNotification("~b~XPM: ~w~Leaderboard ordered by ~g~" .. order)
end)

function AddFakePlayer()
Expand Down
7 changes: 5 additions & 2 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description 'XP Ranking System (non-ESX version)'

author 'Karl Saunders'

version '1.4.1'
version '1.5.0'

server_scripts {
'@mysql-async/lib/MySQL.lua',
Expand All @@ -33,6 +33,7 @@ files {
'ui/fonts/ChaletComprimeCologneSixty.ttf',
'ui/css/app.css',
'ui/js/class.xpm.js',
'ui/js/class.paginator.js',
'ui/js/class.leaderboard.js',
'ui/js/app.js'
}
Expand All @@ -50,4 +51,6 @@ export 'XPM_GetMaxXP'
export 'XPM_GetMaxRank'

export 'XPM_ShowUI'
export 'XPM_HideUI'
export 'XPM_HideUI'
export 'XPM_TimeoutUI'
export 'XPM_SortLeaderboard'
9 changes: 6 additions & 3 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ Locales["en"] = {
['cmd_current_lvl'] = "Your current rank is ^*^2 %s",
['cmd_next_lvl'] = "You require ^*^2 %s XP ^*^7to advance to rank ^*^2 %s",

['err_xp_update'] = "XpM: Invalid XP (%s) passed to '%s'",
['err_lvl_update'] = "XpM: Invalid Rank (%s) passed to '%s'",
['err_lvls_check'] = "XpM: You have an error in %s ranks in '%s'",
['err_xp_update'] = "^1XPM ERROR: ^7`Invalid XP (%s) passed to '%s'",
['err_lvl_update'] = "^1XPM ERROR: ^7`Invalid Rank (%s) passed to '%s'",
['err_lvls_check'] = "^1XPM ERROR: ^7`You have an error in %s rank(s) in '%s'",
['err_lvl_check'] = "Rank %s: %s",

['err_db_user'] = "^1XPM ERROR: ^7`users` table missing from database. Did you import `es_extended.sql` from es_extended?",
['err_db_columns'] = "^1XPM ERROR: ^7`rp_xp` / `rp_rank` columns missing from `users` table. Did you import `XpM.sql`?",
}
Loading

0 comments on commit ef7f34e

Please sign in to comment.