--// Setting ACL group.
local ACL = "Mafia"
--// Setting delay value.
local DELAY = 1000
--// Store players delay in memory server.
local cooldown = {}
--// Get player account name.
local function getPlayerAccountName(player)
local account = getPlayerAccount(player)
return getAccountName(account)
end
--// Verify if player is in ACL group.
local function isPlayerHasAcl(player, acl)
local group = aclGetGroup(acl)
local accountName = getPlayerAccountName(player)
return isObjectInACLGroup("user."..accountName, group)
end
--// Clan chat.
local function clan(player, _, ...)
--// Protect player from spamming.
local now = getTickCount()
if cooldown[player] and now - cooldown[player] < DELAY then
cancelEvent()
return outputChatBox("Please wait a moment before sending another message.", player, 255, 0, 0)
end
--// Set player delay.
cooldown[player] = now
--// Verify if player is in ACL group.
if not isPlayerHasAcl(player, ACL) then
return false
end
--// Concatenate message.
local message = table.concat({...}, " ")
if not message or message == "" then
return false
end
--// Show message to all players in the same ACL group.
local name = getPlayerName(player)
local players = getElementsByType("player")
local r, g, b = getPlayerNametagColor(player)
for i = 1, #players do
local target = players[i]
if isPlayerHasAcl(target, ACL) then
outputChatBox("[Clan]: "..name..": "..message, target, r, g, b)
end
end
return true
end
addCommandHandler("clan", clan)
--// Bind key to player on resource start.
addEventHandler("onResourceStart", resourceRoot, function()
local players = getElementsByType("player")
for i = 1, #players do
local player = players[i]
bindKey(player, "u", "down", "chatbox", "clan")
end
end)
--// Bind key to player on player login.
addEventHandler("onPlayerLogin", root, function()
bindKey(source, "u", "down", "chatbox", "clan")
end)
Hey, what's up? Honestly, I don't see any reason to implement this on the client-side. The best option is to do it on the server-side, ensuring server security against cheaters, better synchronization for all players, and other benefits. I made some improvements to your initial code.