-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathranks.lua
More file actions
107 lines (95 loc) · 3.83 KB
/
ranks.lua
File metadata and controls
107 lines (95 loc) · 3.83 KB
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
-- ranks.lua
-- Implements the /ranks command and hierarchy functions.
function HandleConsoleRanks(Split)
local Ranks = cRankManager:GetAllRanks()
return true, "Ranks (" .. #Ranks .. "): " .. table.concat(Ranks, ", ")
end
function HandleRanksCommand(Split, Player)
local Ranks = cRankManager:GetAllRanks()
return true, SendMessage(Player, cChatColor.LightGray .. "Ranks (" .. #Ranks .. "): " .. table.concat(Ranks, cChatColor.LightGray .. ", "))
end
function HandleAssignCommand(Split, Player)
local Response
local PlayerName = Split[2]
local NewRank = Split[3]
if not PlayerName then
Response = SendMessage(Player, cChatColor.LightGray .. "Usage: " .. Split[1] .. " <player> [rank]")
else
-- Translate from username to unique identifier.
local PlayerUUID = GetPlayerUUID(PlayerName)
if not PlayerUUID or string.len(PlayerUUID) ~= 32 then
Response = SendMessageFailure(Player, "Could not find that player (" .. PlayerName .. ").")
else
-- If lacking parameters, view their rank.
if not NewRank then
-- Display the rank.
local CurrentRank = cRankManager:GetPlayerRankName(PlayerUUID)
if CurrentRank == "" then
Response = SendMessageFailure(Player, "Could not find that player's rank (" .. PlayerName .. "), have they joined before?")
else
Response = SendMessage(Player, cChatColor.LightGray .. "Found the player " .. PlayerName .. "'s rank to be of " .. CurrentRank .. ".")
end
else
-- Change the player's rank:
if not cRankManager:RankExists(NewRank) then
Response = SendMessageFailure(Player, "Could not find that rank (" .. NewRank .. "), did you use Caps?")
else
cRankManager:SetPlayerRank(PlayerUUID, PlayerName, NewRank)
cRoot:Get():ForEachPlayer(
function(a_CBPlayer)
if (a_CBPlayer:GetName() == PlayerName) then
a_CBPlayer:LoadRank()
end
end
)
local CurrentRank = cRankManager:GetPlayerRankName(PlayerUUID)
Response = cRoot:Get():BroadcastChat(cChatColor.LightGray .. cChatColor.Italic .. "Updated the player " .. PlayerName .. "'s rank at request of staff.")
end
end
end
end
return true, Response
end
function HandleConsoleAssign(Split)
local Response
local PlayerName = Split[2]
local NewRank = Split[3]
if not PlayerName then
Response = "Usage: " .. Split[1] .. " <player> [rank]"
else
-- Translate from username to unique identifier.
local PlayerUUID = GetPlayerUUID(PlayerName)
if not PlayerUUID or string.len(PlayerUUID) ~= 32 then
Response = "Could not find that player."
else
-- If lacking parameters, view their rank.
if not NewRank then
-- Display the rank.
local CurrentRank = cRankManager:GetPlayerRankName(PlayerUUID)
if CurrentRank == "" then
Response = "Could not find that player's rank, have they joined before?"
else
Response = "Found the player " .. PlayerName .. "'s rank to be of " .. CurrentRank .. "."
end
else
-- Change the player's rank:
if not cRankManager:RankExists(NewRank) then
Response = "Could not find that rank, did you use Caps?"
else
cRankManager:SetPlayerRank(PlayerUUID, PlayerName, NewRank)
cRoot:Get():ForEachPlayer(
function(a_CBPlayer)
if (a_CBPlayer:GetName() == PlayerName) then
a_CBPlayer:LoadRank()
end
end
)
local CurrentRank = cRankManager:GetPlayerRankName(PlayerUUID)
Response = LOGINFO("Assigned the player " .. PlayerName .. " to " .. CurrentRank .. ".")
Response = cRoot:Get():BroadcastChat(cChatColor.LightGray .. cChatColor.Italic .. "Updated the player " .. PlayerName .. "'s rank at request of console.")
end
end
end
end
return true, Response
end