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

TalkAction [TFS 1.0] Custom ban command with ban length and reason

rsdsebek

C++/LUA coder
Joined
Oct 8, 2008
Messages
128
Reaction score
30
Hi,
Recently I wrote ban window for my project, so this command isn't longer compatible with my TFS, though it's fully compatible with the newest stock TFS 1.0 revision - so I'm sharing ;)
Create new file called "customban.lua" in /data/talkactions/scripts directory:
Code:
function onSay(cid, words, param)
    local player = Player(cid)
    if player:getGroup():getId() < 5 then
        return false
    end
  
    local split = param:split(",")
    if split[1] ~= nil then
        local accountId = getAccountNumberByPlayerName(split[1])
        if accountId > 0 then
            local comment = ""
            if split[2] == nil then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Usage: /ban Nick, days, reason\nFor example: /ban Goku Saiyan, 20, Bug abuse")
                return false
            elseif isNumber(split[2]) == false then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Usage: /ban Nick, days, reason\nFor example: /ban Goku Saiyan, 20, Bug abuse")
                return false
            end
            if split[3] ~= nil then
                comment = split[3]
            end
        else
            player:sendCancelMessage("Player with name " .. split[1] .. " doesn't exist.")
            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 targetCid = getPlayerByName(split[1])
        local timeNow = os.time()
        local queryBool = db:query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" .. accountId .. "," .. "'" .. tostring(split[3]) .. "'" ..", " .. timeNow .. ", " .. timeNow + (split[2] * 86400) .. ", " .. getPlayerGUIDByName(getCreatureName(cid)) .. ")")

        if queryBool == true then
            if targetCid ~= false then
                doRemoveCreature(targetCid)
            end
            broadcastMessage("" .. split[1] .. " was banished because of " .. split[3] .. " for " .. split[2] .. " days.", 17)          
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Usage: /ban Nick, days, reason\nFor example: /ban Goku Saiyan, 20, Bug abuse")
        end
    end  
end
then add this line to /data/talkactions/talkactions.xml file:
Code:
<talkaction words="/customban" separator=" " script="customban.lua" />

Usage of the command: /customban nick, days, reason.

Enjoy! :D

My best,
Sebastian
 
Last edited:
Back
Top