Jump to content

ban system


Snow-Man

Recommended Posts

hey can you help me to fix my ban system?

bansTable = {}
function addBanPlayer(admin, player, reason, time)
	if not admin or not player or type(reason) ~= "string" or type(time) ~= "number"  then
		return false
	end
	
	timer = math.floor(time)
	if (timer < 0 and timer ~= -1) then
		return false
	end
	for _, v in pairs(bansTable) do
		if (v[1] == admin) then
			return false
		end
			local timer = getRealTime().timestamp+timer
			
	exports.USCsql:exec("INSERT INTO `bans` (`admin`, `player`, `reason`, `duration`, `IP`) VALUES (?, ?, ?, ?)", admin, player, reason, timer, getPlayerIP(player) )
	table.insert(bansTable, {admin, player, reason, timer, ip})
	
end
end

 

Link to comment

when i ban someone it doesn't work,

i mean when someone join to server

function checkPIFBanned()
		if isPlayerBanned(getPlayerIP(source)) then
			local ban = exports.USCsql:queryData("SELECT `admin`,`player`,`reason`,`duration` FROM `bans` WHERE `IP`=?", getPlayerSerial(source))
			triggerClientEvent(source, "drawDXBanScreen", source, ban.admin, ban.player, ban.reason, ban.duration)
		end
	end
addEventHandler("onPlayerJoin", root, checkPIFBanned)

 

Link to comment

i'm not sure but try this 

function checkPIFBanned()
		if isPlayerBanned(getPlayerIP(source)) then
			local ban = exports.USCsql:queryData("SELECT `admin`,`player`,`reason`,`duration` FROM `bans` WHERE `IP`=?", getPlayerSerial(source))
			for i, v in ipairs(ban) do
			triggerClientEvent(source, "drawDXBanScreen", source, {v["admin"], v["player"], v["reason"], v["duration"]})
			end
		end
	end
addEventHandler("onPlayerJoin", root, checkPIFBanned)

 

Edited by Best-Killer
Link to comment

dbQuery returns a table like this:

result = { { key = value } }

even if you get a single row use result[1]. In your case it would be ban[1].

However, that's just a guess.

Why are you using the column name IP and you store player's serial in it? I'd recommend to rename the column to serial so people know what's stored inside it.

Link to comment
8 minutes ago, Snow-Man said:

i have made function to check if player banned or no

is it incorrect idea about coding?

At the top you inserted player ip in this column so why you check the serial instead of ip if u used that before ?

Edited by MR.GRAND
Link to comment
3 minutes ago, Snow-Man said:

i just want to get if player banned then draw text and cancel login

Try this

 

function checkPIFBanned()
		if isPlayerBanned(getPlayerIP(source)) then
			local ban = exports.USCsql:queryData("SELECT `admin`,`player`,`reason`,`duration` FROM `bans` WHERE `IP`=?", getPlayerIP(source))
			triggerClientEvent(source, "drawDXBanScreen", source, ban[1]['admin'], ban[1]['player'], ban[1]['reason'], ban[1]['duration'])
		end
	end
addEventHandler("onPlayerJoin", root, checkPIFBanned)

 

Link to comment
On 12/28/2016 at 10:09 PM, MR.GRAND said:

Try this

 


function checkPIFBanned()
		if isPlayerBanned(getPlayerIP(source)) then
			local ban = exports.USCsql:queryData("SELECT `admin`,`player`,`reason`,`duration` FROM `bans` WHERE `IP`=?", getPlayerIP(source))
			triggerClientEvent(source, "drawDXBanScreen", source, ban[1]['admin'], ban[1]['player'], ban[1]['reason'], ban[1]['duration'])
		end
	end
addEventHandler("onPlayerJoin", root, checkPIFBanned)

 

thank you, that's works :)

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...