Skip to content

Commit

Permalink
Improved fuel tank verification
Browse files Browse the repository at this point in the history
- Now fuel tanks will properly make use of its verification function, along with allowing people to implement scalable and non scalable fuel tank classes into ACF.
- Added Size to the list of dupe information arguments on fuel tanks.
  • Loading branch information
TwistedTail committed Oct 14, 2023
1 parent 6ec8a17 commit 5235a25
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions lua/entities/acf_fueltank/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,46 +49,45 @@ do -- Spawn and Update functions
}

local function VerifyData(Data)
if not isvector(Data.Size) then
local Group = Classes.GetGroup(FuelTanks, Data.FuelTank)
local Tank = FuelTanks.GetItem(Group.ID, Data.FuelTank)

if Tank.Size then -- Updating pre-scalable update fuel tanks
Data.Size = Vector(Tank.Size)
Data.Shape = Tank.Shape
else
local X = ACF.CheckNumber(Data.TankSizeX, 24)
local Y = ACF.CheckNumber(Data.TankSizeY, 24)
local Z = ACF.CheckNumber(Data.TankSizeZ, 24)

if Data.FuelTank == "Drum" then
Y = X
end

Data.Size = Vector(X, Y, Z)
end
if not isstring(Data.FuelTank) then
Data.FuelTank = Data.SizeId or Data.Id
end

do -- Clamping size
local Min = ACF.FuelMinSize
local Max = ACF.FuelMaxSize
local Size = Data.Size
local Class = Classes.GetGroup(FuelTanks, Data.FuelTank)

Size.x = math.Clamp(math.Round(Size.x), Min, Max)
Size.y = math.Clamp(math.Round(Size.y), Min, Max)
Size.z = math.Clamp(math.Round(Size.z), Min, Max)
end
if not Class then
Data.FuelTank = "Box"

if not Data.FuelTank then
Data.FuelTank = Data.SizeId or Data.Id or "Jerry_Can"
Class = FuelTanks.Get("Box")
elseif FuelTanks.IsAlias(Data.FuelTank) then
Data.FuelTank = Class.ID
end

local Class = Classes.GetGroup(FuelTanks, Data.FuelTank)
if Class.IsScalable then
local FuelTank = FuelTanks.GetItem(Class.ID, Data.FuelTank)

if not Class then
Data.FuelTank = "Jerry_Can"
if FuelTank then
Data.FuelTank = Class.ID
Data.Size = Vector(FuelTank.Size)
elseif not isvector(Data.Size) then
local X = ACF.CheckNumber(Data.TankSizeX, 24)
local Y = ACF.CheckNumber(Data.TankSizeY, 24)
local Z = ACF.CheckNumber(Data.TankSizeZ, 24)

Class = Classes.GetGroup(FuelTanks, "Jerry_Can")
Data.Size = Vector(X, Y, Z)
end

do -- Clamping size
local Min = ACF.FuelMinSize
local Max = ACF.FuelMaxSize
local Size = Data.Size

Size.x = math.Clamp(math.Round(Size.x), Min, Max)
Size.y = math.Clamp(math.Round(Size.y), Min, Max)
Size.z = math.Clamp(math.Round(Size.z), Min, Max)
end
else
Data.Size = nil
end

-- Making sure to provide a valid fuel type
Expand Down Expand Up @@ -263,7 +262,7 @@ do -- Spawn and Update functions
return Tank
end

Entities.Register("acf_fueltank", MakeACF_FuelTank, "FuelTank", "FuelType")
Entities.Register("acf_fueltank", MakeACF_FuelTank, "FuelTank", "FuelType", "Size")

ACF.RegisterLinkSource("acf_fueltank", "Engines")

Expand Down

0 comments on commit 5235a25

Please sign in to comment.