Mais organizado e com um salve de registro em logs:
function onSay(cid, words, param, channel)
local t = string.explode(param, ",")
if #t < 3 then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Digite /ban nome, dias, motivo.")
return true
end
local name, days, motivo = t[1], tonumber(t[2]), t[3]
local acc = getAccountIdByName(name)
if acc ~= 0 then
local tempo = days * 24 * 3600
local target = getCreatureByName(name)
if target then
doAddAccountBanishment(acc, target, os.time() + tempo, 5, 2, "Você foi banido por " .. motivo .. ", por " .. tempo .. " segundos.", 0)
doBroadcastMessage("O jogador " .. getCreatureName(target) .. " foi banido por " .. getCreatureName(cid) .. ". Motivo: " .. motivo .. ".", 25)
addEvent(doRemoveCreature, 3 * 1000, target, true)
-- Registro no arquivo de log
local bansFile = "data/logs/bans.txt"
local playerName = getCreatureName(cid)
local currentTime = os.date("%Y-%m-%d %H:%M:%S")
local file = io.open(bansFile, "a")
if file then
file:write(currentTime .. " - " .. playerName .. " baniu " .. name .. " por " .. days .. " dias. Motivo: " .. motivo .. "\n")
file:close()
else
print("Erro ao abrir o arquivo de log de bans.")
end
return true
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Jogador não encontrado.")
return true
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Jogador não encontrado.")
return true
end
end
Creditos: Odranoel