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

Lua UnBan Script..

Elexonic

Well-Known Member
Joined
Jun 18, 2008
Messages
1,920
Reaction score
59
I have one problem in my ot ... no can UNBAN players..

this is my script for ban..
Code:
function onSay(cid, words, param)
	local t = string.explode(string.lower(param), ",")
	if not t[1] then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.") return true
	end
        local player = getPlayerByNameWildcard(t[1]) 
        if(not player)then 
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player not found.") return true 
        end
        local days = not tonumber(t[2]) and 1 or tonumber(t[2])
		doBroadcastMessage(getCreatureName(player).." was banned by "..getCreatureName(cid))
		doAddIpBanishment(getPlayerIp(player), days * 24 * 60 * 60)
		doRemoveCreature(player)
		
	return true
end

And this is my script.. UNBAN..

Code:
function onSay(cid, words, param, channel)
    if(param == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
        return true
    end
 
 
    local account, tmp = getAccountIdByName(param), true
    if(account == 0) then
        account = getAccountIdByAccount(param)
        if(account == 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player or account '" .. param .. "' does not exists.")
            return true
        end
 
 
        tmp = false
    end
 
 
    local ban = getBanData(account, BAN_ACCOUNT)
    if(ban and doRemoveAccountBanishment(account)) then
        local name = param
        if(tmp) then
            name = account
        end
 
 
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, name .. " has been " .. (ban.expires == -1 and "undeleted" or "unbanned") .. ".")
    end
 
 
    if(not tmp) then
        return true
    end
 
 
    tmp = getIpByName(param)
    if(isIpBanished(getPlayerIp) and doRemoveIpBanishment(getPlayerIp)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "IP Banishment on " .. doConvertIntegerToIp(ip) .. " has been lifted.")
    end
 
 
    local guid = getPlayerGUIDByName(param, true)
    if(guid == nil) then
        return true
    end
 
 
    ban = getBanData(guid, BAN_PLAYER, PLAYERBAN_LOCK)
    if(ban and doRemovePlayerBanishment(guid, PLAYERBAN_LOCK)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Namelock from " .. param .. " has been removed.")
    end
 
 
    ban = getBanData(guid, BAN_PLAYER, PLAYERBAN_BANISHMENT)
    if(ban and doRemovePlayerBanishment(guid, PLAYERBAN_BANISHMENT)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, param .. " has been " .. (ban.expires == -1 and "undeleted" or "unbanned") .. ".")
    end
 
 
    return true
end

When using this script say..

16:16 IP Banishment on 0.0.0.0 has been lifted.

But no unbaned :S
 
First of all stop creating multiple scripts for one problem.
Second of all, use a different script.

Use this one:
Lua:
function convertSecondsToText(s)
	if s == 0 then
		return "0 seconds"
	end
	text = ""
	local days = 0
	if s >= 60*60*24 then
		days = math.floor(s / (60*60*24))
		if days == 1 then
			text = text .. "one day"
		else
			text = text .. days .. " days"
		end
		s = s % (60*60*24)
	end
	local hours = 0
	if s >= 60*60 then
		hours = math.floor(s / (60*60))
		if days > 0 then
			text = text .. ", "
		end
		if hours == 1 then
			text = text .. "one hour"
		else
			text = text .. hours .. " hours"
		end
		s = s % (60*60)
	end
	local minutes = 0
	if s >= 60 then
		minutes = math.floor(s / 60)
		if days > 0 or hours > 0 then
			text = text .. ", "
		end
		if minutes == 1 then
			text = text .. "one minute"
		else
			text = text .. minutes .. " minutes"
		end
		s = s % (60)
	end
	local seconds = s
	if days > 0 or hours > 0 or minutes > 0 and seconds > 0 then
		text = text .. " and "
	end
	if seconds == 1 then
		text = text .. "one second"
	else
		text = text .. seconds .. " seconds"
	end
	return text
end
 
function parseTime(str)
	n = tonumber(string.match(str, "(%d+)")) or 1
	t = string.match(str, "([%a%*]+)") or "d"
 
	if t == "*" or t == "forever" then
		n = 4294967295
	elseif t == "ss" or t == "serversave" then
		n = 0
	elseif t == "y" or t == "year" or t == "years" then
		n = n * 60*60*24*365
	elseif t == "m" or t == "month" or t == "months" then
		n = n * 60*60*24*30
	elseif t == "w" or t == "week" or t == "weeks" then
		n = n * 60*60*24*7
	elseif t == "d" or t == "day" or t == "days" then
		n = n * 60*60*24
	elseif t == "h" or t == "hour" or t == "hours" then
		n = n * 60*60
	elseif t == "m" or t == "min" or t == "minute" or t == "minutes" then
		n = n * 60
	else
		--n = n
	end
 
	return n
end
 
function doSendBanListMessage(creature, format)
	for v in string.gmatch(format, "$(%w+)") do
		local ss = ""
		if v == "player" then
			ss = "Player bans:\n"
			local banlist = getPlayerBanList()
			if #banlist == 0 then
				doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "No players are banned.")
			else
				for index, ban in pairs(banlist) do
					local dt = "serversave"
					if ban["expires"] > 0 then
						dt = os.date("%c", ban["expires"])
						if dt == nil then dt = "serversave" end
					end
					local bantext = "\"" .. ban["playerName"] .. "\" until " .. dt .. "\n"
					if #ss + #bantext > 250 then
						-- Can't find in one message
						doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, ss)
						ss = bantext
					else
						ss = ss .. bantext
					end
				end
			end
		elseif v == "account" then
			ss = "Account bans:\n"
			local banlist = getAccountBanList()
			if #banlist == 0 then
				doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "No accounts are banned.")
			else
				for index, ban in pairs(banlist) do
					local dt = "serversave"
					if ban["expires"] > 0 then
						dt = os.date("%c", ban["expires"])
					end
					local bantext = "#" .. ban["accountName"] .. " until " .. dt .. "\n"
					if #ss + #bantext > 250 then
						-- Can't find in one message
						doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, ss)
						ss = bantext
					else
						ss = ss .. bantext
					end
				end
			end
		elseif v == "ip" then
			ss = "IP bans:\n"
			local banlist = getIPBanList()
			if #banlist == 0 then
				doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "No IPs are banned.")
			else
				for index, ban in pairs(banlist) do
					local dt = "serversave"
					if ban["expires"] > 0 then
						dt = os.date("%c", ban["expires"])
					end
					local bantext = convertIntToIP(ban["ip"], ban["mask"]) ..
						-- The +0.0 is required to circumvent lua's shortcomings with string->number conversion
						" until " .. dt .. "\n"
					if #ss + #bantext > 250 then
						-- Can't find in one message
						doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, ss)
						ss = "\n" .. bantext
					else
						ss = ss .. bantext
					end
				end
			end
		end
		if string.find(ss, "\n", string.find(ss, "\n") + 1) then doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, ss) end
	end
