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

Solved Need /ban with comment, and lenght for TFS 1.0

vichoko

Member
Joined
Oct 9, 2008
Messages
128
Reaction score
6
Location
Santiago, Chile
I'm looking for this talkaction /ban with the option to add a comment and the lenght of the ban time.
I asked for this talkaction in other forum, but i didn't got it to work; and i think that's because the script they gave me was for a older version of TFS.
Anyway i'll put it here, if someone can convert it to TFS 1.0 it could be cool.
For the other side, if someone have this talkaction that i'm looking for that is working it will be useful too :D

Thanks for reading!

Code:
<talkaction log="yes" words="/ban" access="3" event="script" value="ban.lua"/>
Code:
function onSay(cid, words, param)
local parametres = string.explode(param, ",")
if(parametres[1] ~= nil) then
local accId = getAccountIdByName(parametres[1])
if(accId > 0) then
local comment = ""
if(parametres[2] == nil) then
doPlayerSendCancel(cid, "You must enter ban days.")
return true
elseif(isNumber(parametres[2]) == false) then
doPlayerSendCancel(cid, "Ban days use only numbers.")
return true
end
if(parametres[3] ~= nil) then
comment = parametres[3]
end
doAddAccountBanishment(accId, getPlayerGUIDByName(parametres[1]), os.time() + (86400 * parametres[2]), 4, 2, comment, getPlayerGUID(cid), '')
local player = getPlayerByNameWildcard(parametres[1])
if(isPlayer(player) == TRUE) then
doRemoveCreature(player)
end
else
doPlayerSendCancel(cid, "Player with name " .. parametres[1] .. " doesn't exist.")
end
else
doPlayerSendCancel(cid, "You must enter name.")
end
return true
end
 
I remade the default TFS 1.0 ban script.

PHP:
local banDays = 7

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

    local name = param
    local reason = ''
    local banInfo = ''
    local banTime = 0
    local banMultiplier = 0
    local params = param:split(',')
    if params ~= nil then
        name = params[1]
        reason = string.trim(params[2])
        banInfo = string.trim(params[3])
    end
    if banInfo then
        if banInfo:find('h') then
            banTime = banInfo:sub(0, banInfo:find('h') - 1)
            banMultiplier = 3600
        elseif banInfo:find('d') then
            banTime = banInfo:sub(0, banInfo:find('d') - 1)
            banMultiplier = 86400
        else
            banTime = banDays
            banMultiplier = 86400
        end
        banTime = banTime * banMultiplier
    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 + banTime .. ", " .. 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

Usage:
/ban playerName, reason, time

Ban with hours duration:
/ban testName, Botting, 30h

Ban with days duration:
/ban testName, Botting, 30d
 
I remade the default TFS 1.0 ban script.

PHP:
local banDays = 7

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

    local name = param
    local reason = ''
    local banInfo = ''
    local banTime = 0
    local banMultiplier = 0
    local params = param:split(',')
    if params ~= nil then
        name = params[1]
        reason = string.trim(params[2])
        banInfo = string.trim(params[3])
    end
    if banInfo then
        if banInfo:find('h') then
            banTime = banInfo:sub(0, banInfo:find('h') - 1)
            banMultiplier = 3600
        elseif banInfo:find('d') then
            banTime = banInfo:sub(0, banInfo:find('d') - 1)
            banMultiplier = 86400
        else
            banTime = banDays
            banMultiplier = 86400
        end
        banTime = banTime * banMultiplier
    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 + banTime .. ", " .. 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

Usage:
/ban playerName, reason, time

Ban with hours duration:
/ban testName, Botting, 30h

Ban with days duration:
/ban testName, Botting, 30d
I have this error when i try to call it:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/ban.lua:onSay
data/talkactions/scripts/ban.lua:17: attempt to call field 'trim' (a nil value)
stack traceback:
    [C]: in function 'trim'
 
Back
Top