pa3ck Posted March 30, 2014 Share Posted March 30, 2014 Hello there, the default MTA ban system is not working the way I want it to, so I'll need to make my own ban system. The thing is, I have no clue how to even start it. If I ban somebody, how I'm going to check if the ban is over? I'll save the date and time along with the duration ( using MySQL), that's okay, but I have no idea how to check if the player is still banned. Any idea? Link to comment
WhoAmI Posted March 30, 2014 Share Posted March 30, 2014 When player connects, you are getting his serial and current time. You are converting time to timestamp and checking if it is higher than timestamp in ban, if so, you are letting him connect. That's how I see it. Link to comment
pa3ck Posted March 30, 2014 Author Share Posted March 30, 2014 What do you mean by converting it to timestamp? I don't get it. Link to comment
WhoAmI Posted March 30, 2014 Share Posted March 30, 2014 local time = getRealTime ( ) local timestamp = time.timestamp This is current time, but written in another way. Link to comment
pa3ck Posted March 30, 2014 Author Share Posted March 30, 2014 Oh, okay, thank you. I've never used timestamp before. So, when I ban someone, which timestamp would I save? How am I going to convert it with the ban length? Link to comment
WhoAmI Posted March 30, 2014 Share Posted March 30, 2014 Maybe if you are banning someone for example 24 hours, you shall add to real time those hours and convert it into timestamp. Here is the section about it http://www.lua.org/pil/22.1.html Maybe my thinking is completly bad, I don't know. Link to comment
cheez3d Posted March 30, 2014 Share Posted March 30, 2014 addCommandHandler("ban",function(player,_,target,time) local target = getPlayerFromName(target) dbExec(--[[connection_handler]],"INSERT INTO `table` (`serial`,`timestamp`) VALUES (?,?);",getPlayerSerial(target),getRealTime()["timestamp"]+time) kickPlayer(target,player,string.format("You have been banned for %d seconds.",time)) end) addEventHandler("onPlayerJoin",root,function() local serial = getPlayerSerial(source) local data = dbPoll(dbQuery(--[[connection_handler]],"SELECT COUNT(*) AS 'count' FROM `table` WHERE `serial`=?;",serial),-1) if #data[1]["count"] ~= 0 then data = dbPoll(dbQuery(--[[connection_handler]],"SELECT `timestamp` FROM `table` WHERE `serial`=?;",serial),-1) if getRealTime()["timestamp"]>=data[1]["timestamp"] then dbExec(--[[connection_handler]],"DELETE FROM `table` WHERE `serial`=?",serial) else kickPlayer(source,"Console","You are temp-banned!") end end end) Just a basic example. Link to comment
myonlake Posted March 30, 2014 Share Posted March 30, 2014 You can merge those two queries together. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now