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

Lua TFS 1.3 antibot

Dorianek

Member
Joined
Nov 29, 2018
Messages
247
Reaction score
10
Location
Poland
Hello, how can I change the following script so that the ban time lasts 45 minutes? Thank you in advance for your help and best regards

Lua:
ANTIBOT = {
    prefix = "[AntiBot] ",
    questions = {
        {question = "What year did COVID-19 start?", staticAnswer = true, answer = "2019"},
        {question = "What is your current Sword skill?", skill = true, answer = SKILL_SWORD},
        {question = "What is your current club skill?", skill = true, answer = SKILL_CLUB},
        {question = "What is your current Distance skill?", skill = true, answer = SKILL_DISTANCE},
        {question = "What is your current level?", answer = "level"},
        {question = "What day is it today?", answer = "day"},
    },
    playerQuestion = {},
    messages = {
        time = "You have %s to answer the question.",
        chat = "This chat can only be used during verification.",
        howAnswer = "You must answer only the answer, for example: What day is it today? Reply: %d",
        correctAnswer = "You got the question right. Thanks.",
        incorrectAnswer = "You got the answer wrong, you still have %d attempts.",
        logout = "You cannot hang up while there is an active check.",
    },
    punishment = {
        try = {
            max = 3,
            reason = "Too many attempts.",
            timePunishment = 1, -- In days
            players = {},
        },
        time = {
            maxTime = 180, -- In seconds
            reason = "Didn't answer the question within the allotted time.",
            timePunishment = 2, -- In days
            players = {},
        },
    },
    notUseOnTrainers = false, -- True = training players will not be checked
    notUseOnPz = false, -- True = players on pz will not be checked
    verification = {20, 40}, -- 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 (ANTIBOT.notUseOnPz) and (Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE)) then
        ANTIBOT:reset(playerId)
        return false
    end

    if ANTIBOT.notUseOnTrainers and staminaBonus.events[player:getName()] then
        ANTIBOT:reset(playerId)
        return false
    end

    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
 
This script is mine haha, happy to see someone using it.

Lua:
ANTIBOT = {
    prefix = "[AntiBot] ",
    questions = {
        {question = "What year did COVID-19 start?", staticAnswer = true, answer = "2019"},
        {question = "What is your current Sword skill?", skill = true, answer = SKILL_SWORD},
        {question = "What is your current club skill?", skill = true, answer = SKILL_CLUB},
        {question = "What is your current Distance skill?", skill = true, answer = SKILL_DISTANCE},
        {question = "What is your current level?", answer = "level"},
        {question = "What day is it today?", answer = "day"},
    },
    playerQuestion = {},
    messages = {
        time = "You have %s to answer the question.",
        chat = "This chat can only be used during verification.",
        howAnswer = "You must answer only the answer, for example: What day is it today? Reply: %d",
        correctAnswer = "You got the question right. Thanks.",
        incorrectAnswer = "You got the answer wrong, you still have %d attempts.",
        logout = "You cannot hang up while there is an active check.",
    },
    punishment = {
        try = {
            max = 3,
            reason = "Too many attempts.",
            timePunishment = 1, -- In days
            players = {},
        },
        time = {
            maxTime = 180, -- In seconds
            reason = "Didn't answer the question within the allotted time.",
            timePunishment = 2700, -- In seconds
            players = {},
        },
    },
    notUseOnTrainers = false, -- True = training players will not be checked
    notUseOnPz = false, -- True = players on pz will not be checked
    verification = {20, 40}, -- 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 (ANTIBOT.notUseOnPz) and (Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE)) then
        ANTIBOT:reset(playerId)
        return false
    end

    if ANTIBOT.notUseOnTrainers and staminaBonus.events[player:getName()] then
        ANTIBOT:reset(playerId)
        return false
    end

    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) .. ", " .. 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) .. ", " .. player:getGuid() .. ")")
    end

    ANTIBOT:reset(playerId)
    player:save()
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    player:remove()
end

Try this way
 
Back
Top