ClearChatBox: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(rework examples section)
 
(2 intermediate revisions by 2 users not shown)
Line 23: Line 23:
</section>
</section>


==Example==  
==Example==
<section name="Client" class="client" show="true">
<section name="Server" class="server" show="true">
This example removes spam caused by outputChatBox
This example adds an admin command to clear the chatbox for everyone
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
for i=1,10 do
function cmdClearChat(p, cmd)
  outputChatBox( "spam ..." )
    if not isPlayerStaff(p) then return end
    clearChatBox()
end
end
addCommandHandler("clearchat", cmdClearChat)


clearChatBox()
-- Utility function
outputChatBox("Chat cleared successfully!")
local staffACLs = {
</syntaxhighlight>
    aclGetGroup("Admin"),
</section>
    aclGetGroup("Moderator")
}


<section name="Server" class="server" show="false">
function isPlayerStaff(p)
This example deletes messages for all players
if isElement(p) and getElementType(p) == "player" and not isGuestAccount(getPlayerAccount(p)) then
<syntaxhighlight lang="lua">
local object = getAccountName(getPlayerAccount(p))
 
local players = getElementsByType('player')


for k, v in pairs(players) do
for _, group in ipairs(staffACLs) do
  clearChatBox(v)
if isObjectInACLGroup("user." .. object, group) then
return true
end
end
end
return false
end
end
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 04:42, 30 October 2021

This function clears the chatbox. It does not clear the console (F8)

Syntax

Click to collapse [-]
Client
bool clearChatBox ()

Returns

Returns true if the player's chat was cleared successfully, false otherwise.

Click to collapse [-]
Server
bool clearChatBox ( [ element clearFor = getRootElement() ])

Required Arguments

  • clearFor : The player whose chat is to be cleared. By default, this is set to the root element, which will affect all players.

Returns

Returns true if the player's chat was cleared successfully, false otherwise.

Example

Click to collapse [-]
Server

This example adds an admin command to clear the chatbox for everyone

function cmdClearChat(p, cmd)
    if not isPlayerStaff(p) then return end
    clearChatBox()
end
addCommandHandler("clearchat", cmdClearChat)

-- Utility function
local staffACLs = {
    aclGetGroup("Admin"),
    aclGetGroup("Moderator")
}

function isPlayerStaff(p)
	if isElement(p) and getElementType(p) == "player" and not isGuestAccount(getPlayerAccount(p)) then
		local object = getAccountName(getPlayerAccount(p))

		for _, group in ipairs(staffACLs) do
			if isObjectInACLGroup("user." .. object, group) then
				return true
			end
		end
	end
	return false
end

See Also