• 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!

CreatureEvent [TFS 1.X] AntiBot

MovieBR

Member
Joined
Dec 19, 2016
Messages
16
Reaction score
15
[AntiBot]
1614685715519.png


I made this system for Thunder but I will leave it aside in this topic here for those who want to implement it in their otserv.

1614685715519.png

Create a file in the lib folder named antibot.lua
Lua:
ANTIBOT = {
    prefix = "[AntiBot] ",
    questions = {
        {question = "Qual o ano que começou o COVID-19?", staticAnswer = true, answer = "2019"},
        {question = "Qual seu skill atual de Sword?", skill = true, answer = SKILL_SWORD},
        {question = "Qual seu skill atual de Club?", skill = true, answer = SKILL_CLUB},
        {question = "Qual seu skill atual de Distance?", skill = true, answer = SKILL_DISTANCE},
        {question = "Qual seu level atual?", answer = "level"},
        {question = "Qual o dia de hoje?", answer = "day"},
    },
    playerQuestion = {},
    messages = {
        time = "Você possui %s para responder a pergunta.",
        chat = "Esse chat só pode ser usado durante a verificação.",
        howAnswer = "Você deve responder somente a resposta, por exemplo: Qual o dia de hoje? Resposta: %d",
        correctAnswer = "Você acertou a pergunta. Obrigado.",
        incorrectAnswer = "Você errou a resposta, você ainda possui %d tentativas.",
        logout = "Você não pode deslogar enquanto hover uma verificação ativa.",
    },
    punishment = {
        try = {
            max = 3,
            reason = "Quantidade excessiva de tentativas.",
            timePunishment = 1, -- In days
            players = {},
        },
        time = {
            maxTime = 180, -- In seconds
            reason = "Não respondeu a pergunta dentro do tempo estipulado.",
            timePunishment = 2, -- In days
            players = {},
        },
    },
    verification = {40, 60}, -- in minutes
}

function ANTIBOT:addTry(playerId)

    local player = Player(playerId)

    if not player then
        return false
    end

    playerId = player:getId()

    if not ANTIBOT.punishment.try.players[playerId] then
        ANTIBOT.punishment.try.players[playerId] = 0
    end

    ANTIBOT.punishment.try.players[playerId] = ANTIBOT.punishment.try.players[playerId] + 1

    if ANTIBOT.punishment.try.players[playerId] and ANTIBOT.punishment.try.players[playerId] >= ANTIBOT.punishment.try.max then
        sendChannelMessage(13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.punishment.try.reason)
        ANTIBOT:addPunishment(playerId)
    end
end

function ANTIBOT:time(playerId)
    local player = Player(playerId)

    if not player then
        ANTIBOT:reset(playerId)
        return false
    end

    playerId = player:getId()

    if not ANTIBOT.punishment.time.players[playerId] then
        ANTIBOT.punishment.time.players[playerId] = 0
        ANTIBOT:sendQuestions(playerId)
    end

    addEvent(function()
        if ANTIBOT.punishment.time.players[playerId] and ANTIBOT.punishment.time.players[playerId] >= 0 and ANTIBOT.punishment.time.players[playerId] < ANTIBOT.punishment.time.maxTime then
            ANTIBOT.punishment.time.players[playerId] = ANTIBOT.punishment.time.players[playerId] + 1
            player:sendCancelMessage(ANTIBOT.prefix .. ANTIBOT.messages.time:format(string.diff(ANTIBOT.punishment.time.maxTime - ANTIBOT.punishment.time.players[playerId], true)))
            ANTIBOT:time(playerId)
        end
    end, 1000)

    if ANTIBOT.punishment.time.players[playerId] and ANTIBOT.punishment.time.players[playerId] >= ANTIBOT.punishment.time.maxTime then
        ANTIBOT:addPunishment(playerId)
    end

end

