This repository was archived by the owner on Apr 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathutils.lua
98 lines (84 loc) · 2.2 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
-- 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].XP)
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].XP
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 GetRankFromXP(_xp)
local len = #Config.Ranks
for rank = 1, len do
if rank < len then
if Config.Ranks[rank + 1].XP > tonumber(_xp) then
return rank
end
else
return rank
end
end
end
function CloneTable(object)
local lookup_table = {}
local function copy(object)
if type(object) ~= "table" then
return object
elseif lookup_table[object] then
return lookup_table[object]
end
local new_table = {}
lookup_table[object] = new_table
for key, value in pairs(object) do
new_table[copy(key)] = copy(value)
end
return setmetatable(new_table, getmetatable(object))
end
return copy(object)
end