Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into sound-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
thecraftianman committed Jan 19, 2024
2 parents 60e883c + b72f40c commit 001e193
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lua/acf/ballistics/ballistics_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions lua/acf/contraption/seats_sv.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- 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
if Entity.wac_ignore then return end -- WAC vehicles do this too

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

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, "[ACF] Seat is not legal and is currently disabled.")
return false
end
end)
3 changes: 2 additions & 1 deletion lua/acf/core/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -122,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
Expand Down
13 changes: 12 additions & 1 deletion lua/acf/menu/data_callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions lua/acf/menu/items_cl/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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)
Expand Down
1 change: 1 addition & 0 deletions lua/acf/persisted_vars/vars_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 20 additions & 1 deletion lua/tests/acf/ballistics/ballistics_sv/get_impact_type.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,24 @@ return {
name = "Returns Prop if impacting a Player Entity",
func = function()
local Trace = {}
local Entity = { IsPlayer = stub().returns( true ) }
local Entity = {
IsPlayer = stub().returns( true ),
IsNPC = stub().returns( false )
}

local Type = ACF.Ballistics.GetImpactType( Trace, Entity )
expect( Type ).to.equal( "Prop" )
end
},

{
name = "Returns Prop if impacting an NPC Entity",
func = function()
local Trace = {}
local Entity = {
IsPlayer = stub().returns( false ),
IsNPC = stub().returns( true )
}

local Type = ACF.Ballistics.GetImpactType( Trace, Entity )
expect( Type ).to.equal( "Prop" )
Expand All @@ -29,6 +46,7 @@ return {
local Trace = {}
local Entity = {
IsPlayer = stub().returns( false ),
IsNPC = stub().returns( false ),
CPPIGetOwner = function()
return { IsValid = stub().returns( true ) }
end
Expand All @@ -45,6 +63,7 @@ return {
local Trace = {}
local Entity = {
IsPlayer = stub().returns( false ),
IsNPC = stub().returns( false ),
CPPIGetOwner = function()
return { IsValid = stub().returns( false ) }
end
Expand Down

0 comments on commit 001e193

Please sign in to comment.