function ANTIBOT:sendQuestions(playerId)

    local player = Player(playerId)

    if not player then
        return false
    end

    playerId = player:getId()

    random = math.random(#ANTIBOT.questions)

    ANTIBOT.playerQuestion[playerId] = random

    player:say("ANTIBOT", TALKTYPE_MONSTER_SAY)
    player:openChannel(13)
    addEvent(sendChannelMessage, 500, 13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.howAnswer:format(os.date("%d")))
    addEvent(sendChannelMessage, 800, 13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.questions[random].question)
end

function ANTIBOT:reset(playerId)
    ANTIBOT.punishment.try.players[playerId] = nil
    ANTIBOT.punishment.time.players[playerId] = nil
    ANTIBOT.playerQuestion[playerId] = nil
end

function ANTIBOT:addPunishment(playerId)

    local player = Player(playerId)
    if not player then
        return false
    end

    playerId = player:getId()

    local accountId = getAccountNumberByPlayerName(player:getName())
    if accountId == 0 then
        return false
    end

    local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId)
    if resultId ~= false then
        result.free(resultId)
        return false
    end

    local timeNow = os.time()

    if ANTIBOT.punishment.try.players[playerId] and ANTIBOT.punishment.try.players[playerId] >= ANTIBOT.punishment.try.max then
        db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(ANTIBOT.prefix .. ANTIBOT.punishment.try.reason) .. ", " .. timeNow .. ", " .. timeNow + (ANTIBOT.punishment.try.timePunishment * 86400) .. ", " .. player:getGuid() .. ")")
    elseif ANTIBOT.punishment.time.players[playerId] and ANTIBOT.punishment.time.players[playerId] >= ANTIBOT.punishment.time.maxTime then
        db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(ANTIBOT.prefix .. ANTIBOT.punishment.time.reason) .. ", " .. timeNow .. ", " .. timeNow + (ANTIBOT.punishment.time.timePunishment * 86400) .. ", " .. player:getGuid() .. ")")
    end

    ANTIBOT:reset(playerId)
    player:save()
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    player:remove()
end
Don't forget to register this lib in the lib.lua file
1614685715519.png

In the chachannels/scripts folder create a file named antibot.lua
Lua:
function onJoin(player)
    if not ANTIBOT.playerQuestion[player:getId()] then
        player:sendTextMessage(5, ANTIBOT.prefix .. ANTIBOT.messages.chat)
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    return true
end

function onLeave(player)
    if ANTIBOT.playerQuestion[player:getId()] then
        return false
    end
    return true
end


function onSpeak(player, type, message)
    if not ANTIBOT.playerQuestion[player:getId()] then
        sendChannelMessage(13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.chat)
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local question = ANTIBOT.questions[ANTIBOT.playerQuestion[player:getId()]]

    if question.skill then
        correctAnswer = tonumber(player:getSkillLevel(question.answer))
        message = tonumber(message)
    elseif question.answer == "level" then
        correctAnswer = tonumber(player:getLevel())
        message = tonumber(message)
    elseif question.answer == "day" then
        correctAnswer = tonumber(os.date("%d"))
        message = tonumber(message)
    elseif question.staticAnswer then
        message = message:lower()
        correctAnswer = question.answer:lower()
    end

    verification = false

    if message == correctAnswer then
        verification = true
    end

    if verification then
        addEvent(sendChannelMessage, 200, 13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.correctAnswer)
        ANTIBOT:reset(player:getId())
    else
        ANTIBOT:addTry(player:getId())
        addEvent(function()
            if ANTIBOT.punishment.try.players[player:getId()] and ANTIBOT.punishment.try.players[player:getId()] < ANTIBOT.punishment.try.max and player then
                sendChannelMessage(13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.incorrectAnswer:format(ANTIBOT.punishment.try.max - ANTIBOT.punishment.try.players[player:getId()]))
            end
        end, 100)
    end

    return true
end
XML:
<channel id="13" name="AntiBot" script="antibot.lua" />
1614685715519.png
Now in the creaturescripts/scripts folder create a file named antibot.lua
Lua:
function onLogin(player)

    if player:getAccountType() >= ACCOUNT_TYPE_GAMEMASTER then
        return true
    end

    player:registerEvent("AntiBot")
    checkAnti(player:getId())
    
    return true
