-
Notifications
You must be signed in to change notification settings - Fork 60
/
rankmanager.lua
193 lines (154 loc) · 6.03 KB
/
rankmanager.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
local PLUGIN = PLUGIN
PLUGIN.name = "Overwatch Rank Manager"
PLUGIN.author = "Gary Tate, wowm0d"
PLUGIN.description = "Allows Overwatch to manage ranks."
PLUGIN.schema = "HL2 RP"
PLUGIN.version = "1.3"
PLUGIN.readme = [[
Overwatch Rank Manager for Helix
---
Installation:
- Edit the PLUGIN.rankTable variable at line 50 to fit your rank needs.
- Place rankmanager.Lua file into your Schema's Plugin directory.
Support for this plugin can be found here: https://discord.gg/mntpDMU
]]
PLUGIN.license = [[
The MIT License (MIT)
Copyright (c) 2019 Gary Tate
Copyright (c) 2020 wowm0d
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
ix.lang.AddTable("english", {
cmdCharRankDemote = "Demote an active Overwatch functionary.",
cmdCharRankPromote = "Promote an active Overwatch functionary.",
cmdCharRankSet = "Set the rank of an active Overwatch functionary.",
cRankPromotion = "%s has promoted %s to %s.",
cRankDemotion = "%s has demoted %s to %s.",
cRankSet = "%s has set %s's rank to %s.",
cRankMaxRank = "%s is already the maximum rank.",
cRankMinRank = "%s is already the minimum rank.",
cRankSameRank = "%s is already %s rank.",
cRankInvalidRank = "%s is an invalid rank, cannot change their rank.",
cRankInvalidFaction = "%s is not in a valid faction.",
cRankInvalidInput = "'%s' is not a valid rank."
})
function PLUGIN:CanPlayerSetRanks(client)
if (client:IsDispatch()) then
return true
end
end
if (SERVER) then
timer.Simple(0, function()
PLUGIN.rankTable = {
[FACTION_MPF] = {"00", "10", "20", "30", "40", "50", "60", "70", "80", "90", "RL"},
[FACTION_OTA] = {"OWS", "OWC", "EOW", "EOC"}
}
-- Ignore Below --
PLUGIN.rankMap = {}
for _, ranks in next, PLUGIN.rankTable do
PLUGIN.rankMap[ranks] = {}
for index, rank in next, ranks do
PLUGIN.rankMap[ranks][rank:lower()] = index
end
end
end)
end
ix.command.Add("CharRankSet", {
description = "@cmdCharRankSet",
arguments = {
ix.type.character,
ix.type.string
},
OnCheckAccess = function(_, client)
return hook.Run("CanPlayerSetRanks", client) == true
end,
OnRun = function(self, client, target, rank)
local targetRanks = PLUGIN.rankTable[target:GetFaction()]
if (!targetRanks) then
return "@cRankInvalidFaction", target:GetName()
end
local newRank = PLUGIN.rankMap[targetRanks][rank:lower()]
if (!newRank) then
return "@cRankInvalidInput", rank
end
local name = target:GetName()
for index, rank in next, targetRanks do
if (string.find(name, "[%D+]" .. rank .. "[%D+]")) then
if (newRank == index) then
return "@cRankSameRank", name, rank
end
newRank = targetRanks[newRank]
target:SetName(string.gsub(name, "([%D+])" .. rank .. "([%D+])", "%1" .. newRank .. "%2"))
for _, v in next, player.GetAll() do
if (self:OnCheckAccess(v) or v == target:GetPlayer()) then
v:NotifyLocalized("cRankSet", client:GetName(), name, newRank)
end
end
return
end
end
return "@cRankInvalidRank", name
end
})
ix.command.Add("CharRankPromote", {
description = "@cmdCharRankPromote",
arguments = ix.type.character,
OnCheckAccess = function(_, client)
return hook.Run("CanPlayerSetRanks", client) == true
end,
OnRun = function(self, client, target)
local targetRanks = PLUGIN.rankTable[target:GetFaction()]
if (!targetRanks) then
return "@cRankInvalidFaction", target:GetName()
end
local name = target:GetName()
for index, rank in next, targetRanks do
if (string.find(name, "[%D+]" .. rank .. "[%D+]")) then
if (index == #targetRanks) then
return "@cRankMaxRank", name
end
local newRank = targetRanks[index + 1]
target:SetName(string.gsub(name, "([%D+])" .. rank .. "([%D+])", "%1" .. newRank .. "%2"))
for _, v in next, player.GetAll() do
if (self:OnCheckAccess(v) or v == target:GetPlayer()) then
v:NotifyLocalized("cRankPromotion", client:GetName(), name, newRank)
end
end
return
end
end
return "@cRankInvalidRank", name
end
})
ix.command.Add("CharRankDemote", {
description = "@cmdCharRankDemote",
arguments = ix.type.character,
OnCheckAccess = function(_, client)
return hook.Run("CanPlayerSetRanks", client) == true
end,
OnRun = function(self, client, target)
local targetRanks = PLUGIN.rankTable[target:GetFaction()]
if (!targetRanks) then
return "@cRankInvalidFaction", target:GetName()
end
local name = target:GetName()
for index, rank in next, targetRanks do
if (string.find(name, "[%D+]" .. rank .. "[%D+]")) then
if (index == 1) then
return "@cRankMinRank", name
end
local newRank = targetRanks[index - 1]
target:SetName(string.gsub(name, "([%D+])" .. rank .. "([%D+])", "%1" .. newRank .. "%2"))
for _, v in next, player.GetAll() do
if (self:OnCheckAccess(v) or v == target:GetPlayer()) then
v:NotifyLocalized("cRankDemotion", client:GetName(), name, newRank)
end
end
return
end
end
return "@cRankInvalidRank", name
end
})