This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
utils.lua
111 lines (91 loc) · 2.51 KB
/
utils.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
-- Get Identifier
function GetSteamIdentifier(id)
local identifier = false
for k,v in ipairs(GetPlayerIdentifiers(id)) do
if string.match(v, 'steam:') then
identifier = v
break
end
end
return identifier
end
-- Check XP is an integer
function IsInt(XPCheck)
XPCheck = tonumber(XPCheck)
if XPCheck and XPCheck == math.floor(XPCheck) then
return true
end
return false
end
-- Prevent XP from going over / under limits
function LimitXP(XPCheck)
local Max = tonumber(Config.Ranks[#Config.Ranks])
if XPCheck > Max then
XPCheck = Max
elseif XPCheck < 0 then
XPCheck = 0
end
return tonumber(XPCheck)
end
function CheckRanks()
local Limit = #Config.Ranks
local InValid = {}
for i = 1, Limit do
local RankXP = Config.Ranks[i]
if not IsInt(RankXP) then
table.insert(InValid, _('err_lvl_check', i, RankXP))
end
end
return InValid
end
function SortLeaderboard(players, order)
if order == nil then
order = Config.Leaderboard.Order
end
if order == "rank" then
table.sort(players, function(a,b)
return a.rank > b.rank
end)
elseif order == "id" then
table.sort(players, function(a,b)
return a.id > b.id
end)
elseif order == "name" then
table.sort(players, function(a,b)
return a.name < b.name
end)
end
end
function PlayerIsActive(tab, val)
for k, v in ipairs(tab) do
if tonumber(v.id) == tonumber(val) then
return k
end
end
return false
end
function GetOnlinePlayers(_source, players)
local Active = {}
for _, playerId in ipairs(GetPlayers()) do
local name = GetPlayerName(playerId)
for k, v in pairs(players) do
if name == v.name then
local Player = {
name = name,
id = playerId,
xp = v.rp_xp,
rank = v.rp_rank
}
if v.identifier == GetSteamIdentifier(_source) then
Player.current = true
end
if Config.Leaderboard.ShowPing then
Player.ping = GetPlayerPing(playerId)
end
table.insert(Active, Player)
break
end
end
end
return Active
end