From e85007c395f2e72bed9f82d3fa13c41fc9f3b005 Mon Sep 17 00:00:00 2001 From: Falco Peijnenburg Date: Thu, 27 Jul 2023 21:38:49 +0200 Subject: [PATCH] Merged FPP --- gamemode/modules/fpp/pp/client/hud.lua | 15 ++++---- gamemode/modules/fpp/pp/server/antispam.lua | 40 +++++++++++++++------ gamemode/modules/fpp/pp/server/settings.lua | 6 ++-- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/gamemode/modules/fpp/pp/client/hud.lua b/gamemode/modules/fpp/pp/client/hud.lua index 0aea7ba86..f9f54dbc2 100644 --- a/gamemode/modules/fpp/pp/client/hud.lua +++ b/gamemode/modules/fpp/pp/client/hud.lua @@ -41,13 +41,14 @@ local HUDNote_c = 0 local HUDNote_i = 1 local HUDNotes = {} ---Notify ripped off the Sandbox notify, changed to my likings -function FPP.AddNotify( str, type ) +-- Notify ripped off the Sandbox notify, changed to my likings +function FPP.AddNotify(str, type, total_time) local tab = {} tab.text = str tab.recv = SysTime() tab.velx = 0 tab.vely = -5 + tab.time_visible = total_time ~= 0 and total_time or 6 surface_SetFont( "TabLarge" ) local w = surface_GetTextSize( str ) @@ -72,7 +73,7 @@ function FPP.AddNotify( str, type ) ply:EmitSound("npc/turret_floor/click1.wav", 10, 100) end -usermessage.Hook("FPP_Notify", function(u) FPP.AddNotify(u:ReadString(), u:ReadBool()) end) +usermessage.Hook("FPP_Notify", function(u) FPP.AddNotify(u:ReadString(), u:ReadBool(), u:ReadFloat()) end) local function DrawNotice(k, v, i) @@ -104,15 +105,15 @@ local function DrawNotice(k, v, i) local ideal_y = ScrH() - (HUDNote_c - i) * h local ideal_x = ScrW() / 2 + w * 0.5 + (ScrW() / 20) - local timeleft = 6 - (SysTime() - v.recv) + local timeleft = v.time_visible - (SysTime() - v.recv) -- Cartoon style about to go thing - if (timeleft < 0.8) then + if (timeleft < 0.5) then ideal_x = ScrW() / 2 + w * 0.5 + 200 end -- Gone! - if (timeleft < 0.5) then + if (timeleft < 0.2) then ideal_y = ScrH() + 50 end @@ -176,7 +177,7 @@ local function HUDPaint() end for k, v in pairs(HUDNotes) do - if v ~= 0 and v.recv + 6 < SysTime() then + if v ~= 0 and v.recv + v.time_visible < SysTime() then HUDNotes[ k ] = 0 HUDNote_c = HUDNote_c - 1 if (HUDNote_c == 0) then HUDNotes = {} end diff --git a/gamemode/modules/fpp/pp/server/antispam.lua b/gamemode/modules/fpp/pp/server/antispam.lua index 6cb459f20..fe01fb80f 100644 --- a/gamemode/modules/fpp/pp/server/antispam.lua +++ b/gamemode/modules/fpp/pp/server/antispam.lua @@ -55,27 +55,45 @@ function FPP.AntiSpam.CreateEntity(ply, ent, IsDuplicate) -- I power by ten because the volume of a prop can vary between 65 and like a few billion if tobool(FPP.Settings.FPP_ANTISPAM1.bigpropantispam) and phys:GetVolume() and phys:GetVolume() > math.pow(10, FPP.Settings.FPP_ANTISPAM1.bigpropsize) and not string.find(class, "constraint") and not string.find(class, "hinge") and not string.find(class, "magnet") and not string.find(class, "collision") and not blacklist[class] then + ply.FPPAntispamBigProp = ply.FPPAntispamBigProp or 0 + ply.FPPAntiSpamLastBigProp = ply.FPPAntiSpamLastBigProp or 0 if not IsDuplicate then - ply.FPPAntispamBigProp = (ply.FPPAntispamBigProp or 0) + 1 - timer.Simple(10 * FPP.Settings.FPP_ANTISPAM1.bigpropwait, function() - if not ply:IsValid() then return end - ply.FPPAntispamBigProp = ply.FPPAntispamBigProp or 0 - ply.FPPAntispamBigProp = math.Max(ply.FPPAntispamBigProp - 1, 0) - end) + ply.FPPAntispamBigProp = ply.FPPAntispamBigProp + 1 end - if ply.FPPAntiSpamLastBigProp and ply.FPPAntiSpamLastBigProp > (CurTime() - (FPP.Settings.FPP_ANTISPAM1.bigpropwait * ply.FPPAntispamBigProp)) then - FPP.Notify(ply, "Please wait " .. FPP.Settings.FPP_ANTISPAM1.bigpropwait * ply.FPPAntispamBigProp .. " Seconds before spawning a big prop again", false) - ply.FPPAntiSpamLastBigProp = CurTime() + local curTime = CurTime() + local spawningBlockedUntil = + ply.FPPAntiSpamLastBigProp + ply.FPPAntispamBigProp * FPP.Settings.FPP_ANTISPAM1.bigpropwait + + if curTime < spawningBlockedUntil then + -- The current attempt would have been blocked until + -- spawningBlockedUntil. The next attempt will add up to that time. + -- The wait time is thus the time the user should wait before the + -- next attempt. + local waitTime = spawningBlockedUntil + FPP.Settings.FPP_ANTISPAM1.bigpropwait - curTime + FPP.Notify( + ply, + "Please wait " .. math.Round(waitTime, 2) .. " Seconds before spawning a big prop again", + false, + waitTime + ) ent:Remove() return end if not IsDuplicate then - ply.FPPAntiSpamLastBigProp = CurTime() + ply.FPPAntiSpamLastBigProp = curTime + -- Spawning succeeded, reset big prop count to 0 + ply.FPPAntispamBigProp = 0 end + local waitTime = FPP.Settings.FPP_ANTISPAM1.bigpropwait FPP.AntiSpam.GhostFreeze(ent, phys) - FPP.Notify(ply, "Your prop is ghosted because it is too big. Interract with it to unghost it.", true) + FPP.Notify( + ply, + "Your prop is ghosted because it is too big. Interract with it to unghost it.", + true, + waitTime + ) return end diff --git a/gamemode/modules/fpp/pp/server/settings.lua b/gamemode/modules/fpp/pp/server/settings.lua index d438d0695..2fdac4f8c 100644 --- a/gamemode/modules/fpp/pp/server/settings.lua +++ b/gamemode/modules/fpp/pp/server/settings.lua @@ -21,7 +21,7 @@ FPP.RestrictedToolsPlayers = FPP.RestrictedToolsPlayers or {} FPP.Groups = FPP.Groups or {} FPP.GroupMembers = FPP.GroupMembers or {} -function FPP.Notify(ply, text, bool) +function FPP.Notify(ply, text, bool, total_time) if ply:EntIndex() == 0 then ServerLog(text) return @@ -29,14 +29,16 @@ function FPP.Notify(ply, text, bool) umsg.Start("FPP_Notify", ply) umsg.String(text) umsg.Bool(bool) + umsg.Float(total_time or 6) umsg.End() ply:PrintMessage(HUD_PRINTCONSOLE, text) end -function FPP.NotifyAll(text, bool) +function FPP.NotifyAll(text, bool, total_time) umsg.Start("FPP_Notify") umsg.String(text) umsg.Bool(bool) + umsg.Float(total_time or 6) umsg.End() for _, ply in ipairs(player.GetAll()) do ply:PrintMessage(HUD_PRINTCONSOLE, text)