Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then
- --Edit here:
- local addicts = 0
- local weeks = 0
- local days = 1
- local hours = 6
- local min = 0
- local max_tries = 3 --how many times it will retry to get a players time before kicking for timeout
- local check_interval = 60 --(sec) interval for retrying
- local WhiteList = {"STEAM_0:1:7099"} --add SteamIDs here in "" seperated by ,
- local function isanywayallowed(ply)
- if ply.EV_GetRank and ply:EV_GetRank() ~= "guest" then print("!guest"); return true end
- if ply:IsAdmin() then print("admin"); return true end
- if table.HasValue(WhiteList, ply:SteamID()) then print("wl"); return true end
- --add your custom exception rules here if you're more familiar with lua
- return false
- end
- --editing down here is not recommended if you didn't even know what going on above
- local req_h = math.min(addicts*8765.8+weeks*168+days*24+hours+min/60, 8765.8 ) --can only check for 1 year so every greater value would just kick everyone
- print("/-----------------------------------\\")
- print("|Antinoob minimum required hours: "..req_h)
- print("\\----------------Uke----------------/")
- util.AddNetworkString("noobcheck_playtime")
- local function check(ply)
- --if not isanywayallowed(ply) then
- local nwstr = ""
- if ply.anoobkey == nil or ply.anoobkey == "" then
- local r = {{48,57},{65,90},{97,122}} --[%w]
- for i = 1, 7 do -- you're more likely to win the lottery
- local n = math.random(1,#r)
- nwstr = nwstr..string.char(math.random(r[n][1],r[n][2]))
- end
- else
- nwstr = ply.anoobkey
- end
- ply.anoobtry = ply.anoobtry + 1 or 1
- ply.anoobkey = nwstr
- ply:SendLua("net.Start(\"noobcheck_playtime\"); net.WriteString(\""..nwstr.."\"); net.WriteFloat(achievements.GetCount(5)); net.SendToServer()")
- print("[Antinoob] Checking: "..ply:Name().." (attempt: "..ply.anoobtry.."/"..max_tries..")")
- timer.Simple(check_interval,function()
- if ply == nil or not IsValid(ply) then return end
- if ply.noobcheckpassed ~= true and not isanywayallowed(ply) then
- if ply.anoobtry < max_tries then
- check(ply)
- else
- local name = ply:Name()
- ply:Kick("Noobcheck timed out. Try again.")
- for k, v in pairs(player.GetAll()) do
- if v ~= ply then
- v:PrintMessage(3,"Couldn't check for "..name.."'s playtime.")
- end
- end
- end
- end
- end)
- --else
- -- ply.noobcheckpassed = true
- -- but wouldnt print the time into the chat
- --end
- end
- hook.Add( "PlayerInitialSpawn", "noobcheck_spawnzhook",function(ply)
- ply.anoobtry = 0
- check(ply)
- end)
- local function can(ply)
- if ply == nil or not IsValid(ply) then return false end
- if (ply.noobcheckpassed and ply:Alive()) or isanywayallowed(ply) then return true end
- return false
- end
- --Block regular guests from spamming while dead:
- hook.Add("PlayerSpawnEffect","noobcheck",function(ply)
- if not can(ply) then return false end
- end)
- hook.Add("PlayerSpawnNPC","noobcheck",function(ply)
- if not can(ply) then return false end
- end)
- hook.Add("PlayerSpawnObject","noobcheck",function(ply)
- if not can(ply) then return false end
- end)
- hook.Add("PlayerSpawnProp","noobcheck",function(ply)
- if not can(ply) then return false end
- end)
- hook.Add("PlayerSpawnRagdoll","noobcheck",function(ply)
- if not can(ply) then return false end
- end)
- hook.Add("PlayerSpawnSENT","noobcheck",function(ply)
- if not can(ply) then return false end
- end)
- hook.Add("PlayerSpawnSWEP","noobcheck",function(ply)
- if not can(ply) then return false end
- end)
- hook.Add("PlayerSpawnVehicle","noobcheck",function(ply)
- if not can(ply) then return false end
- end)
- net.Receive( "noobcheck_playtime" , function(ley, ply)
- if ply == nil or not IsValid(ply) or ply.noobcheckpassed == true then return end
- local key = net.ReadString()
- local ti = math.floor(net.ReadFloat()/0.6)/100
- print(ply:Name().." ("..ply:SteamID()..") played GMod for "..ti.." hours. ("..req_h.."h needed to stay)")
- if (ti < req_h or ply.anoobkey != key) and not isanywayallowed(ply) then
- --local txt = "You need "..req_h.."h to play here. You've got "..ti.."h."
- local txt = "You need "..(req_h-ti).." more hours to play here."
- if ply.anoobkey != key then txt = "" end
- ply:Kick(txt)
- else
- ply.noobcheckpassed = true
- end
- --print the time for everyone:
- for k, v in pairs(player.GetAll()) do
- if v ~= nil and IsValid(v) then
- if v ~= ply then
- v:PrintMessage(3,ply:Name().." played GMod for "..ti.." hours. ("..req_h.."h needed to stay)")
- else
- v:PrintMessage(3,"You played GMod for "..ti.." hours. ("..req_h.."h needed to stay)")
- end
- end
- end
- --
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement