Skip to content

Commit 0f0151d

Browse files
committed
Add GUI panel for mute
1 parent e49bae1 commit 0f0151d

File tree

6 files changed

+346
-11
lines changed

6 files changed

+346
-11
lines changed

[admin]/admin2/client/main/admin_players.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,11 @@ function aPlayersTab.onClientClick(button)
174174
guiComboBoxGetItemText(aPlayersTab.SlapOptions, guiComboBoxGetSelected(aPlayersTab.SlapOptions))
175175
)
176176
elseif (source == aPlayersTab.Mute) then
177-
triggerServerEvent(
178-
"aPlayer",
179-
localPlayer,
180-
player,
181-
iif(aPlayers[player].mute, "unmute", "mute")
182-
)
177+
if aPlayers[player].mute then
178+
triggerServerEvent("aPlayer", localPlayer, player, "unmute")
179+
else
180+
aMute.Show(player)
181+
end
183182
elseif (source == aPlayersTab.Freeze) then
184183
triggerServerEvent(
185184
"aPlayer",
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
--[[**********************************
2+
*
3+
* Multi Theft Auto - Admin Panel
4+
*
5+
* client\widgets\admin_mute.lua
6+
*
7+
* Original File by omar-o22
8+
*
9+
**************************************]]
10+
aMute = {
11+
defaultDurations = {
12+
{"1 minute", 60},
13+
{"1 hour", 60 * 60},
14+
{"1 day", 60 * 60 * 24},
15+
{"1 week", 60 * 60 * 24 * 7},
16+
{"Permanent", 0}, -- HARDCODED AS SECOND LAST IN THIS TABLE, DO NOT MOVE
17+
{"Custom", 0} -- HARDCODED AS LAST LAST IN THIS TABLE, DO NOT MOVE
18+
},
19+
}
20+
21+
function aMute.Show(player)
22+
if (not aMuteForm) then
23+
aMute.Create()
24+
end
25+
26+
if (player) then
27+
aMute.playerName = getPlayerName(player)
28+
guiSetText(aMute.Form, "Mute player "..aMute.playerName)
29+
end
30+
31+
addEventHandler("onClientGUIClick", aMute.Form, aMute.onClick)
32+
addEventHandler("onClientGUIFocus", aMute.Form, aMute.onFocus)
33+
addEventHandler("onClientGUIBlur", aMute.Form, aMute.onBlur)
34+
end
35+
36+
function aMute.Close(destroy)
37+
if (destroy) then
38+
destroyElement(aMute.Form)
39+
aMute.Form = nil
40+
else
41+
removeEventHandler("onClientGUIClick", aMute.Form, aMute.onClick)
42+
guiSetVisible(aMute.Form, false)
43+
aMute.Reset()
44+
end
45+
aMute.playerName = nil
46+
end
47+
48+
function aMute.Create()
49+
local sx, sy = guiGetScreenSize()
50+
51+
aMute.Form = guiCreateWindow((sx - 350) / 2, (sy - 270) / 2, 350, 270, "Mute player", false)
52+
aMute.ReasonLabel = guiCreateLabel(25, 40, 300, 20, "Mute reason (required):", false, aMute.Form)
53+
aMute.ReasonEditBox = guiCreateEdit(25, 65, 300, 30, "Enter mute reason...", false, aMute.Form)
54+
aMute.ReasonEditBoxRecievedInput = false
55+
aMute.DurationLabel = guiCreateLabel(25, 110, 300, 20, "Mute duration (required):", false, aMute.Form)
56+
aMute.DurationComboBox = guiCreateComboBox(25, 140, 300, 100, "Select mute duration...", false, aMute.Form)
57+
for i=1, #aMute.defaultDurations do
58+
guiComboBoxAddItem(aMute.DurationComboBox, aMute.defaultDurations[i][1])
59+
end
60+
aMute.DurationEditBox = guiCreateEdit(25, 175, 300, 30, "Duration (seconds)...", false, aMute.Form)
61+
aMute.DurationEditBoxRecievedInput = false
62+
guiSetEnabled(aMute.DurationEditBox, false)
63+
64+
aMute.SubmitButton = guiCreateButton(70, 222, 100, 30, "Submit", false, aMute.Form)
65+
aMute.CancelButton = guiCreateButton(180, 222, 100, 30, "Cancel", false, aMute.Form)
66+
aRegister("mute", aMute.Form, aMute.Show, aMute.Close)
67+
end
68+
69+
function aMute.Reset()
70+
guiSetText(aMute.Form, "Mute player")
71+
guiSetText(aMute.ReasonEditBox, "Enter mute reason...")
72+
aMute.ReasonEditBoxRecievedInput = false
73+
guiComboBoxSetSelected(aMute.DurationComboBox, -1)
74+
guiSetText(aMute.DurationEditBox, "Duration (seconds)...")
75+
guiSetEnabled(aMute.DurationEditBox, false)
76+
aMute.DurationEditBoxRecievedInput = false
77+
end
78+
79+
function aMute.onClick(button, state)
80+
if not (button == "left" and state == "up") then
81+
return
82+
end
83+
84+
-- Handle cancel button first
85+
if source == aMute.CancelButton then
86+
aMute.Close()
87+
return
88+
end
89+
90+
-- Autofill and enable/disable duration editbox based on choice
91+
if source == aMute.DurationComboBox then
92+
local selected = guiComboBoxGetSelected(aMute.DurationComboBox)
93+
if selected == -1 then
94+
return
95+
elseif selected == #aMute.defaultDurations - 2 then
96+
-- Second-last option is permanent duration - clear and disable edit box
97+
guiSetText(aMute.DurationEditBox, "0")
98+
guiSetEnabled(aMute.DurationEditBox, false)
99+
elseif selected == #aMute.defaultDurations - 1 then
100+
-- Last option (should) be custom duration - enable duration edit box
101+
guiSetText(aMute.DurationEditBox, "Duration (seconds)...")
102+
guiSetEnabled(aMute.DurationEditBox, true)
103+
aMute.DurationEditBoxRecievedInput = false
104+
else
105+
guiSetText(aMute.DurationEditBox, aMute.defaultDurations[selected + 1][2])
106+
guiSetEnabled(aMute.DurationEditBox, false)
107+
end
108+
return
109+
end
110+
111+
-- Handle submit button
112+
if source == aMute.SubmitButton then
113+
aMute.verifyForm()
114+
return
115+
end
116+
end
117+
118+
function aMute.onFocus()
119+
-- Clear reason/duration edit boxes on first click
120+
if source == aMute.ReasonEditBox then
121+
if not aMute.ReasonEditBoxRecievedInput then
122+
guiSetText(aMute.ReasonEditBox, "")
123+
aMute.ReasonEditBoxRecievedInput = true
124+
end
125+
elseif source == aMute.DurationEditBox then
126+
if not aMute.DurationEditBoxRecievedInput then
127+
guiSetText(aMute.DurationEditBox, "")
128+
aMute.DurationEditBoxRecievedInput = true
129+
end
130+
end
131+
end
132+
133+
function aMute.onBlur()
134+
-- Reset default text of reason/duration edit boxes if they lose focus with no input
135+
if source == aMute.ReasonEditBox then
136+
if guiGetText(source) == "" then
137+
guiSetText(aMute.ReasonEditBox, "Enter mute reason...")
138+
aMute.ReasonEditBoxRecievedInput = false
139+
end
140+
elseif source == aMute.DurationEditBox then
141+
if guiGetText(source) == "" and (guiComboBoxGetSelected(aMute.DurationComboBox) == #aMute.defaultDurations - 1) then
142+
guiSetText(aMute.DurationEditBox, "Duration (seconds)...")
143+
aMute.DurationEditBoxRecievedInput = false
144+
end
145+
end
146+
end
147+
148+
function aMute.verifyForm()
149+
-- Verify mute reason
150+
local muteReason = guiGetText(aMute.ReasonEditBox)
151+
if muteReason == "" or (not aMute.ReasonEditBoxRecievedInput) then
152+
messageBox("No mute reason provided.", MB_ERROR, MB_OK)
153+
return
154+
end
155+
156+
-- Verify mute duration
157+
local muteDuration
158+
local durationSelection = guiComboBoxGetSelected(aMute.DurationComboBox)
159+
if durationSelection == -1 then
160+
messageBox("No mute duration provided.", MB_ERROR, MB_OK)
161+
return
162+
end
163+
durationSelection = durationSelection + 1 -- ComboBox item indices starts at 0 instead of one
164+
if durationSelection == #aMute.defaultDurations then
165+
muteDuration = guiGetText(aMute.DurationEditBox)
166+
muteDuration = tonumber(muteDuration)
167+
if not muteDuration or muteDuration <= 0 then
168+
messageBox("Invalid mute duration provided.", MB_ERROR, MB_OK)
169+
return
170+
end
171+
else
172+
muteDuration = aMute.defaultDurations[durationSelection][2]
173+
end
174+
175+
-- Build mute request "packet" and send to server
176+
local actualPlayer -- Actual player may be offline
177+
if aMute.playerName then
178+
actualPlayer = getPlayerFromName(aMute.playerName)
179+
end
180+
local data = {
181+
playerName = aMute.playerName,
182+
reason = muteReason,
183+
duration = muteDuration
184+
}
185+
186+
triggerServerEvent(
187+
"aPlayer",
188+
localPlayer,
189+
actualPlayer,
190+
"mute",
191+
data
192+
)
193+
aMute.Close()
194+
end

[admin]/admin2/conf/messages.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<log>ADMIN: $admin has kicked $player ($data)</log>
1616
</group>
1717
<group action="mute" r="255" g="0" b="0">
18-
<all>$player has been muted by $admin.</all>
18+
<all>$player has been muted by $admin ($data).</all>
1919
<log>ADMIN: $admin has muted $player</log>
2020
</group>
2121
<group action="unmute" r="0" g="255" b="100">

[admin]/admin2/meta.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<script src="client/widgets/admin_warp.lua" type="client" cache="false"/>
6767
<script src="client/widgets/admin_report.lua" type="client" cache="false"/>
6868
<script src="client/widgets/admin_weapon.lua" type="client" cache="false"/>
69+
<script src="client/widgets/admin_mute.lua" type="client" cache="false"/>
6970

7071
<script src="shared/utils.lua" type="shared" cache="false"/>
7172

[admin]/admin2/server/admin_functions.lua

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,31 @@ aFunctions = {
3131
["ban"] = function(player, data)
3232
setTimer(banPlayer, 100, 1, player, true, true, true, client, data)
3333
end,
34-
["mute"] = function(player)
35-
setPlayerMuted(player, true)
34+
["mute"] = function(player, data)
35+
if (not data or not data.duration) then
36+
return
37+
end
38+
39+
if isPlayerMuted(player) then
40+
return
41+
end
42+
43+
local time
44+
if data.duration == 0 then
45+
time = "Permanent"
46+
else
47+
time = secondsToTimeDesc(data.duration)
48+
end
49+
50+
aSetPlayerMuted(player, true, data.duration)
51+
return true, time
3652
end,
3753
["unmute"] = function(player)
38-
setPlayerMuted(player, false)
54+
if not isPlayerMuted(player) then
55+
return
56+
end
57+
58+
aSetPlayerMuted(player, false)
3959
end,
4060
["freeze"] = function(player)
4161
local vehicle = getPedOccupiedVehicle(player)

0 commit comments

Comments
 (0)