From a4b37615d96c50297b9f247a1df9a9b0cb171794 Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:11:45 -0500 Subject: [PATCH 1/5] Add legality checks to seats --- lua/acf/contraption/seats_sv.lua | 44 ++++++++++++++++++++++++++++++ lua/acf/core/globals.lua | 1 + lua/acf/menu/data_callbacks.lua | 13 ++++++++- lua/acf/menu/items_cl/settings.lua | 8 ++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 lua/acf/contraption/seats_sv.lua diff --git a/lua/acf/contraption/seats_sv.lua b/lua/acf/contraption/seats_sv.lua new file mode 100644 index 000000000..f239cf0e5 --- /dev/null +++ b/lua/acf/contraption/seats_sv.lua @@ -0,0 +1,44 @@ +-- Optional functionality for legality checking on all vehicles + +hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity) + timer.Simple(0, function() + if not IsValid(Entity) then return end + if Entity:GetClass() ~= "prop_vehicle_prisoner_pod" then return end + if Entity.fphysSeat then return end -- simfphys vehicles will make non-solid seats that should be ignored + + local PhysObj = Entity:GetPhysicsObject() + if not IsValid(PhysObj) then return end + + Entity.ACF = {} + Entity.ACF.PhysObj = PhysObj + Entity.ACF.LegalMass = PhysObj:GetMass() + Entity.ACF.Model = Entity:GetModel() + Entity.ACF.LegalSeat = true + Entity.WireDebugName = Entity.WireDebugName or (Entity.VehicleTable and Entity.VehicleTable.Name) or "ACF Legal Vehicle" + + Entity.Enable = function() + Entity.ACF.LegalSeat = true + end + + Entity.Disable = function() + Entity.ACF.LegalSeat = false + + local Driver = Entity:GetDriver() + if not IsValid(Driver) then return end + Driver:ExitVehicle() + end + PrintTable(Entity:GetTable()) + if not ACF.VehicleLegalChecks then return end + + ACF.CheckLegal(Entity) + end) +end) + +hook.Add("CanPlayerEnterVehicle", "ACF_SeatLegality", function(Player, Entity) + if not Entity.ACF then return end + + if not Entity.ACF.LegalSeat then + ACF.SendNotify(Player, false, "Seat is not legal and is currently disabled.") + return false + end +end) \ No newline at end of file diff --git a/lua/acf/core/globals.lua b/lua/acf/core/globals.lua index ea6e11c4a..2cbe1aeb8 100644 --- a/lua/acf/core/globals.lua +++ b/lua/acf/core/globals.lua @@ -10,6 +10,7 @@ do -- ACF global vars -- General Settings ACF.LegalChecks = true -- Whether or not IsLegal checks should be run on ACF entities + ACF.VehicleLegalChecks = true -- Whether or not IsLegal checks should be run on vehicle entities ACF.Year = 1945 ACF.IllegalDisableTime = 30 -- Time in seconds for an entity to be disabled when it fails ACF.IsLegal ACF.RestrictInfo = true -- If enabled, players will be only allowed to get info from entities they're allowed to mess with. diff --git a/lua/acf/menu/data_callbacks.lua b/lua/acf/menu/data_callbacks.lua index 24fbf8327..9435448e7 100644 --- a/lua/acf/menu/data_callbacks.lua +++ b/lua/acf/menu/data_callbacks.lua @@ -37,7 +37,18 @@ local Settings = { if CLIENT and not IsValid(Player) then return end - Message("Info", "Legality checks have been " .. (Bool and "enabled." or "disabled.")) + Message("Info", "Legality checks for ACF entities have been " .. (Bool and "enabled." or "disabled.")) + end, + VehicleLegalChecks = function(Player, _, Value) + local Bool = tobool(Value) + + if ACF.VehicleLegalChecks == Bool then return end + + ACF.VehicleLegalChecks = Bool + + if CLIENT and not IsValid(Player) then return end + + Message("Info", "Legality checks for vehicles have been " .. (Bool and "enabled." or "disabled.")) end, GunsCanFire = function(Player, _, Value) local Bool = tobool(Value) diff --git a/lua/acf/menu/items_cl/settings.lua b/lua/acf/menu/items_cl/settings.lua index 5604cb8fa..d538fdc32 100644 --- a/lua/acf/menu/items_cl/settings.lua +++ b/lua/acf/menu/items_cl/settings.lua @@ -139,6 +139,14 @@ do -- Serverside settings return Value end) + local VehicleLegalChecks = Base:AddCheckBox("Enable legality checks on vehicle entities.") + VehicleLegalChecks:SetServerData("VehicleLegalChecks", "OnChange") + VehicleLegalChecks:DefineSetter(function(Panel, _, _, Value) + Panel:SetValue(Value) + + return Value + end) + local GunFire = Base:AddCheckBox("Allow guns to fire.") GunFire:SetServerData("GunsCanFire", "OnChange") GunFire:DefineSetter(function(Panel, _, _, Value) From 6f504a9355eb97ba1dde71bdf4292bc97e2eb801 Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:22:14 -0500 Subject: [PATCH 2/5] Remove debug print Oops --- lua/acf/contraption/seats_sv.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/acf/contraption/seats_sv.lua b/lua/acf/contraption/seats_sv.lua index f239cf0e5..d8dc64544 100644 --- a/lua/acf/contraption/seats_sv.lua +++ b/lua/acf/contraption/seats_sv.lua @@ -27,7 +27,7 @@ hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity) if not IsValid(Driver) then return end Driver:ExitVehicle() end - PrintTable(Entity:GetTable()) + if not ACF.VehicleLegalChecks then return end ACF.CheckLegal(Entity) From e945906048d16be89468846a6ddf5d67336d4d2f Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Sat, 30 Dec 2023 00:06:23 -0500 Subject: [PATCH 3/5] Persist vehicle legality setting --- lua/acf/persisted_vars/vars_sv.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/acf/persisted_vars/vars_sv.lua b/lua/acf/persisted_vars/vars_sv.lua index a6d2ab5ae..eb846543a 100644 --- a/lua/acf/persisted_vars/vars_sv.lua +++ b/lua/acf/persisted_vars/vars_sv.lua @@ -2,6 +2,7 @@ -- Settings ACF.PersistServerData("LegalChecks", true) +ACF.PersistServerData("VehicleLegalChecks", true) ACF.PersistServerData("ServerDataAllowAdmin", false) ACF.PersistServerData("RestrictInfo", true) ACF.PersistServerData("GunsCanFire", true) From 27c3bed1f6ed4fbeca21e9ac8937b5cf95cad866 Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Sun, 31 Dec 2023 15:12:24 -0500 Subject: [PATCH 4/5] Treat NPCs like players in ballistics handling Fixes #346 --- lua/acf/ballistics/ballistics_sv.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/acf/ballistics/ballistics_sv.lua b/lua/acf/ballistics/ballistics_sv.lua index f0531ada2..6d28cfd2d 100644 --- a/lua/acf/ballistics/ballistics_sv.lua +++ b/lua/acf/ballistics/ballistics_sv.lua @@ -157,7 +157,7 @@ end function Ballistics.GetImpactType(Trace, Entity) if Trace.HitWorld then return "World" end - if Entity:IsPlayer() then return "Prop" end + if Entity:IsPlayer() or Entity:IsNPC() then return "Prop" end return IsValid(Entity:CPPIGetOwner()) and "Prop" or "World" end From fb0c1ee30c967e5256c78b2a8774f2f22d7100f9 Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Tue, 2 Jan 2024 20:40:37 -0500 Subject: [PATCH 5/5] Somewhat buff fuel consumption rate The 27.8 fuel consumption rate is based around a single engine, but a significant number of players use 2 or 3 engines, which are much more difficult to use with this previous fuel rate. Decreasing the fuel rate to some degree helps account for this very common setup while still maintaining the intended effect on fuel balancing. --- lua/acf/core/globals.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/acf/core/globals.lua b/lua/acf/core/globals.lua index 2cbe1aeb8..8a9e89141 100644 --- a/lua/acf/core/globals.lua +++ b/lua/acf/core/globals.lua @@ -123,7 +123,7 @@ do -- ACF global vars -- Fuel ACF.RequireFuel = true -- Whether or not fuel usage should be required for engines - ACF.FuelRate = 27.8 -- Multiplier for fuel usage, 1.0 is approx real world + ACF.FuelRate = 15 -- Multiplier for fuel usage, 1.0 is approx real world ACF.FuelFactor = 1 -- Multiplier for ACF.FuelRate ACF.FuelMinSize = 6 -- Defines the shortest possible length of fuel tanks for all their axises, in gmu ACF.FuelMaxSize = 96 -- Defines the highest possible length of fuel tanks for all their axises, in gmu