xXGhostXx Posted May 1, 2019 Share Posted May 1, 2019 Hi . I making ban system and i have a problem for make ban time ! i use mySQL ! and i created banBy - banReason just i cant make ban time ! like : /aban <Name> <Time> <Reason> Whats your idea for make ban time ? i want admin press day number and player ban from the server when player ban time is finished player can go to server Link to comment
XaskeL Posted May 1, 2019 Share Posted May 1, 2019 use timestamp getRealTime().timestamp + (86400*31) // 31 day, 1 day = 86400 sec addEventHandler("onPlayerLogin", root, function(previousAccount, account) if timestamp in server < timestamp in db then return kickPlayer(source) end end) Link to comment
xXGhostXx Posted May 1, 2019 Author Share Posted May 1, 2019 7 minutes ago, XaskeL said: use timestamp getRealTime().timestamp + (86400*31) // 31 day, 1 day = 86400 sec addEventHandler("onPlayerLogin", root, function(previousAccount, account) if timestamp in server < timestamp in db then return kickPlayer(source) end end) bro you can make example for this function ? Link to comment
Overkillz Posted May 1, 2019 Share Posted May 1, 2019 12 minutes ago, xXGhostXx said: bro you can make example for this function ? Practically he gave you the whole code. Merge it with your "supossed DB Code" and it should be done. Link to comment
SaNoR Posted May 1, 2019 Share Posted May 1, 2019 Something like this function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end function aBan(source, cmd, nickname, time, ...) if (hasObjectPermissionTo(source, "function.banPlayer", false)) then time = tonumber(time) if nickname and time then local b_player, b_serial, b_time, b_reason = getPlayerFromPartialName(nickname), "", 1, "" if isElement(b_player) then b_serial = getPlayerSerial(b_player) b_time = getRealTime().timestamp + (time * 86400) if #{...} ~= 0 then b_reason = table.concat({...}, " ") end if kickPlayer(b_player, source, b_reason) then -- INSERT TO MYSQL b_serial, b_time, b_reason outputChatBox(getPlayerName(b_player).." has been banned by "..getPlayerName(source)..". ("..time.." day"..(time == 1 and ")" or "s)"), root, 255, 0, 0) end end else outputChatBox("/aban [Nickname] [Days] [Reason]", source, 255, 0, 0) end end end addCommandHandler("aban", aBan) addEventHandler("onPlayerJoin", root, function() local serial = getPlayerSerial(source) -- SELECT PLAYER SERIAL FROM DB if #result ~= 0 then -- IF FOUND if getRealTime().timestamp < result.b_time then kickPlayer(source, os.date("%Y-%m-%d %H:%M:%S", result.b_time)) end end end) 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