SHOW:
|
|
- or go back to the newest paste.
| 1 | if SERVER then | |
| 2 | ||
| 3 | --Edit here: | |
| 4 | ||
| 5 | local addicts = 0 | |
| 6 | local weeks = 0 | |
| 7 | local days = 1 | |
| 8 | local hours = 6 | |
| 9 | local min = 0 | |
| 10 | ||
| 11 | local max_tries = 3 --how many times it will retry to get a players time before kicking for timeout | |
| 12 | local check_interval = 60 --(sec) interval for retrying | |
| 13 | ||
| 14 | local WhiteList = {"STEAM_0:1:7099"} --add SteamIDs here in "" seperated by ,
| |
| 15 | ||
| 16 | local function isanywayallowed(ply) | |
| 17 | if ply.EV_GetRank and ply:EV_GetRank() ~= "guest" then print("!guest"); return true end
| |
| 18 | if ply:IsAdmin() then print("admin"); return true end
| |
| 19 | if table.HasValue(WhiteList, ply:SteamID()) then print("wl"); return true end
| |
| 20 | --add your custom exception rules here if you're more familiar with lua | |
| 21 | ||
| 22 | return false | |
| 23 | end | |
| 24 | ||
| 25 | --editing down here is not recommended if you didn't even know what going on above | |
| 26 | ||
| 27 | 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 | |
| 28 | ||
| 29 | print("/-----------------------------------\\")
| |
| 30 | print("|Antinoob minimum required hours: "..req_h)
| |
| 31 | print("\\----------------Uke----------------/")
| |
| 32 | ||
| 33 | util.AddNetworkString("noobcheck_playtime")
| |
| 34 | ||
| 35 | local function check(ply) | |
| 36 | --if not isanywayallowed(ply) then | |
| 37 | local nwstr = "" | |
| 38 | if ply.anoobkey == nil or ply.anoobkey == "" then | |
| 39 | local r = {{48,57},{65,90},{97,122}} --[%w]
| |
| 40 | for i = 1, 7 do -- you're more likely to win the lottery | |
| 41 | local n = math.random(1,#r) | |
| 42 | nwstr = nwstr..string.char(math.random(r[n][1],r[n][2])) | |
| 43 | end | |
| 44 | else | |
| 45 | nwstr = ply.anoobkey | |
| 46 | end | |
| 47 | ply.anoobtry = ply.anoobtry + 1 or 1 | |
| 48 | ply.anoobkey = nwstr | |
| 49 | ||
| 50 | ply:SendLua("net.Start(\"noobcheck_playtime\"); net.WriteString(\""..nwstr.."\"); net.WriteFloat(achievements.GetCount(5)); net.SendToServer()")
| |
| 51 | print("[Antinoob] Checking: "..ply:Name().." (attempt: "..ply.anoobtry.."/"..max_tries..")")
| |
| 52 | timer.Simple(check_interval,function() | |
| 53 | if ply == nil or not IsValid(ply) then return end | |
| 54 | if ply.noobcheckpassed ~= true and not isanywayallowed(ply) then | |
| 55 | if ply.anoobtry < max_tries then | |
| 56 | check(ply) | |
| 57 | else | |
| 58 | local name = ply:Name() | |
| 59 | ply:Kick("Noobcheck timed out. Try again.")
| |
| 60 | for k, v in pairs(player.GetAll()) do | |
| 61 | if v ~= ply then | |
| 62 | v:PrintMessage(3,"Couldn't check for "..name.."'s playtime.") | |
| 63 | end | |
| 64 | end | |
| 65 | end | |
| 66 | end | |
| 67 | end) | |
| 68 | --else | |
| 69 | -- ply.noobcheckpassed = true | |
| 70 | -- but wouldnt print the time into the chat | |
| 71 | --end | |
| 72 | end | |
| 73 | ||
| 74 | hook.Add( "PlayerInitialSpawn", "noobcheck_spawnzhook",function(ply) | |
| 75 | ply.anoobtry = 0 | |
| 76 | check(ply) | |
| 77 | end) | |
| 78 | ||
| 79 | local function can(ply) | |
| 80 | if ply == nil or not IsValid(ply) then return false end | |
| 81 | if (ply.noobcheckpassed and ply:Alive()) or isanywayallowed(ply) then return true end | |
| 82 | return false | |
| 83 | end | |
| 84 | ||
| 85 | --Block regular guests from spamming while dead: | |
| 86 | hook.Add("PlayerSpawnEffect","noobcheck",function(ply)
| |
| 87 | if not can(ply) then return false end | |
| 88 | end) | |
| 89 | hook.Add("PlayerSpawnNPC","noobcheck",function(ply)
| |
| 90 | if not can(ply) then return false end | |
| 91 | end) | |
| 92 | hook.Add("PlayerSpawnObject","noobcheck",function(ply)
| |
| 93 | if not can(ply) then return false end | |
| 94 | end) | |
| 95 | hook.Add("PlayerSpawnProp","noobcheck",function(ply)
| |
| 96 | if not can(ply) then return false end | |
| 97 | end) | |
| 98 | hook.Add("PlayerSpawnRagdoll","noobcheck",function(ply)
| |
| 99 | if not can(ply) then return false end | |
| 100 | end) | |
| 101 | hook.Add("PlayerSpawnSENT","noobcheck",function(ply)
| |
| 102 | if not can(ply) then return false end | |
| 103 | end) | |
| 104 | hook.Add("PlayerSpawnSWEP","noobcheck",function(ply)
| |
| 105 | if not can(ply) then return false end | |
| 106 | end) | |
| 107 | hook.Add("PlayerSpawnVehicle","noobcheck",function(ply)
| |
| 108 | if not can(ply) then return false end | |
| 109 | end) | |
| 110 | ||
| 111 | net.Receive( "noobcheck_playtime" , function(ley, ply) | |
| 112 | if ply == nil or not IsValid(ply) or ply.noobcheckpassed == true then return end | |
| 113 | local key = net.ReadString() | |
| 114 | local ti = math.floor(net.ReadFloat()/0.6)/100 | |
| 115 | ||
| 116 | print(ply:Name().." ("..ply:SteamID()..") played GMod for "..ti.." hours. ("..req_h.."h needed to stay)")
| |
| 117 | ||
| 118 | if (ti < req_h or ply.anoobkey != key) and not isanywayallowed(ply) then | |
| 119 | --local txt = "You need "..req_h.."h to play here. You've got "..ti.."h." | |
| 120 | local txt = "You need "..(req_h-ti).." more hours to play here." | |
| 121 | if ply.anoobkey != key then txt = "" end | |
| 122 | ply:Kick(txt) | |
| 123 | else | |
| 124 | ply.noobcheckpassed = true | |
| 125 | end | |
| 126 | --print the time for everyone: | |
| 127 | for k, v in pairs(player.GetAll()) do | |
| 128 | - | if v ~= ply then |
| 128 | + | if v ~= nil and IsValid(v) then |
| 129 | - | v:PrintMessage(3,ply:Name().." played GMod for "..ti.." hours. ("..req_h.."h needed to stay)")
|
| 129 | + | if v ~= ply then |
| 130 | - | else |
| 130 | + | v:PrintMessage(3,ply:Name().." played GMod for "..ti.." hours. ("..req_h.."h needed to stay)")
|
| 131 | - | v:PrintMessage(3,"You played GMod for "..ti.." hours. ("..req_h.."h needed to stay)")
|
| 131 | + | |
| 132 | v:PrintMessage(3,"You played GMod for "..ti.." hours. ("..req_h.."h needed to stay)")
| |
| 133 | end | |
| 134 | end | |
| 135 | end | |
| 136 | -- | |
| 137 | end) | |
| 138 | end |