end
 
function doBanPlayerChild(creature)
	doRemoveCreature(creature)
end
 
function doBanPlayer(gm, creature)
	local access = getPlayerAccess(creature)
	if access ~= LUA_ERROR and access < 2 then
		return
	end
	doPlayerSendTextMessage(creature, MESSAGE_EVENT_ADVANCE, "You have been banned.")
	addEvent(doBanPlayerChild, 1000, creature)
end
 
function onSay(creature, words, param)
	local access = getPlayerAccess(creature)
	if access ~= LUA_ERROR and access < 2 then
		return TRUE
	end
	local params = string.explode(param, ",")
	for k,v in pairs(params) do
		params[k] = v:strip_whitespace()
	end
 
	if #params == 0 then
		-- Print all bans
		doSendBanListMessage(creature, "$player $account $ip")
	elseif #params == 1 then
		if params[1] == "ip" then
			doSendBanListMessage(creature, "$ip")
		elseif params[1] == "player" or params[1] == "p" then
			doSendBanListMessage(creature, "$player")
		elseif params[1] == "account" or params[1] == "acc" or params[1] == "a" then
			doSendBanListMessage(creature, "$account")
		else
			doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "Invalid syntax.")
		end
		return TRUE
	elseif #params == 2 then
		doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "Invalid syntax.")
		return TRUE
	else -- Params greater than or equal to 3
		local op = params[1]
		if op == "add" or op == "a" or op == "r" or op == "rem" or op == "remove" then
			local do_add = op == "add" or op == "a"
			local bantype = params[2]
			local target = params[3]
 
			if bantype == "a" or bantype == "account" or bantype == "acc" then
				local accno = 0
				local isname = false
				if target:find("[^0-9]") == nil then
					-- No characters, an account number
					accno = target
				else
					-- Else a character name
					accno = getAccountNumberByPlayerName(target)
					isname = true
				end
 
				if accno ~= 0 then
					if do_add then
						local length = 0 -- Default until shutdown
						if #params >= 4 then
							length = parseTime(params[4])
						end
						players = getPlayersByAccountNumber(accno)
						for _, pid in pairs(players) do
							doBanPlayer(creature, pid)
						end
 
						local ret = addAccountBan(accno, length, getPlayerGUID(creature), "Banned using /b", 0, 0)
						if ret then
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, target .. (isname and "'s account" or "") .. " was banned " .. (length ~= 0 and (" for " .. convertSecondsToText(length)) or " until serversave") .. ".")
						else
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "No account was banned.")
						end
					else
						local ret = removeAccountBan(accno)
						if ret == TRUE then
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, target .. (isname and "'s account" or "") .. " was unbanned.")
						else
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "No account was unbanned.")
						end
					end
				else
					doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "The account does not exist.")
				end
			elseif bantype == "p" or bantype == "player" then
				local guid = getPlayerGUIDByName(target)
				if guid ~= 0 then
					if do_add then
						local length = 0 -- Default until shutdown
						if #params >= 4 then
							length = parseTime(params[4])
						end
						pid = getPlayerByName(target)
						if pid ~= 0 then
							doBanPlayer(creature, pid)
						end
						local ret = addPlayerBan(target, length, getPlayerGUID(creature), "Banned using /b", 0, 0)
						if ret then
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, target .. " was banned " .. (length ~= 0 and ("for " .. convertSecondsToText(length)) or " until serversave") .. ".")
						else
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "No player was banned.")
						end
					else
						local ret = removePlayerBan(target)
						if ret == TRUE then
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, target .. " was unbanned.")
						else
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "No player was unbanned.")
						end
					end
				else
					doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "The player does not exist.")
				end
			elseif bantype == "ip" or bantype == "i" then
				local isname = false
				local ip, mask = 0, 0
				if target:find("[^0-9x%.%:]") == nil and target:find(".") ~= nil then
					-- No characters, an ip
					ip, mask = convertIPToInt(target)
				else
					-- Else a character name
					ip = getIPByPlayerName(target)
					mask = 4294967295
					isname = true
				end
 
				if ip ~= 0 then
					if do_add then
						local length = 0 -- Default until shutdown
						if #params >= 4 then
							length = parseTime(params[4])
						end
						players = getPlayersByIPAddress(ip, mask)
						for _, pid in pairs(players) do
							doBanPlayer(creature, pid)
						end
 
						local ret = addIPBan(ip, mask, length, getPlayerGUID(creature), "Banned with /b", 0, 0)
						if ret then
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, target .. (isname and "'s IP" or "") .. " was banned " .. (length ~= 0 and (" for " .. convertSecondsToText(length)) or " until serversave") .. ".")
						else
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "No IP was banned.")
						end
					else
						if removeIPBan(ip, mask) == TRUE then
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, target .. (isname and "'s IP" or "") .. " was unbanned.")
						else
							doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "No IP was unbanned.")
						end
					end
				else
					doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "Invalid IP address.")
				end
			else
				doPlayerSendTextMessage(creature, MESSAGE_STATUS_CONSOLE_RED, "Invalid ban type.")
			end
		end
	end
	return TRUE
