• Ban system
    4 replies, posted
So i'm working on a ban system that stores all bans in a database but I am having trouble when it comes to the player joining and not being kicked for being banned. I'm requesting the data from the database and checking if the ban is active or not and then trying to return true or false to the CheckPassword hook. Im not sure what is wrong. All help is appreciated :) [CODE]function checkBan(sid64) local Check = db:query("SELECT * FROM bans WHERE SteamID64=".. sid64 .." AND Active=1") function Check:onSuccess(data) local row = data[1] if row == nil then print("No data") return end if row["Active"] ~= nil then return true end end function Check:onError(err) print("An error occured while executing the query: " .. err) end Check:start() end hook.Add("CheckPassword", "bans_check", function(sid64) if checkBan(sid64) then return false, "You are banned" end end)[/CODE]
Its take some time to get values from database. Try this:[code]local banned = checkBan(sid64) return not banned, "You are banned"[/code]Also, check ULX ban system.
I changed it a bit and it still does not work. [CODE]function getBanData(sid64) local Check = db:query("SELECT * FROM bans WHERE SteamID64=".. sid64 .." AND Active=1") function Check:onSuccess(data) local row = data[1] if row == nil then return end return row--, "-==You have been banned!==-\n You were banned by: (Admin)\n Length: " .. banLength(row["_Time"]) .. "\n Reason: " .. row["_Reason"] end function Check:onError(err) print("An error occured while executing the query: " .. err) end Check:start() end function checkBan(sid64) local banData, message = getBanData(sid64) if not banData then return end print(banData, message) return false, message end hook.Add("CheckPassword", "bans_check", checkBan)[/CODE]
Have you tried hooking it to playerauthed instead?
The query onSuccess is a second function that doesn't return the result to the main pool naturally. You need to do what iJohnny said, and then within that Checkban function you return the function OnSuccess
Sorry, you need to Log In to post a reply to this thread.