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

TFS 1.X+ ban script error tfs 1.2

abdala ragab

Veteran OT User
Joined
Aug 18, 2018
Messages
461
Solutions
11
Reaction score
340
Location
gamelaot.sytes.net
When I ban the player, he only gets a kick and then logs in again
What is the solution to this error?
This is the script I have

Lua:
local banDays = 7

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local name = param
    local reason = ''

    local separatorPos = param:find(',')
    if separatorPos ~= nil then
        name = param:sub(0, separatorPos - 1)
        reason = string.trim(param:sub(separatorPos + 1))
    end

    local accountId = getAccountNumberByPlayerName(name)
    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()
    db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(reason) .. ", " .. timeNow .. ", " .. timeNow + (banDays * 86400) .. ", " .. player:getGuid() .. ")")

    local target = Player(name)
    if target ~= nil then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
        target:remove()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
    end
end
 
Check this
telling my what have error
without kick&ban
Lua:
TEster has logged in.
Admin has logged in.
[Error - mysql_real_query] Query: UPDATE `accounts` SET `is_banned` = 1 WHERE `i
d` = 1597532200
Message: Unknown column 'is_banned' in 'field list'

Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/ban.lua:onSay
data/talkactions/scripts/ban.lua:39: attempt to call method 'kick' (a nil value)

stack traceback:
        [C]: in function 'kick'
        data/talkactions/scripts/ban.lua:39: in function <data/talkactions/scrip
ts/ban.lua:3>
 
open database add this
let me know

Lua:
CREATE TABLE IF NOT EXISTS `account_bans` (
  `account_id` int NOT NULL,
  `reason` varchar(255) NOT NULL,
  `banned_at` bigint NOT NULL,
  `expires_at` bigint NOT NULL,
  `banned_by` int NOT NULL,
  PRIMARY KEY (`account_id`),
  FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`banned_by`) REFERENCES `players` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;

CREATE TABLE IF NOT EXISTS `account_ban_history` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `account_id` int NOT NULL,
  `reason` varchar(255) NOT NULL,
  `banned_at` bigint NOT NULL,
  `expired_at` bigint NOT NULL,
  `banned_by` int NOT NULL,
  PRIMARY KEY (`id`),
  FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`banned_by`) REFERENCES `players` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;

must add this same
 
open database
add this and let me know
i have add
Lua:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/ban.lua:onSay
data/talkactions/scripts/ban.lua:39: attempt to call method 'kick' (a nil value)

stack traceback:
        [C]: in function 'kick'
        data/talkactions/scripts/ban.lua:39: in function <data/talkactions/scrip
ts/ban.lua:3>
 
Add now this

Lua:
local banDays = 7

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local name = param
    local reason = ''

    local separatorPos = param:find(',')
    if separatorPos then
        name = param:sub(0, separatorPos - 1)
        reason = string.trim(param:sub(separatorPos + 1))
    end

    local accountId = getAccountNumberByPlayerName(name)
    if accountId == 0 then
        return false
    end

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

    local timeNow = os.time()
    db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(reason) .. ", " .. timeNow .. ", " .. timeNow + (banDays * 86400) .. ", " .. player:getGuid() .. ")")

    local target = Player(name)
    if target then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
        target:remove()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
    end
end

have kick again ? show my your ban.cpp and iologindata.cpp
 
open ban.cpp change this

Lua:
bool Ban::acceptConnection(uint32_t clientIP)
{
    std::lock_guard<std::recursive_mutex> lockClass(lock);

    uint64_t currentTime = OTSYS_TIME();

    auto it = ipConnectMap.find(clientIP);
    if (it == ipConnectMap.end()) {
        ipConnectMap.emplace(clientIP, ConnectBlock(currentTime, 0, 1));
        return true;
    }

    ConnectBlock& connectBlock = it->second;
    if (connectBlock.blockTime > currentTime) {
        connectBlock.blockTime += 250;
        return false;
    }

    int64_t timeDiff = currentTime - connectBlock.lastAttempt;
    connectBlock.lastAttempt = currentTime;
    if (timeDiff <= 5000) {
        if (++connectBlock.count > 5) {
            connectBlock.count = 0;
            if (timeDiff <= 500) {
                connectBlock.blockTime = currentTime + 3000;
                return false;
            }
        }
    } else {
        connectBlock.count = 1;
    }
    return true;
}

bool IOBan::isAccountBanned(uint32_t accountId, BanInfo& banInfo)
{
    Database& db = Database::getInstance();

    DBResult_ptr result = db.storeQuery(fmt::format("SELECT `reason`, `expires_at`, `banned_at`, `banned_by`, (SELECT `name` FROM `players` WHERE `id` = `banned_by`) AS `name` FROM `account_bans` WHERE `account_id` = {:d}", accountId));
    if (!result) {
        return false;
    }

    int64_t expiresAt = result->getNumber<int64_t>("expires_at");
    if (expiresAt != 0 && time(nullptr) > expiresAt) {
        // Move the ban to history if it has expired
        g_databaseTasks.addTask(fmt::format("INSERT INTO `account_ban_history` (`account_id`, `reason`, `banned_at`, `expired_at`, `banned_by`) VALUES ({:d}, {:s}, {:d}, {:d}, {:d})", accountId, db.escapeString(result->getString("reason")), result->getNumber<time_t>("banned_at"), expiresAt, result->getNumber<uint32_t>("banned_by")));
        g_databaseTasks.addTask(fmt::format("DELETE FROM `account_bans` WHERE `account_id` = {:d}", accountId));
        return false;
    }

    banInfo.expiresAt = expiresAt;
    banInfo.reason = result->getString("reason");
    banInfo.bannedBy = result->getString("name");
    return true;
}