end

And add this in talkactions.xml

Code:
<talkaction words="/b" filter="first word" sensitive="1" script="banmanager.lua"/>

And ban people using:
Code:
/b add, player, ond
 
I create new topic in suport, where I put that nobody is looking.

as unban?
as ban player ip? a player? forever? a week?

/b add Elexonic,?

/unban?
 
Try using this query at PMA:

SQL:
CREATE TABLE `bans`
(
	`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
	`type` TINYINT(1) NOT NULL COMMENT '1 - ip banishment, 2 - namelock, 3 - account banishment, 4 - notation, 5 - deletion',
	`value` INT UNSIGNED NOT NULL COMMENT 'ip address (integer), player guid or account number',
	`param` INT UNSIGNED NOT NULL DEFAULT 4294967295 COMMENT 'used only for ip banishment mask (integer)',
	`active` TINYINT(1) NOT NULL DEFAULT TRUE,
	`expires` INT NOT NULL,
	`added` INT UNSIGNED NOT NULL,
	`admin_id` INT UNSIGNED NOT NULL DEFAULT 0,
	`comment` TEXT NOT NULL,
	`reason` INT UNSIGNED NOT NULL DEFAULT 0,
	`action` INT UNSIGNED NOT NULL DEFAULT 0,
	`statement` VARCHAR(255) NOT NULL DEFAULT '',
	PRIMARY KEY (`id`),
	KEY `type` (`type`, `value`),
	KEY `active` (`active`)
) ENGINE = InnoDB;
 
I don't have the opportunity to test this myself so I cannot verify that it will work. But you could try. :eek:

Code:
if(isIpBanished(getPlayerIp) and doRemoveIpBanishment(getPlayerIp)) then
to
Code:
if(isIpBanished([COLOR=#ff0000]tmp[/COLOR]) and doRemoveIpBanishment([COLOR=#ff0000]tmp[/COLOR])) then
 
Okay for banning players use the ban manager I gave you in earlier posts. For the unbanning:

Go to data/talkactions/sctipts and open Unban.lua and delete everything. The write this and save:

Lua:
function onSay(cid, words, param, channel)
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return true
	end

	local account, tmp = getAccountIdByName(param), true
	if(account == 0) then
		account = getAccountIdByAccount(param)
		if(account == 0) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player or account '" .. param .. "' does not exists.")
			return true
		end

		tmp = false
	end

	local ban = getBanData(account, BAN_ACCOUNT)
	if(ban and doRemoveAccountBanishment(account)) then
		local name = param
		if(tmp) then
			name = account
		end

		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, name .. " has been " .. (ban.expires == -1 and "undeleted" or "unbanned") .. ".")
	end

	if(not tmp) then
		return true
	end

	tmp = getIpByName(param)
	if(isIpBanished(tmp) and doRemoveIpBanishment(tmp)) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "IP Banishment on " .. doConvertIntegerToIp(ip) .. " has been lifted.")
	end

	local guid = getPlayerGUIDByName(param, true)
	if(guid == nil) then
		return true
	end

	ban = getBanData(guid, BAN_PLAYER, PLAYERBAN_LOCK)
	if(ban and doRemovePlayerBanishment(guid, PLAYERBAN_LOCK)) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Namelock from " .. param .. " has been removed.")
	end

	ban = getBanData(guid, BAN_PLAYER, PLAYERBAN_BANISHMENT)
	if(ban and doRemovePlayerBanishment(guid, PLAYERBAN_BANISHMENT)) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, param .. " has been " .. (ban.expires == -1 and "undeleted" or "unbanned") .. ".")
	end

	return true
end

Unban people by using
Code:
/unban NAME
 
Last edited by a moderator:
Back
Top