end

function checkAnti(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end

    min, max = ANTIBOT.verification[1], ANTIBOT.verification[2]
    random = math.random(min, max)

    addEvent(function()
        ANTIBOT:time(player:getId())
        checkAnti(player:getId())
    end, random * 60 * 1000)
end
XML:
<event type="login" name="AntiBot" script="antibot.lua" />
1614685715519.png
Now in the logout.lua file in the creaturescripts/scripts folder
before return true add this
Lua:
if ANTIBOT.punishment.try.players[player:getId()] or ANTIBOT.punishment.time.players[player:getId()] then
    player:sendTextMessage(MESSAGE_INFO_DESCR, ANTIBOT.prefix .. ANTIBOT.messages.logout)
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
end
ANTIBOT:reset(player:getId())
1614685715519.png
System 100% made by me.​
 
[AntiBot]
View attachment 55694


I made this system for Thunder but I will leave it aside in this topic here for those who want to implement it in their otserv.

View attachment 55694

Create a file in the lib folder named antibot.lua
Lua:
ANTIBOT = {
    prefix = "[AntiBot] ",
    questions = {
        {question = "Qual o ano que começou o COVID-19?", staticAnswer = true, answer = "2019"},
        {question = "Qual seu skill atual de Sword?", skill = true, answer = SKILL_SWORD},
        {question = "Qual seu skill atual de Club?", skill = true, answer = SKILL_CLUB},
        {question = "Qual seu skill atual de Distance?", skill = true, answer = SKILL_DISTANCE},
        {question = "Qual seu level atual?", answer = "level"},
        {question = "Qual o dia de hoje?", answer = "day"},
    },
    playerQuestion = {},
    messages = {
        time = "Você possui %s para responder a pergunta.",
        chat = "Esse chat só pode ser usado durante a verificação.",
        howAnswer = "Você deve responder somente a resposta, por exemplo: Qual o dia de hoje? Resposta: %d",
        correctAnswer = "Você acertou a pergunta. Obrigado.",
        incorrectAnswer = "Você errou a resposta, você ainda possui %d tentativas.",
        logout = "Você não pode deslogar enquanto hover uma verificação ativa.",
    },
    punishment = {
        try = {
            max = 3,
            reason = "Quantidade excessiva de tentativas.",
            timePunishment = 1, -- In days
            players = {},
        },
        time = {
            maxTime = 180, -- In seconds
            reason = "Não respondeu a pergunta dentro do tempo estipulado.",
            timePunishment = 2, -- In days
            players = {},
        },
    },
    verification = {40, 60}, -- in minutes
}

function ANTIBOT:addTry(playerId)

    local player = Player(playerId)

    if not player then
        return false
    end

    playerId = player:getId()

    if not ANTIBOT.punishment.try.players[playerId] then
        ANTIBOT.punishment.try.players[playerId] = 0
    end

    ANTIBOT.punishment.try.players[playerId] = ANTIBOT.punishment.try.players[playerId] + 1

    if ANTIBOT.punishment.try.players[playerId] and ANTIBOT.punishment.try.players[playerId] >= ANTIBOT.punishment.try.max then
        sendChannelMessage(13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.punishment.try.reason)
        ANTIBOT:addPunishment(playerId)
    end
end

function ANTIBOT:time(playerId)
    local player = Player(playerId)

    if not player then
        ANTIBOT:reset(playerId)
        return false
    end

    playerId = player:getId()

    if not ANTIBOT.punishment.time.players[playerId] then
        ANTIBOT.punishment.time.players[playerId] = 0
        ANTIBOT:sendQuestions(playerId)
    end

    addEvent(function()
        if ANTIBOT.punishment.time.players[playerId] and ANTIBOT.punishment.time.players[playerId] >= 0 and ANTIBOT.punishment.time.players[playerId] < ANTIBOT.punishment.time.maxTime then
            ANTIBOT.punishment.time.players[playerId] = ANTIBOT.punishment.time.players[playerId] + 1
            player:sendCancelMessage(ANTIBOT.prefix .. ANTIBOT.messages.time:format(string.diff(ANTIBOT.punishment.time.maxTime - ANTIBOT.punishment.time.players[playerId], true)))
            ANTIBOT:time(playerId)
        end
    end, 1000)

    if ANTIBOT.punishment.time.players[playerId] and ANTIBOT.punishment.time.players[playerId] >= ANTIBOT.punishment.time.maxTime then
        ANTIBOT:addPunishment(playerId)
    end

end

function ANTIBOT:sendQuestions(playerId)

    local player = Player(playerId)

    if not player then
        return false
    end

    playerId = player:getId()

    random = math.random(#ANTIBOT.questions)

    ANTIBOT.playerQuestion[playerId] = random

    player:say("ANTIBOT", TALKTYPE_MONSTER_SAY)
    player:openChannel(13)
    addEvent(sendChannelMessage, 500, 13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.howAnswer:format(os.date("%d")))
    addEvent(sendChannelMessage, 800, 13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.questions[random].question)
end

function ANTIBOT:reset(playerId)
    ANTIBOT.punishment.try.players[playerId] = nil
    ANTIBOT.punishment.time.players[playerId] = nil
    ANTIBOT.playerQuestion[playerId] = nil
end

function ANTIBOT:addPunishment(playerId)

    local player = Player(playerId)
    if not player then
        return false
    end

    playerId = player:getId()

    local accountId = getAccountNumberByPlayerName(player:getName())
    if accountId == 0 then
        return false
    end

    local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId)
    if resultId ~= false then
        result.free(resultId)
        return false
    end

    local timeNow = os.time()

    if ANTIBOT.punishment.try.players[playerId] and ANTIBOT.punishment.try.players[playerId] >= ANTIBOT.punishment.try.max then
        db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(ANTIBOT.prefix .. ANTIBOT.punishment.try.reason) .. ", " .. timeNow .. ", " .. timeNow + (ANTIBOT.punishment.try.timePunishment * 86400) .. ", " .. player:getGuid() .. ")")
    elseif ANTIBOT.punishment.time.players[playerId] and ANTIBOT.punishment.time.players[playerId] >= ANTIBOT.punishment.time.maxTime then
        db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(ANTIBOT.prefix .. ANTIBOT.punishment.time.reason) .. ", " .. timeNow .. ", " .. timeNow + (ANTIBOT.punishment.time.timePunishment * 86400) .. ", " .. player:getGuid() .. ")")
    end

    ANTIBOT:reset(playerId)
    player:save()
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    player:remove()
end
Don't forget to register this lib in the lib.lua file
View attachment 55694

