• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Talkaction with check words

CastorFlynn

Member
Joined
Aug 29, 2021
Messages
88
Reaction score
8
Is there any way to check words inside talkaction with param?

I would like something like if msgcontains return false, but talkactions doesn't accept "msg" or "message" as a function or something.

I would like to block for example /b idiot , /b stupid

Lua:
local broadcast = TalkAction("/b")

function broadcast.onSay(player, words, param)
    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    if param == "" then
        player:sendCancelMessage("Command param required.")
        return false
    end

    Spdlog.info("" .. player:getName() .. " broadcasted: ".. param)
    for _, targetPlayer in ipairs(Game.getPlayers()) do
        targetPlayer:sendPrivateMessage(player, param, TALKTYPE_BROADCAST)
    end
    return false
end

broadcast:separator(" ")
broadcast:register()
 
I'm sure TFS has its own table.contains or searching function, cant remember what it is. Either way, this is doing the exact same thing, it's just uglier :(

Lua:
local block = {"stupid", "idiot"}

local broadcast = TalkAction("/b")
function broadcast.onSay(player, words, param)
    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    if param == "" then
        player:sendCancelMessage("Command param required.")
        return false
    end
    
    local p = param:lower()
    for i = 1, #block do
        if p == block[i] then
            player:sendCancelMessage("You're naughty.")
            return false
        end
    end

    Spdlog.info("" .. player:getName() .. " broadcasted: ".. param)
    for _, targetPlayer in ipairs(Game.getPlayers()) do
        targetPlayer:sendPrivateMessage(player, param, TALKTYPE_BROADCAST)
    end
    return false
end

broadcast:separator(" ")
broadcast:register()
 
I'm sure TFS has its own table.contains or searching function, cant remember what it is. Either way, this is doing the exact same thing, it's just uglier :(

Lua:
local block = {"stupid", "idiot"}

local broadcast = TalkAction("/b")
function broadcast.onSay(player, words, param)
    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    if param == "" then
        player:sendCancelMessage("Command param required.")
        return false
    end
   
    local p = param:lower()
    for i = 1, #block do
        if p == block[i] then
            player:sendCancelMessage("You're naughty.")
            return false
        end
    end

    Spdlog.info("" .. player:getName() .. " broadcasted: ".. param)
    for _, targetPlayer in ipairs(Game.getPlayers()) do
        targetPlayer:sendPrivateMessage(player, param, TALKTYPE_BROADCAST)
    end
    return false
end

broadcast:separator(" ")
broadcast:register()

It blocks out the words only if there were just them and exactly them.
 
Back
Top