Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions [admin]/admin2/client/main/admin_players.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,11 @@ function aPlayersTab.onClientClick(button)
guiComboBoxGetItemText(aPlayersTab.SlapOptions, guiComboBoxGetSelected(aPlayersTab.SlapOptions))
)
elseif (source == aPlayersTab.Mute) then
triggerServerEvent(
"aPlayer",
localPlayer,
player,
iif(aPlayers[player].mute, "unmute", "mute")
)
if aPlayers[player].mute then
triggerServerEvent("aPlayer", localPlayer, player, "unmute")
else
aMute.Show(player)
end
elseif (source == aPlayersTab.Freeze) then
triggerServerEvent(
"aPlayer",
Expand Down
194 changes: 194 additions & 0 deletions [admin]/admin2/client/widgets/admin_mute.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
--[[**********************************
*
* Multi Theft Auto - Admin Panel
*
* client\widgets\admin_mute.lua
*
* Original File by omar-o22
*
**************************************]]
aMute = {
defaultDurations = {
{"1 minute", 60},
{"1 hour", 60 * 60},
{"1 day", 60 * 60 * 24},
{"1 week", 60 * 60 * 24 * 7},
{"Permanent", 0}, -- HARDCODED AS SECOND LAST IN THIS TABLE, DO NOT MOVE
{"Custom", 0} -- HARDCODED AS LAST LAST IN THIS TABLE, DO NOT MOVE
},
}

function aMute.Show(player)
if (not aMuteForm) then
aMute.Create()
end

if (player) then
aMute.playerName = getPlayerName(player)
guiSetText(aMute.Form, "Mute player "..aMute.playerName)
end

addEventHandler("onClientGUIClick", aMute.Form, aMute.onClick)
addEventHandler("onClientGUIFocus", aMute.Form, aMute.onFocus)
addEventHandler("onClientGUIBlur", aMute.Form, aMute.onBlur)
end

function aMute.Close(destroy)
if (destroy) then
destroyElement(aMute.Form)
aMute.Form = nil
else
removeEventHandler("onClientGUIClick", aMute.Form, aMute.onClick)
guiSetVisible(aMute.Form, false)
aMute.Reset()
end
aMute.playerName = nil
end

function aMute.Create()
local sx, sy = guiGetScreenSize()

aMute.Form = guiCreateWindow((sx - 350) / 2, (sy - 270) / 2, 350, 270, "Mute player", false)
aMute.ReasonLabel = guiCreateLabel(25, 40, 300, 20, "Mute reason (required):", false, aMute.Form)
aMute.ReasonEditBox = guiCreateEdit(25, 65, 300, 30, "Enter mute reason...", false, aMute.Form)
aMute.ReasonEditBoxRecievedInput = false
aMute.DurationLabel = guiCreateLabel(25, 110, 300, 20, "Mute duration (required):", false, aMute.Form)
aMute.DurationComboBox = guiCreateComboBox(25, 140, 300, 100, "Select mute duration...", false, aMute.Form)
for i=1, #aMute.defaultDurations do
guiComboBoxAddItem(aMute.DurationComboBox, aMute.defaultDurations[i][1])
end
aMute.DurationEditBox = guiCreateEdit(25, 175, 300, 30, "Duration (seconds)...", false, aMute.Form)
aMute.DurationEditBoxRecievedInput = false
guiSetEnabled(aMute.DurationEditBox, false)

aMute.SubmitButton = guiCreateButton(70, 222, 100, 30, "Submit", false, aMute.Form)
aMute.CancelButton = guiCreateButton(180, 222, 100, 30, "Cancel", false, aMute.Form)
aRegister("mute", aMute.Form, aMute.Show, aMute.Close)
end

function aMute.Reset()
guiSetText(aMute.Form, "Mute player")
guiSetText(aMute.ReasonEditBox, "Enter mute reason...")
aMute.ReasonEditBoxRecievedInput = false
guiComboBoxSetSelected(aMute.DurationComboBox, -1)
guiSetText(aMute.DurationEditBox, "Duration (seconds)...")
guiSetEnabled(aMute.DurationEditBox, false)
aMute.DurationEditBoxRecievedInput = false
end

function aMute.onClick(button, state)
if not (button == "left" and state == "up") then
return
end

-- Handle cancel button first
if source == aMute.CancelButton then
aMute.Close()
return
end

-- Autofill and enable/disable duration editbox based on choice
if source == aMute.DurationComboBox then
local selected = guiComboBoxGetSelected(aMute.DurationComboBox)
if selected == -1 then
return
elseif selected == #aMute.defaultDurations - 2 then
-- Second-last option is permanent duration - clear and disable edit box
guiSetText(aMute.DurationEditBox, "0")
guiSetEnabled(aMute.DurationEditBox, false)
elseif selected == #aMute.defaultDurations - 1 then
-- Last option (should) be custom duration - enable duration edit box
guiSetText(aMute.DurationEditBox, "Duration (seconds)...")
guiSetEnabled(aMute.DurationEditBox, true)
aMute.DurationEditBoxRecievedInput = false
else
guiSetText(aMute.DurationEditBox, aMute.defaultDurations[selected + 1][2])
guiSetEnabled(aMute.DurationEditBox, false)
end
return
end

-- Handle submit button
if source == aMute.SubmitButton then
aMute.verifyForm()
return
end
end

function aMute.onFocus()
-- Clear reason/duration edit boxes on first click
if source == aMute.ReasonEditBox then
if not aMute.ReasonEditBoxRecievedInput then
guiSetText(aMute.ReasonEditBox, "")
aMute.ReasonEditBoxRecievedInput = true
end
elseif source == aMute.DurationEditBox then
if not aMute.DurationEditBoxRecievedInput then
guiSetText(aMute.DurationEditBox, "")
aMute.DurationEditBoxRecievedInput = true
end
end
end

function aMute.onBlur()
-- Reset default text of reason/duration edit boxes if they lose focus with no input
if source == aMute.ReasonEditBox then
if guiGetText(source) == "" then
guiSetText(aMute.ReasonEditBox, "Enter mute reason...")
aMute.ReasonEditBoxRecievedInput = false
end
elseif source == aMute.DurationEditBox then
if guiGetText(source) == "" and (guiComboBoxGetSelected(aMute.DurationComboBox) == #aMute.defaultDurations - 1) then
guiSetText(aMute.DurationEditBox, "Duration (seconds)...")
aMute.DurationEditBoxRecievedInput = false
end
end
end

function aMute.verifyForm()
-- Verify mute reason
local muteReason = guiGetText(aMute.ReasonEditBox)
if muteReason == "" or (not aMute.ReasonEditBoxRecievedInput) then
messageBox("No mute reason provided.", MB_ERROR, MB_OK)
return
end

-- Verify mute duration
local muteDuration
local durationSelection = guiComboBoxGetSelected(aMute.DurationComboBox)
if durationSelection == -1 then
messageBox("No mute duration provided.", MB_ERROR, MB_OK)
return
end
durationSelection = durationSelection + 1 -- ComboBox item indices starts at 0 instead of one
if durationSelection == #aMute.defaultDurations then
muteDuration = guiGetText(aMute.DurationEditBox)
muteDuration = tonumber(muteDuration)
if not muteDuration or muteDuration <= 0 then
messageBox("Invalid mute duration provided.", MB_ERROR, MB_OK)
return
end
else
muteDuration = aMute.defaultDurations[durationSelection][2]
end

-- Build mute request "packet" and send to server
local actualPlayer -- Actual player may be offline
if aMute.playerName then
actualPlayer = getPlayerFromName(aMute.playerName)
end
local data = {
playerName = aMute.playerName,
reason = muteReason,
duration = muteDuration
}

triggerServerEvent(
"aPlayer",
localPlayer,
actualPlayer,
"mute",
data
)
aMute.Close()
end
2 changes: 1 addition & 1 deletion [admin]/admin2/conf/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<log>ADMIN: $admin has kicked $player ($data)</log>
</group>
<group action="mute" r="255" g="0" b="0">
<all>$player has been muted by $admin.</all>
<all>$player has been muted by $admin ($data).</all>
<log>ADMIN: $admin has muted $player</log>
</group>
<group action="unmute" r="0" g="255" b="100">
Expand Down
1 change: 1 addition & 0 deletions [admin]/admin2/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<script src="client/widgets/admin_warp.lua" type="client" cache="false"/>
<script src="client/widgets/admin_report.lua" type="client" cache="false"/>
<script src="client/widgets/admin_weapon.lua" type="client" cache="false"/>
<script src="client/widgets/admin_mute.lua" type="client" cache="false"/>

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

Expand Down
26 changes: 23 additions & 3 deletions [admin]/admin2/server/admin_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,31 @@ aFunctions = {
["ban"] = function(player, data)
setTimer(banPlayer, 100, 1, player, true, true, true, client, data)
end,
["mute"] = function(player)
setPlayerMuted(player, true)
["mute"] = function(player, data)
if (not data or not data.duration) then
return
end

if isPlayerMuted(player) then
return
end

local time
if data.duration == 0 then
time = "Permanent"
else
time = secondsToTimeDesc(data.duration)
end

aSetPlayerMuted(player, true, data.duration)
return true, time
end,
["unmute"] = function(player)
setPlayerMuted(player, false)
if not isPlayerMuted(player) then
return
end

aSetPlayerMuted(player, false)
end,
["freeze"] = function(player)
local vehicle = getPedOccupiedVehicle(player)
Expand Down
Loading