In the chachannels/scripts folder create a file named antibot.lua
Lua:
function onJoin(player)
    if not ANTIBOT.playerQuestion[player:getId()] then
        player:sendTextMessage(5, ANTIBOT.prefix .. ANTIBOT.messages.chat)
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    return true
end

function onLeave(player)
    if ANTIBOT.playerQuestion[player:getId()] then
        return false
    end
    return true
end


function onSpeak(player, type, message)
    if not ANTIBOT.playerQuestion[player:getId()] then
        sendChannelMessage(13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.chat)
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local question = ANTIBOT.questions[ANTIBOT.playerQuestion[player:getId()]]

    if question.skill then
        correctAnswer = tonumber(player:getSkillLevel(question.answer))
        message = tonumber(message)
    elseif question.answer == "level" then
        correctAnswer = tonumber(player:getLevel())
        message = tonumber(message)
    elseif question.answer == "day" then
        correctAnswer = tonumber(os.date("%d"))
        message = tonumber(message)
    elseif question.staticAnswer then
        message = message:lower()
        correctAnswer = question.answer:lower()
    end

    verification = false

    if message == correctAnswer then
        verification = true
    end

    if verification then
        addEvent(sendChannelMessage, 200, 13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.correctAnswer)
        ANTIBOT:reset(player:getId())
    else
        ANTIBOT:addTry(player:getId())
        addEvent(function()
            if ANTIBOT.punishment.try.players[player:getId()] and ANTIBOT.punishment.try.players[player:getId()] < ANTIBOT.punishment.try.max and player then
                sendChannelMessage(13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.incorrectAnswer:format(ANTIBOT.punishment.try.max - ANTIBOT.punishment.try.players[player:getId()]))
            end
        end, 100)
    end

    return true
