Jump to content

Mute Player onClientGUIClick with timer.


Om.

Recommended Posts

function mutePlayer(button)
  if button == "left" then
    if (source == playerTab.button[2]) then
      player = guiGridListGetSelectedItemText(GUIEditor.gridlist[1])
      time = guiGetText(playerTab.combobox[1])
      reason = guiGetText(playerTab.edit[1])
      thePlayer = getPlayerFromName(player)
      if (time == "10 mins") then
        setElementData(thePlayer, "isPlayerMuted", true)
        setTimer(setElementData, 1000, 1, getPlayerFromName(player), false)
        outputChatBox("(Admin) " .. player .. " has been muted for 10 minutes by " .. getPlayerName(localPlayer) .. " for " .. reason)
      end
      guiSetVisible(playerTab.window[1], false)
      guiSetVisible(GUIEditor.window[1], true)
    end
  end
end
addEventHandler("onClientGUIClick", resourceRoot, mutePlayer)

Debug Error says: Bad argument @ 'setElementData' [Expected string at argument 2, got boolean on this line:

setTimer(setElementData, 1000, 1, getPlayerFromName(player), false)

 

Link to comment
On 21/12/2016 at 5:28 PM, Om. said:

Should be more like:

setTimer(setElementData, 60000 * 10, 1, thePlayer, "isPlayerMuted", false)

But thePlayer could easily have quit within those 10 minutes. Also your entire script is fundamentally flawed because there is no verification of permission, such things should be done server side and verify permission with hasObjectPermissionTo and there is also avoid using setElementData for important stuff like whether someone is muted unless you have server side checks to prevent that element data being changed by a client. Further reading on that here:

https://wiki.multitheftauto.com/wiki/Script_security

 

Link to comment
On 12/23/2016 at 0:05 AM, Arran said:

Should be more like:


setTimer(setElementData, 60000 * 10, 1, thePlayer, "isPlayerMuted", false)

But thePlayer could easily have quit within those 10 minutes. Also your entire script is fundamentally flawed because there is no verification of permission, such things should be done server side and verify permission with hasObjectPermissionTo and there is also avoid using setElementData for important stuff like whether someone is muted unless you have server side checks to prevent that element data being changed by a client. Further reading on that here:

https://wiki.multitheftauto.com/wiki/Script_security

 

Well, This one worked too :3 thank you

Link to comment
On 22-12-2016 at 7:35 PM, Arran said:

Should be more like:


setTimer(setElementData, 60000 * 10, 1, thePlayer, "isPlayerMuted", false)

But thePlayer could easily have quit within those 10 minutes. Also your entire script is fundamentally flawed because there is no verification of permission, such things should be done server side and verify permission with hasObjectPermissionTo and there is also avoid using setElementData for important stuff like whether someone is muted unless you have server side checks to prevent that element data being changed by a client. Further reading on that here:

https://wiki.multitheftauto.com/wiki/Script_security

 

So if I understand correctly you can do this

setTimer(mtaFunction, timeInterval, timesToExecute, [arguments for mtaFunction])

Ah yes I see so the behaviour is actually the same, it doesn't matter if it's a predefined function or selfmade. it just requires any function.

Thanks I didn't knew this actually quite logical!

Link to comment
  • MTA Anti-Cheat Team
On 22-12-2016 at 7:35 PM, Arran said:

Also your entire script is fundamentally flawed

The code isnt of good standard no, @Om. i've created a similar script (mutepanel @ https://community.multitheftauto.com/index.php?p=resources&s=details&id=13638) that's likely to be close or match to your desired end result, check my code as reference to how you could do things maybe;

SERVER:

-- Always change this to player account names you want to be a MuteMod

local authorizedMuters = {
	["AccountName1"] = true,
	["AccountName2"] = true
}

local aclGroupName = "mutepanel"

-- ## End of Settings ##

-- # Main Code # Edit with caution #
function scriptInitialize()
	-- Check/create ACL group
	local aclGroup = aclGetGroup (aclGroupName)
	if not aclGroup or aclGroup == nil then
		if not aclGroupName or type(aclGroupName) ~= "string" then return outputDebugString ("Error creating ACL group for mute panel, check configuration", 0) end
		local aclg = aclCreateGroup (aclGroupName)
		local acl = aclCreate (aclGroupName)
		aclGroup = aclg
		if acl then
			aclSetRight (acl, "command.mute", true)
			aclGroupAddACL (aclg, acl)
		else
			return outputDebugString ("Error creating ACL group for mute panel, check configuration", 0)
		end
	end

	-- Clean group of old usernames
	local list = aclGroupListObjects(aclGroup)
	if list and #list ~= 0 then
		for _,object in ipairs (list) do
			local prefix = gettok(object, 1, ".")
			if prefix == "user" then
				local user = gettok(object, 2, ".")
				if user and not authorizedMuters[user] then
					if aclGroupRemoveObject (aclGroup, object) then
						outputDebugString ("* Mute Panel: User account '"..user.."' has been removed from the ACL as it has been removed from the script", 0)
					end
				end
			end
		end
	end

	if authorizedMuters then
		for k in pairs (authorizedMuters) do
			if getAccount(k) then
				if not isObjectInACLGroup ("user."..k, aclGroup) then
					if aclGroupAddObject (aclGroup, "user."..k) then
						outputDebugString ("* Mute Panel: Added user account '"..k.."' to ACL", 0)
					end
				end
			else
				outputDebugString ("* Mute Panel: Failed to add user account '"..k.."' as it is not registered", 0)
			end
		end
	end
end
addEventHandler ("onResourceStart", resourceRoot, scriptInitialize)

function mutePanel(player)
	local account = getPlayerAccount(player)
	if account and not isGuestAccount(account) and authorizedMuters[getAccountName(account)] then
		setElementData (player, "AnonAdmin", true)
		triggerClientEvent (player, "requestMutePanel", player)
	end
end
addCommandHandler ("mp", mutePanel)

addEvent ("onMutePanelMute", true)
function requestMute(victim, reason)
	if not client or source ~= client then return end

	if not victim or not isElement(victim) then
		return outputChatBox ("* Mute Panel: Selected player no longer exists", client, 255, 30, 30)
	end

	if isPlayerMuted(victim) then
		return outputChatBox ("* Mute Panel: Selected player is already muted", client, 255, 30, 30)
	end

	triggerEvent ("aPlayer", client, victim, "mute", reason, 300)
end
addEventHandler ("onMutePanelMute", root, requestMute)

 

CLIENT:

local sx, sy = guiGetScreenSize()

addEvent ("requestMutePanel", true)
function openMutePanel()
	if isElement(mp) then return end
	showCursor(true)
	guiSetInputMode("no_binds")
	mp = guiCreateWindow(sx/2-139, sy/2-265, 278, 530, "Mute Panel", false)
	guiWindowSetSizable(mp, false)
	guiSetAlpha(mp, 0.90)

	mp_grid = guiCreateGridList(9, 79, 259, 271, false, mp)
	local playersCol = guiGridListAddColumn(mp_grid, "Players:", 0.9)

	--Fill gridlist with online players:
	if playersCol then
		for _,p in ipairs(getElementsByType("player")) do
			if p ~= localPlayer then
				local row = guiGridListAddRow (mp_grid)
				guiGridListSetItemText (mp_grid, row, playersCol, getPlayerName(p), false, false)
				guiGridListSetItemData (mp_grid, row, 1, p)
			end
		end
	end
	mp_search = guiCreateEdit(9, 47, 259, 27, "", false, mp)
	mp_searchlbl = guiCreateLabel(91, 29, 97, 18, "Search by name:", false, mp)
	guiSetFont(mp_searchlbl, "default-bold-small")
	mp_reasonlbl = guiCreateLabel(47, 360, 184, 15, "Reason (paste exact spam line):", false, mp)
	guiSetFont(mp_reasonlbl, "default-bold-small")
	guiLabelSetColor(mp_reasonlbl, 254, 0, 0)
	mp_reasonmemo = guiCreateMemo(9, 375, 258, 67, "", false, mp)
	mute = guiCreateButton(11, 449, 257, 32, "Mute", false, mp)
	guiSetProperty(mute, "NormalTextColour", "FFFD9500")
	closemp = guiCreateButton(11, 488, 257, 32, "Close Window", false, mp)
end
addEventHandler ("requestMutePanel", localPlayer, openMutePanel)

function onMPGUIClick(btn, state)
	if btn == "left" and state == "up" then
		if source == closemp then
			guiSetInputMode("allow_binds")
			if isElement(mp) then destroyElement(mp) end
			showCursor(false)
		elseif source == mute then
			local reason = guiGetText(mp_reasonmemo)
			if not reason or reason == "" or reason:len() < 3 then
				outputChatBox ("* Mute Panel: Reason needs to be at least 4 characters long", 255, 30, 30)
			else
				local r, c = guiGridListGetSelectedItem (mp_grid)
				if not r or r == -1 or not c or c == -1 then
					return outputChatBox ("* Mute Panel: Select a player from the list", 255, 30, 30)
				end
				local playerData = guiGridListGetItemData (mp_grid, r, c)
				if not playerData or not isElement(playerData) then
					return outputChatBox ("* Mute Panel: This player no longer exists", 255, 30, 30)
				end
				triggerServerEvent ("onMutePanelMute", localPlayer, playerData, reason)
			end
		end
	end
end
addEventHandler ("onClientGUIClick", root, onMPGUIClick)

function searchBarFunction()
	if source == mp_search then
		local searchText = guiGetText(mp_search)
		if searchText == "" then
			guiGridListClear(mp_grid)
			for _,p in ipairs(getElementsByType("player")) do
				if p ~= localPlayer then
					local row = guiGridListAddRow (mp_grid)
					guiGridListSetItemText (mp_grid, row, 1, getPlayerName(p), false, false)
					guiGridListSetItemData (mp_grid, row, 1, p)
				end
			end
		else
			guiGridListClear(mp_grid)
			for _,plr in ipairs(getElementsByType("player")) do
				local name = getPlayerName(plr)
				-- remove hex first:
				for i=1,3 do
					if name:find("#%x%x%x%x%x%x") then
						name = name:gsub("#%x%x%x%x%x%x", "")
					else
						break
					end
				end
				if getPlayerName(plr):lower():find(searchText:lower()) or name:lower():find(searchText:lower()) then
					local row = guiGridListAddRow(mp_grid)
					guiGridListSetItemText(mp_grid, row, 1, getPlayerName(plr), false, false)
					guiGridListSetItemData (mp_grid, row, 1, plr)
				end
			end
		end
	end
end
addEventHandler ("onClientGUIChanged", root, searchBarFunction)

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...