Skip to content

Commit

Permalink
Merge pull request #393 from marchc1/add-seat-model-check
Browse files Browse the repository at this point in the history
Add seat model check
  • Loading branch information
thecraftianman authored Mar 13, 2024
2 parents 2a69dd8 + eb7e38d commit 6e24672
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
50 changes: 48 additions & 2 deletions lua/acf/contraption/seats_sv.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
-- Optional functionality for legality checking on all vehicles

-- A whitelist of allowed seats, prevents setting your seat to something with a microscopic physics object
local ValidSeatModels = {
-- Default HL2 seats
["models/nova/airboat_seat.mdl"] = true,
["models/nova/chair_office02.mdl"] = true,
["models/props_phx/carseat2.mdl"] = true,
["models/props_phx/carseat2.mdl"] = true,
["models/props_phx/carseat3.mdl"] = true,
["models/props_phx/carseat2.mdl"] = true,
["models/nova/chair_plastic01.mdl"] = true,
["models/nova/jeep_seat.mdl"] = true,
["models/nova/chair_office01.mdl"] = true,
["models/nova/chair_wood01.mdl"] = true,
["models/vehicles/prisoner_pod_inner.mdl"] = true,

-- ACF default seats
["models/vehicles/driver_pod.mdl"] = true,
["models/vehicles/pilot_seat.mdl"] = true,

-- Playerstart seats
["models/chairs_playerstart/airboatpose.mdl"] = true,
["models/chairs_playerstart/jeeppose.mdl"] = true,
["models/chairs_playerstart/podpose.mdl"] = true,
["models/chairs_playerstart/sitposealt.mdl"] = true,
["models/chairs_playerstart/pronepose.mdl"] = true,
["models/chairs_playerstart/sitpose.mdl"] = true,
["models/chairs_playerstart/standingpose.mdl"] = true,

-- Racing seats
["models/lubprops/seat/raceseat.mdl"] = true,
["models/lubprops/seat/raceseat2.mdl"] = true,
}

ACF.ValidSeatModels = ValidSeatModels

hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity)
timer.Simple(0, function()
if not IsValid(Entity) then return end
Expand All @@ -12,7 +47,7 @@ hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity)
Entity.ACF = {}
Entity.ACF.PhysObj = PhysObj
Entity.ACF.LegalMass = PhysObj:GetMass()
Entity.ACF.Model = Entity:GetModel()
Entity.ACF.Model = Entity.VehicleTable.Model or Entity:GetModel()
Entity.ACF.LegalSeat = true
Entity.WireDebugName = Entity.WireDebugName or Entity.VehicleTable.Name or "ACF Legal Vehicle"

Expand All @@ -34,11 +69,22 @@ hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity)
end)
end)

hook.Add("ACF_IsLegal", "ACF_CheckLegal_SeatLegality", function(Entity)
if not ACF.VehicleLegalChecks then return end
if not Entity:IsVehicle() then return end

local ModelPath = Entity:GetModel()

if not ValidSeatModels[ModelPath] and ModelPath ~= Entity.VehicleTable.Model then
return false, "Bad Seat Model", "This seat model is not on the whitelist."
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)
end)
4 changes: 4 additions & 0 deletions lua/tests/acf/core/validation_sv/is_legal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ return {
return true
end,

IsVehicle = function()
return false
end,

GetCollisionGroup = function()
return COLLISION_GROUP_NONE
end
Expand Down

0 comments on commit 6e24672

Please sign in to comment.