end
XML:
<channel id="13" name="AntiBot" script="antibot.lua" />
View attachment 55694
Now in the creaturescripts/scripts folder create a file named antibot.lua
Lua:
function onLogin(player)

    if player:getAccountType() >= ACCOUNT_TYPE_GAMEMASTER then
        return true
    end

    player:registerEvent("AntiBot")
    checkAnti(player:getId())
 
    return true
end

function checkAnti(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end

    min, max = ANTIBOT.verification[1], ANTIBOT.verification[2]
    random = math.random(min, max)

    addEvent(function()
        ANTIBOT:time(player:getId())
        checkAnti(player:getId())
    end, random * 60 * 1000)
end
XML:
<event type="login" name="AntiBot" script="antibot.lua" />
View attachment 55694
Now in the logout.lua file in the creaturescripts/scripts folder
before return true add this
Lua:
if ANTIBOT.punishment.try.players[player:getId()] or ANTIBOT.punishment.time.players[player:getId()] then
    player:sendTextMessage(MESSAGE_INFO_DESCR, ANTIBOT.prefix .. ANTIBOT.messages.logout)
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
end
ANTIBOT:reset(player:getId())
View attachment 55694
System 100% made by me.​

It remembered a lot (even similar), with a system I made a few years ago. I believe I posted here and tibiaking. Inclusive how to use caches. (Which was what I was studying at the time).


I do it in 2017, so much similar the line of trinking xD

Did you based this code in this system? Anyway, good job!
 
Last edited:
It remembered a lot (even similar), with a system I made a few years ago. I believe I posted here and tibiaking. Inclusive how to use caches. (Which was what I was studying at the time).


I do it in 2017, so much similar the line of trinking xD

Did you based this code in this system? Anyway, good job!
I didn’t get to see your topic, a big coincidence actually, but it’s great code too.
 
it would be possible to add a check if the player is in PZ the check bot does not appear
 
if ANTIBOT.notUseOnTrainers and staminaBonus.eventsTrainer[player:getName()] then
ANTIBOT:reset(playerId)
return false
end

I changed your check to the names you used I noticed one thing if the player is stamina full he doesn't activate the event and with that the check doesn't work


idea is good but I was testing and the channel idea is complicated because it sends everyone's questions there on big servers this causes a mess
the best solution would be to open a 'private channel' but I don't think it would be that simple=\
 
Last edited:
[AntiBot]
View attachment 55694


I made this system for Thunder but I will leave it aside in this topic here for those who want to implement it in their otserv.

View attachment 55694

Create a file in the lib folder named antibot.lua
Lua:
ANTIBOT = {
    prefix = "[AntiBot] ",
    questions = {
        {question = "Qual o ano que começou o COVID-19?", staticAnswer = true, answer = "2019"},
        {question = "Qual seu skill atual de Sword?", skill = true, answer = SKILL_SWORD},
        {question = "Qual seu skill atual de Club?", skill = true, answer = SKILL_CLUB},
        {question = "Qual seu skill atual de Distance?", skill = true, answer = SKILL_DISTANCE},
        {question = "Qual seu level atual?", answer = "level"},
        {question = "Qual o dia de hoje?", answer = "day"},
    },
    playerQuestion = {},
    messages = {
        time = "Você possui %s para responder a pergunta.",
        chat = "Esse chat só pode ser usado durante a verificação.",
        howAnswer = "Você deve responder somente a resposta, por exemplo: Qual o dia de hoje? Resposta: %d",
        correctAnswer = "Você acertou a pergunta. Obrigado.",
        incorrectAnswer = "Você errou a resposta, você ainda possui %d tentativas.",
        logout = "Você não pode deslogar enquanto hover uma verificação ativa.",
    },
    punishment = {
        try = {
            max = 3,
            reason = "Quantidade excessiva de tentativas.",
            timePunishment = 1, -- In days
            players = {},
        },
        time = {
            maxTime = 180, -- In seconds
            reason = "Não respondeu a pergunta dentro do tempo estipulado.",
            timePunishment = 2, -- In days
            players = {},
        },
    },
    verification = {40, 60}, -- in minutes
}

function ANTIBOT:addTry(playerId)

    local player = Player(playerId)

    if not player then
        return false
    end

    playerId = player:getId()

    if not ANTIBOT.punishment.try.players[playerId] then
        ANTIBOT.punishment.try.players[playerId] = 0
    end

    ANTIBOT.punishment.try.players[playerId] = ANTIBOT.punishment.try.players[playerId] + 1

    if ANTIBOT.punishment.try.players[playerId] and ANTIBOT.punishment.try.players[playerId] >= ANTIBOT.punishment.try.max then
        sendChannelMessage(13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.punishment.try.reason)
        ANTIBOT:addPunishment(playerId)
    end
end

function ANTIBOT:time(playerId)
    local player = Player(playerId)

    if not player then
        ANTIBOT:reset(playerId)
        return false
    end

    playerId = player:getId()

    if not ANTIBOT.punishment.time.players[playerId] then
        ANTIBOT.punishment.time.players[playerId] = 0
        ANTIBOT:sendQuestions(playerId)
    end

    addEvent(function()
        if ANTIBOT.punishment.time.players[playerId] and ANTIBOT.punishment.time.players[playerId] >= 0 and ANTIBOT.punishment.time.players[playerId] < ANTIBOT.punishment.time.maxTime then
            ANTIBOT.punishment.time.players[playerId] = ANTIBOT.punishment.time.players[playerId] + 1
            player:sendCancelMessage(ANTIBOT.prefix .. ANTIBOT.messages.time:format(string.diff(ANTIBOT.punishment.time.maxTime - ANTIBOT.punishment.time.players[playerId], true)))
            ANTIBOT:time(playerId)
        end
    end, 1000)

    if ANTIBOT.punishment.time.players[playerId] and ANTIBOT.punishment.time.players[playerId] >= ANTIBOT.punishment.time.maxTime then
        ANTIBOT:addPunishment(playerId)
    end

end

function ANTIBOT:sendQuestions(playerId)

    local player = Player(playerId)

    if not player then
        return false
    end

    playerId = player:getId()

    random = math.random(#ANTIBOT.questions)

    ANTIBOT.playerQuestion[playerId] = random

    player:say("ANTIBOT", TALKTYPE_MONSTER_SAY)
    player:openChannel(13)
    addEvent(sendChannelMessage, 500, 13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.howAnswer:format(os.date("%d")))
    addEvent(sendChannelMessage, 800, 13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.questions[random].question)
end

function ANTIBOT:reset(playerId)
    ANTIBOT.punishment.try.players[playerId] = nil
    ANTIBOT.punishment.time.players[playerId] = nil
    ANTIBOT.playerQuestion[playerId] = nil
end

function ANTIBOT:addPunishment(playerId)

    local player = Player(playerId)
    if not player then
        return false
    end

    playerId = player:getId()

    local accountId = getAccountNumberByPlayerName(player:getName())
    if accountId == 0 then
        return false
    end

    local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId)
    if resultId ~= false then
        result.free(resultId)
        return false
    end

    local timeNow = os.time()

    if ANTIBOT.punishment.try.players[playerId] and ANTIBOT.punishment.try.players[playerId] >= ANTIBOT.punishment.try.max then
        db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(ANTIBOT.prefix .. ANTIBOT.punishment.try.reason) .. ", " .. timeNow .. ", " .. timeNow + (ANTIBOT.punishment.try.timePunishment * 86400) .. ", " .. player:getGuid() .. ")")
    elseif ANTIBOT.punishment.time.players[playerId] and ANTIBOT.punishment.time.players[playerId] >= ANTIBOT.punishment.time.maxTime then
        db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(ANTIBOT.prefix .. ANTIBOT.punishment.time.reason) .. ", " .. timeNow .. ", " .. timeNow + (ANTIBOT.punishment.time.timePunishment * 86400) .. ", " .. player:getGuid() .. ")")
    end

    ANTIBOT:reset(playerId)
    player:save()
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    player:remove()
end
Don't forget to register this lib in the lib.lua file
View attachment 55694

