Skip to content

Commit

Permalink
Improved caliber verification, fixed crate name and short names
Browse files Browse the repository at this point in the history
- Improved caliber verification for non scalable weapons, now it should properly default to 50mm if the weapon is defined but the user failed to provide a caliber value.
- Fixed weapon name and weapon short name having trouble accounting for scalable weapons having items registered items under them.
- Added a bunch of spaces between variables and the start of conditions.
- Removed seemingly unused WeaponData field from ammo crates.
  • Loading branch information
TwistedTail committed Apr 26, 2024
1 parent ee5768a commit 2d8e66b
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lua/entities/acf_ammo/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ do -- Spawning and Updating --------------------
local function VerifyData(Data)
if Data.Id then -- Deprecated ammo data formats
local Crate = Crates.Get(Data.Id) -- Id is the crate model type, Crate holds its offset, size and id.

if Crate then -- Pre scalable crate remnants (ACF2?)
Data.Offset = Vector(Crate.Offset)
Data.Size = Vector(Crate.Size)
Expand All @@ -60,7 +61,7 @@ do -- Spawning and Updating --------------------
Data.Size = Vector(X, Y, Z)
end

Data.Weapon = Data.RoundId -- Note that RoundId is of the old weapon id form, e.g. "14.5mmMG",
Data.Weapon = Data.RoundId -- Note that RoundId is of the old weapon id form, e.g. "14.5mmMG",
Data.AmmoType = Data.RoundType
elseif not isvector(Data.Size) then -- This could just be an else statement? Not sure though.
-- Current ammo data format
Expand Down Expand Up @@ -107,22 +108,24 @@ do -- Spawning and Updating --------------------
-- TODO: FIX
do -- Verifying and clamping caliber value
local Weapon = Source.GetItem(Class.ID, Data.Weapon)

if Weapon then -- Happens on pre scaleable guns (e.g. Data.Weapon="14.5mmMG", Class.ID="MG")
if Class.IsScalable then -- If the class is scalable, set the weapon to the class' ID and bound its caliber
Data.Weapon = Class.ID -- E.g. "MG"

local Bounds = Class.Caliber
local Caliber = ACF.CheckNumber(Weapon.Caliber, Bounds.Base)

Data.Weapon = Class.ID -- E.g. "MG"
Data.Caliber = math.Clamp(Caliber, Bounds.Min, Bounds.Max)
else
-- If the class isn't scalable then this weapon is a registered item (e.g. 14.mmMG) and we use its caliber
Data.Caliber = ACF.CheckNumber(Weapon.Caliber, 50)
end

-- If the class isn't scalable then this weapon is a registered item (e.g. 14.mmMG) and we use its caliber
Data.Caliber = Weapon.Caliber
end
end

-- If our ammo type does not exist or is blacklisted by this weapon, use defaults
local Ammo = AmmoTypes.Get(Data.AmmoType)

if not Ammo or Ammo.Blacklist[Class.ID] then
Data.AmmoType = Class.DefaultAmmo or "AP"

Expand All @@ -143,9 +146,10 @@ do -- Spawning and Updating --------------------

local function UpdateCrate(Entity, Data, Class, Weapon, Ammo)
local Name, ShortName, WireName = Ammo:GetCrateName()
local Caliber = Weapon and Weapon.Caliber or Data.Caliber
local WeaponName = Weapon and Weapon.Name or Caliber .. "mm " .. Class.Name
local WeaponShort = Weapon and Weapon.ID or Caliber .. "mm" .. Class.ID
local Scalable = Class.IsScalable
local Caliber = Either(Scalable, Data.Caliber, Weapon.Caliber)
local WeaponName = Either(Scalable, Caliber .. "mm " .. Class.Name, Weapon.Name)
local WeaponShort = Either(Scalable, Caliber .. "mm" .. Class.ID, Weapon.ID)

Entity:SetSize(Data.Size)

Expand Down Expand Up @@ -184,7 +188,6 @@ do -- Spawning and Updating --------------------
Entity.EntType = "Ammo Crate"
Entity.ClassData = Class
Entity.Class = Class.ID -- Needed for custom killicons
Entity.WeaponData = Weapon
Entity.Caliber = Caliber

WireIO.SetupInputs(Entity, Inputs, Data, Class, Weapon, Ammo)
Expand Down

0 comments on commit 2d8e66b

Please sign in to comment.