• 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
 
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
Hello, check in the onLogin event if there is anything related to checking if the player has a ban so as not to allow them to enter the game.

You can also do a select in the "account_bans" table to see if the player's accounts have actually been banned. That is, if the ban information was stored correctly in the database.
SQL:
SELECT * FROM `account_bans`;

To check the player's account, search for the table probably called "players" , or something related to that name, it will have a column called "account_id\name", something along those lines.
SQL:
SELECT * FROM `players`;

With the "account_id" in hand, perform the following select.
SQL:
SELECT 1 FROM `account_bans` WHERE `account_id`  = 'accountIdYourFound'

If you check that the ban is being stored correctly in your database.

Your problem is probably in the onLogin event.
 
I checked the database and it's fine
What do you mean by onlogin event?
I don't know which engine you use, but there are engines that check in onLogin if the player is banned and if so, won't let them log in.

Usually the check if the player is banned takes place in the protocolgame.cpp file.

Search your project for "isAccountBanned" or something similar and check that the validation is being done correctly.
 
I don't know which engine you use, but there are engines that check in onLogin if the player is banned and if so, won't let them log in.

Usually the check if the player is banned takes place in the protocolgame.cpp file.

Search your project for "isAccountBanned" or something similar and check that the validation is being done correctly.
I didn't make any changes there and everything is identical to the original source
This is the source I used
 
ive got the same problem... anyone solved?
Test that and let me know if it works because I haven't tested that
 
Test that and let me know if it works because I haven't tested that
sorry bro, its not my problem at all. ive got another problem TFS 1.X+ - ban script error tfs 1.2 (https://otland.net/threads/ban-script-error-tfs-1-2.286516/)
 
Lua:
local banDays = 7

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

    local name, reason = param:match("^(%S+)%s*(.*)$")

    if not name or name:len() == 0 then
        return false -- Invalid parameters
    end

    local accountId = getAccountNumberByPlayerName(name)

    if accountId == 0 then
        return false -- Player not found
    end

    local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = ?", accountId)

    if resultId ~= false then
        result.free(resultId)
        return false -- Player already banned
    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 and target:isPlayer() then
        target:remove()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
    end
end

Try something like this ig.
 
Lua:
local banDays = 7

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

    local name, reason = param:match("^(%S+)%s*(.*)$")

    if not name or name:len() == 0 then
        return false -- Invalid parameters
    end

    local accountId = getAccountNumberByPlayerName(name)

    if accountId == 0 then
        return false -- Player not found
    end

    local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = ?", accountId)

    if resultId ~= false then
        result.free(resultId)
        return false -- Player already banned
    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 and target:isPlayer() then
        target:remove()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
    end
end

Try something like this ig.

Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/ban.lua:eek:nSay
data/talkactions/scripts/ban.lua:4: attempt to call method 'isGod' (a nil value)

stack traceback:
[C]: in function 'isGod'
data/talkactions/scripts/ban.lua:4: in function <data/talkactions/script
s/ban.lua:3>
 
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/ban.lua:eek:nSay
data/talkactions/scripts/ban.lua:4: attempt to call method 'isGod' (a nil value)

stack traceback:
[C]: in function 'isGod'
data/talkactions/scripts/ban.lua:4: in function <data/talkactions/script
s/ban.lua:3>
Try this not testing

Lua:
local banDays = 7

function onSay(player, words, param)
    if not player or not player:isPlayer() then
        return false
    end

    local name, reason = param:match("^(%S+)%s*(.*)$")

    if not name or name:len() == 0 then
        return false
    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()
    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 and target:isPlayer() then
        target:remove()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
    end
end
 
Try this let me know

Lua:
local banDays = 7

function onSay(player, words, param)
    if not player or not player:isPlayer() then
        print("Invalid player object.")
        return false
    end

    if not player:isGod() then
        print("You do not have the required privileges.")
        return false
    end

    local name, reason = param:match("^(%S+)%s*(.*)$")

    if not name or name:len() == 0 then
        print("Invalid parameters.")
        return false
    end

    local accountId = getAccountNumberByPlayerName(name)

    if accountId == 0 then
        print("Player not found.")
        return false
    end

    local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = ?", accountId)

    if resultId ~= false then
        result.free(resultId)
        print("Player already banned.")
        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 and target:isPlayer() then
        target:remove()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
    end
end
 
Try this let me know
Lua:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/ban.lua:onSay
data/talkactions/scripts/ban.lua:9: attempt to call method 'isGod' (a nil value)

stack traceback:
        [C]: in function 'isGod'
        data/talkactions/scripts/ban.lua:9: in function <data/talkactions/script
s/ban.lua:3>
 
Try this show my error if have

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 ~= 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 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
 
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() .. ")")

    db.query("UPDATE `accounts` SET `is_banned` = 1 WHERE `id` = " .. accountId)

    local target = Player(name)
    if target then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
        target:kick()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
    end
end
 
Check this
telling my what have error

show my your iologindata.cpp

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() .. ")")

    db.query("UPDATE `accounts` SET `is_banned` = 1 WHERE `id` = " .. accountId)

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