In the chachannels/scripts folder create a file named antibot.lua
Lua:
function onJoin(player)
    if not ANTIBOT.playerQuestion[player:getId()] then
        player:sendTextMessage(5, ANTIBOT.prefix .. ANTIBOT.messages.chat)
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    return true
end

function onLeave(player)
    if ANTIBOT.playerQuestion[player:getId()] then
        return false
    end
    return true
end


function onSpeak(player, type, message)
    if not ANTIBOT.playerQuestion[player:getId()] then
        sendChannelMessage(13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.chat)
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local question = ANTIBOT.questions[ANTIBOT.playerQuestion[player:getId()]]

    if question.skill then
        correctAnswer = tonumber(player:getSkillLevel(question.answer))
        message = tonumber(message)
    elseif question.answer == "level" then
        correctAnswer = tonumber(player:getLevel())
        message = tonumber(message)
    elseif question.answer == "day" then
        correctAnswer = tonumber(os.date("%d"))
        message = tonumber(message)
    elseif question.staticAnswer then
        message = message:lower()
        correctAnswer = question.answer:lower()
    end

    verification = false

    if message == correctAnswer then
        verification = true
    end

    if verification then
        addEvent(sendChannelMessage, 200, 13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.correctAnswer)
        ANTIBOT:reset(player:getId())
    else
        ANTIBOT:addTry(player:getId())
        addEvent(function()
            if ANTIBOT.punishment.try.players[player:getId()] and ANTIBOT.punishment.try.players[player:getId()] < ANTIBOT.punishment.try.max and player then
                sendChannelMessage(13, TALKTYPE_CHANNEL_O, ANTIBOT.prefix .. ANTIBOT.messages.incorrectAnswer:format(ANTIBOT.punishment.try.max - ANTIBOT.punishment.try.players[player:getId()]))
            end
        end, 100)
    end

    return true
