• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Talkaction with check words

CastorFlynn

Member
Joined
Aug 29, 2021
Messages
70
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()
 

Evil Puncker

I know nothing
TFS Developer
Joined
May 30, 2009
Messages
8,509
Solutions
260
Reaction score
4,467
OP
OP
C

CastorFlynn

Member
Joined
Aug 29, 2021
Messages
70
Reaction score
8

Boy67

Veteran OT User
Joined
Jul 4, 2007
Messages
468
Solutions
26
Reaction score
371
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()
 
OP
OP
C

CastorFlynn

Member
Joined
Aug 29, 2021
Messages
70
Reaction score
8
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.
 
Top