Jump to content

ban system


Snow-Man

Recommended Posts

Posted

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

 

USC Informations

Head Staff & Owner Of USC.

Youtube Channel : My Channel

350x20_FFFFFF_FFFFFF_A89999_080404.png

 

Posted

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)

 

USC Informations

Head Staff & Owner Of USC.

Youtube Channel : My Channel

350x20_FFFFFF_FFFFFF_A89999_080404.png

 

Posted (edited)

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
Posted

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.

Posted (edited)
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

 My new GCSS Script : Go 
حصريا : مود الدردشة بين السيرفرات : الذهاب

LUA progress = -100%

Join us :

 Multi Theft Auto Arab 

I'm not the best but, i'm different

Skype : kamel1234128

Someone in this world needs to remember my love .

Posted
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)

 

 My new GCSS Script : Go 
حصريا : مود الدردشة بين السيرفرات : الذهاب

LUA progress = -100%

Join us :

 Multi Theft Auto Arab 

I'm not the best but, i'm different

Skype : kamel1234128

Someone in this world needs to remember my love .

Posted
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

USC Informations

Head Staff & Owner Of USC.

Youtube Channel : My Channel

350x20_FFFFFF_FFFFFF_A89999_080404.png

 

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...