end
XML:
<channel id="13" name="AntiBot" script="antibot.lua" />
View attachment 55694
Now in the creaturescripts/scripts folder create a file named antibot.lua
Lua:
function onLogin(player)

    if player:getAccountType() >= ACCOUNT_TYPE_GAMEMASTER then
        return true
    end

    player:registerEvent("AntiBot")
    checkAnti(player:getId())
  
    return true
end

function checkAnti(playerId)
    local player = Player(playerId)
    if not player then
        return false
    end

    min, max = ANTIBOT.verification[1], ANTIBOT.verification[2]
    random = math.random(min, max)

    addEvent(function()
        ANTIBOT:time(player:getId())
        checkAnti(player:getId())
    end, random * 60 * 1000)
end
XML:
<event type="login" name="AntiBot" script="antibot.lua" />
View attachment 55694
Now in the logout.lua file in the creaturescripts/scripts folder
before return true add this
Lua:
if ANTIBOT.punishment.try.players[player:getId()] or ANTIBOT.punishment.time.players[player:getId()] then
    player:sendTextMessage(MESSAGE_INFO_DESCR, ANTIBOT.prefix .. ANTIBOT.messages.logout)
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
end
ANTIBOT:reset(player:getId())
View attachment 55694
System 100% made by me.​
Its a nice system!!!
• How can I edit to close the antibot chat when player answer correctly?
• Can you explain better how works the verification time? First number is minimum and second is the maximum??
• How can I edit to receive the questions just between a specific moment of the day?
 
Last edited:
Back
Top