bool IOBan::isIpBanned(uint32_t clientIP, BanInfo& banInfo)
{
    if (clientIP == 0) {
        return false;
    }

    Database& db = Database::getInstance();

    DBResult_ptr result = db.storeQuery(fmt::format("SELECT `reason`, `expires_at`, (SELECT `name` FROM `players` WHERE `id` = `banned_by`) AS `name` FROM `ip_bans` WHERE `ip` = {:d}", clientIP));
    if (!result) {
        return false;
    }

    int64_t expiresAt = result->getNumber<int64_t>("expires_at");
    if (expiresAt != 0 && time(nullptr) > expiresAt) {
        g_databaseTasks.addTask(fmt::format("DELETE FROM `ip_bans` WHERE `ip` = {:d}", clientIP));
        return false;
    }

    banInfo.expiresAt = expiresAt;
    banInfo.reason = result->getString("reason");
    banInfo.bannedBy = result->getString("name");
    return true;
}

bool IOBan::isPlayerNamelocked(uint32_t playerId)
{
    return Database::getInstance().storeQuery(fmt::format("SELECT 1 FROM `player_namelocks` WHERE `player_id` = {:d}", playerId)).get() != nullptr;
}

compile let me know
 
Now check

Code:
local banDays = 7

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local name = param
    local reason = ''

    local separatorPos = param:find(',')
    if separatorPos then
        name = param:sub(0, separatorPos - 1)
        reason = string.trim(param:sub(separatorPos + 1))
    end

    local accountId = getAccountNumberByPlayerName(name)
    if accountId == 0 then
        return false
    end

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

    local timeNow = os.time()
    local expiresAt = timeNow + (banDays * 86400)

    -- Update the ban status in the player's account data
    db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(reason) .. ", " .. timeNow .. ", " .. expiresAt .. ", " .. player:getGuid() .. ")")

    local target = Player(name)
    if target then
        -- Set a custom flag or property to mark the player as banned
        target:setStorageValue("isBanned", 1)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
    end
end
 
Last edited:
Thank you for trying to help
no problem

Try this

Lua:
local banDays = 7

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local name = param
    local reason = ''

    local separatorPos = param:find(',')
    if separatorPos then
        name = param:sub(0, separatorPos - 1)
        reason = string.trim(param:sub(separatorPos + 1))
    end

    local accountId = getAccountNumberByPlayerName(name)
    if accountId == 0 then
        return false
    end

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

    local timeNow = os.time()
    local expiresAt = timeNow + (banDays * 86400)

    db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(reason) .. ", " .. timeNow .. ", " .. expiresAt .. ", " .. player:getGuid() .. ")")

    local target = Player(name)
    if target then
        if target:kick() then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Failed to ban " .. target:getName() .. ".")
        end
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
    end
end
 
Lua:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/ban.lua:onSay
data/talkactions/scripts/ban.lua:36: attempt to call method 'kick' (a nil value)

stack traceback:
        [C]: in function 'kick'
        data/talkactions/scripts/ban.lua:36: in function <data/talkactions/scrip
ts/ban.lua:3>
 
Now check

Lua:
local banDays = 7

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local name = param
    local reason = ''

    local separatorPos = param:find(',')
    if separatorPos then
        name = param:sub(0, separatorPos - 1)
        reason = string.trim(param:sub(separatorPos + 1))
    end

    local accountId = getAccountNumberByPlayerName(name)
    if accountId == 0 then
        return false
    end

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

    local timeNow = os.time()
    local expiresAt = timeNow + (banDays * 86400)

    db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(reason) .. ", " .. timeNow .. ", " .. expiresAt .. ", " .. player:getGuid() .. ")")

    local target = Player(name)
    if target then
        target:setStorageValue("isBanned", 1)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
    end
end
 
Banned Players not GM, GOD . Checking

Look now

Lua:
local banDays = 7

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local name = param
    local reason = ''

    local separatorPos = param:find(',')
    if separatorPos then
        name = param:sub(0, separatorPos - 1)
        reason = string.trim(param:sub(separatorPos + 1))
    end

    local accountId = getAccountNumberByPlayerName(name)
    if accountId == 0 then
        return false
    end

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

    local timeNow = os.time()
    local expiresAt = timeNow + (banDays * 86400)

    db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
            accountId .. ", " .. db.escapeString(reason) .. ", " .. timeNow .. ", " .. expiresAt .. ", " .. player:getGuid() .. ")")

    local target = Player(name)
    if target then
 
        target:setStorageValue("isBanned", 1)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
    end
end

this same?

show your groups.xml

Lua:
<?xml version="1.0" encoding="UTF-8"?>
<groups>
    <group id="1" name="player" flags="0" access="0" maxdepotitems="0" maxvipentries="0" />
    <group id="2" name="gamemaster" flags="137438953471" access="1" maxdepotitems="0" maxvipentries="200" />
    <group id="3" name="god" flags="272730398714" access="1" maxdepotitems="0" maxvipentries="200" />
</groups>

because if banned Game Master then only kick not banned
 
Last edited:
Back
Top