Jump to content

[Aide] Help Local Chat Trouble!


André Henrique

Recommended Posts

Greetings everyone, could you help me with my script? I am creating a local chat script and I am having doubts about the functions, I am creating the chat on the "T" key using the command «Say» but every time I type some command example: /kill it automatically sends to the server instead of execute it.

 

local antiAbuse = {};
local localChatInterval = get("*localChatInterval");
local localChatCommand = get("*localChatCommand");
local localChatKey = get("*localChatKey");
local distanceChat = get("distanceChat");

function string:removeHexCode()
    local s = self:gsub("#%x%x%x%x%x%x", "");
    if #s < 1 then
        return self;
    end
    return s;
end

local function localChat(responsiblePlayer, _, ...)
    local username = getPlayerName(responsiblePlayer)
    local accountid = getAccountID(getPlayerAccount(responsiblePlayer))
    if not responsiblePlayer.account.guest then
        if isPlayerMuted(responsiblePlayer) ~= false then
            return outputChatBox("#ff4c44ALERTA#f5f5f5: #ff4c44Você está mutado(a), portanto não poderá mandar mensagens..", responsiblePlayer, 255, 170, 0, true);
end;
        if antiAbuse[responsiblePlayer] ~= nil and getTickCount() - antiAbuse[responsiblePlayer] <= localChatInterval then
            antiAbuse[responsiblePlayer] = getTickCount();
            outputChatBox("#ff4c44ALERTA#f5f5f5: #ff4c44Calma "..username..".. Aguarde para poder mandar outra mensagem!", responsiblePlayer, 255, 170, 0, true);
        else
            antiAbuse[responsiblePlayer] = getTickCount();
            local localMessage = table.concat({...}, " "):removeHexCode();
            outputDebugString(("ᴄʜᴀᴛ ʟᴏᴄᴀʟ - %s("..accountid.."): %s"):format(responsiblePlayer.name:removeHexCode(), localMessage), 3, 255, 170, 0, true);
            local localPlayers = getElementsWithinRange(responsiblePlayer.position, distanceChat, "player");
            local i = 0; repeat
            i = i + 1;
            outputChatBox(("#f5f5f5* #ffff89ᴄʜᴀᴛ ʟᴏᴄᴀʟ - #f5f5f5%s("..accountid.."): #ffff89%s"):format(responsiblePlayer.name:removeHexCode(), localMessage), localPlayers[i], 255, 255, 255, true);
            until i == #localPlayers;
        end
    else
        outputChatBox("#ff4c44ALERTA#f5f5f5: #ff4c44Você precisa entrar em sua conta para poder conversar!", responsiblePlayer, 255, 170, 0, true);
    end
end

local function onPlayerJoin()
    bindKey(source, localChatKey, "down", "chatbox", localChatCommand);
end

local function onPlayerQuit()
    antiAbuse[source] = nil;
end

local function onPlayerMuted()
    antiAbuse[source] = nil;
end

local function onResourceStart()
    addCommandHandler(localChatCommand, localChat);
    local allPlayers = getElementsByType("player");
    for i = 1, #allPlayers do
        bindKey(allPlayers[i], localChatKey, "down", "chatbox", localChatCommand);
    end
    addEventHandler("onPlayerJoin", getRootElement(), onPlayerJoin);
    addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit);
    addEventHandler("onPlayerMuted", getRootElement(), onPlayerMuted);
end
addEventHandler("onResourceStart", resourceRoot, onResourceStart);

 

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...