Jump to content

Own ban system.


pa3ck

Recommended Posts

Posted

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?

Posted

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.

Posted

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?

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

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