diff --git a/lua/acf/ballistics/ballistics_cl.lua b/lua/acf/ballistics/ballistics_cl.lua index 30dcc4102..893091989 100644 --- a/lua/acf/ballistics/ballistics_cl.lua +++ b/lua/acf/ballistics/ballistics_cl.lua @@ -19,7 +19,7 @@ local function BulletFlight(Bullet, DeltaTime) Debug.Line(Bullet.SimPosLast, Bullet.SimPos, 15, Yellow) end -hook.Add("ACF_OnClock", "ACF_ManageBulletEffects", function(_, DeltaTime) +hook.Add("ACF_OnTick", "ACF_ManageBulletEffects", function(_, DeltaTime) for _, Bullet in pairs(ACF.BulletEffect) do BulletFlight(Bullet, DeltaTime) end diff --git a/lua/acf/ballistics/ballistics_sv.lua b/lua/acf/ballistics/ballistics_sv.lua index d1f0663ae..b811314e3 100644 --- a/lua/acf/ballistics/ballistics_sv.lua +++ b/lua/acf/ballistics/ballistics_sv.lua @@ -1,3 +1,4 @@ +local hook = hook local ACF = ACF local Ballistics = ACF.Ballistics local Damage = ACF.Damage @@ -17,7 +18,6 @@ local SkyGraceZone = 100 local FlightTr = { start = true, endpos = true, filter = true, mask = true } local GlobalFilter = ACF.GlobalFilter local AmmoTypes = ACF.Classes.AmmoTypes -local HookRun = hook.Run -- This will create, or update, the tracer effect on the clientside @@ -52,7 +52,7 @@ function Ballistics.RemoveBullet(Bullet) Bullet.Removed = true if not next(Bullets) then - hook.Remove("ACF_OnClock", "ACF Iterate Bullets") + hook.Remove("ACF_OnTick", "ACF Iterate Bullets") end end @@ -148,7 +148,7 @@ function Ballistics.CreateBullet(BulletData) end if not next(Bullets) then - hook.Add("ACF_OnClock", "ACF Iterate Bullets", Ballistics.IterateBullets) + hook.Add("ACF_OnTick", "ACF Iterate Bullets", Ballistics.IterateBullets) end Bullets[Index] = Bullet @@ -200,7 +200,7 @@ function Ballistics.TestFilter(Entity, Bullet) if GlobalFilter[Entity:GetClass()] then return false end - if HookRun("ACF_OnFilterBullet", Entity, Bullet) == false then return false end + if not hook.Run("ACF_OnFilterBullet", Entity, Bullet) then return false end if Entity._IsSpherical then return false end -- TODO: Remove when damage changes make props unable to be destroyed, as physical props can have friction reduced (good for wheels) @@ -208,7 +208,9 @@ function Ballistics.TestFilter(Entity, Bullet) end function Ballistics.DoBulletsFlight(Bullet) - if HookRun("ACF Bullet Flight", Bullet) == false then return end + local CanFly = hook.Run("ACF_PreBulletFlight", Bullet) + + if not CanFly then return end if Bullet.SkyLvL then if Clock.CurTime - Bullet.LifeTime > 30 then @@ -276,7 +278,7 @@ function Ballistics.DoBulletsFlight(Bullet) else local Entity = traceRes.Entity - if Ballistics.TestFilter(Entity, Bullet) == false then + if not Ballistics.TestFilter(Entity, Bullet) then table.insert(Bullet.Filter, Entity) Ballistics.DoBulletsFlight(Bullet) -- Retries the same trace after adding the entity to the filter, important incase something is embedded in something that shouldn't be hit diff --git a/lua/acf/contraption/seats_sv.lua b/lua/acf/contraption/seats_sv.lua index 58448e3fb..767d9a31b 100644 --- a/lua/acf/contraption/seats_sv.lua +++ b/lua/acf/contraption/seats_sv.lua @@ -72,7 +72,7 @@ hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity) end) end) -hook.Add("ACF_IsLegal", "ACF_CheckLegal_SeatLegality", function(Entity) +hook.Add("ACF_OnCheckLegal", "ACF_CheckLegal_SeatLegality", function(Entity) if not ACF.VehicleLegalChecks then return end if not Entity:IsVehicle() then return end diff --git a/lua/acf/core/classes/entities/registration.lua b/lua/acf/core/classes/entities/registration.lua index 2c11b50ba..36835b593 100644 --- a/lua/acf/core/classes/entities/registration.lua +++ b/lua/acf/core/classes/entities/registration.lua @@ -131,7 +131,7 @@ do -- Spawning and updating local HookResult, HookMessage = hook.Run("ACF_CanCreateEntity", Class, Player, Position, Angles, Data) - if HookResult == false then return false, HookMessage end + if not HookResult then return false, HookMessage end local Entity = ClassData.Spawn(Player, Position, Angles, Data) diff --git a/lua/acf/core/classes/grouped.lua b/lua/acf/core/classes/grouped.lua index ee296ebaf..7a78cd2ad 100644 --- a/lua/acf/core/classes/grouped.lua +++ b/lua/acf/core/classes/grouped.lua @@ -31,7 +31,7 @@ function Classes.AddGroup(ID, Destiny, Data) Group[K] = V end - hook.Run("ACF_OnNewClassGroup", ID, Group) + hook.Run("ACF_OnCreateGroup", ID, Group) return Group end @@ -68,7 +68,7 @@ function Classes.AddGroupItem(ID, GroupID, Destiny, Data) Class[K] = V end - hook.Run("ACF_OnNewGroupedClass", ID, Group, Class) + hook.Run("ACF_OnCreateGroupItem", ID, Group, Class) return Class end @@ -188,13 +188,13 @@ function Classes.AddGroupedFunctions(Namespace, Entries) end end -hook.Add("ACF_OnNewClassGroup", "ACF Precache Model", function(_, Group) +hook.Add("ACF_OnCreateGroup", "ACF Precache Model", function(_, Group) if not isstring(Group.Model) then return end util.PrecacheModel(Group.Model) end) -hook.Add("ACF_OnNewGroupedClass", "ACF Precache Model", function(_, _, Class) +hook.Add("ACF_OnCreateGroupItem", "ACF Precache Model", function(_, _, Class) if not isstring(Class.Model) then return end util.PrecacheModel(Class.Model) diff --git a/lua/acf/core/classes/object.lua b/lua/acf/core/classes/object.lua index 7ae0b94eb..c3383afb7 100644 --- a/lua/acf/core/classes/object.lua +++ b/lua/acf/core/classes/object.lua @@ -64,7 +64,7 @@ local function AttachMetaTable(Class, Base) Class:OnLoaded() end - hook.Run("ACF_OnClassLoaded", Class.ID, Class) + hook.Run("ACF_OnLoadClass", Class.ID, Class) Class.Loaded = true end) @@ -102,7 +102,7 @@ function Classes.AddObject(ID, Base, Destiny) return Class end -hook.Add("ACF_OnClassLoaded", "ACF Model Precache", function(_, Class) +hook.Add("ACF_OnLoadClass", "ACF Model Precache", function(_, Class) if not isstring(Class.Model) then return end util.PrecacheModel(Class.Model) diff --git a/lua/acf/core/classes/simple.lua b/lua/acf/core/classes/simple.lua index d6967d413..6b6a11106 100644 --- a/lua/acf/core/classes/simple.lua +++ b/lua/acf/core/classes/simple.lua @@ -29,7 +29,7 @@ function Classes.AddSimple(ID, Destiny, Data) Class[K] = V end - hook.Run("ACF_OnNewSimpleClass", ID, Class) + hook.Run("ACF_OnCreateItem", ID, Class) return Class end @@ -101,7 +101,7 @@ function Classes.AddSimpleFunctions(Namespace, Entries) end end -hook.Add("ACF_OnNewSimpleClass", "ACF Precache Model", function(_, Class) +hook.Add("ACF_OnCreateItem", "ACF Precache Model", function(_, Class) if not isstring(Class.Model) then return end util.PrecacheModel(Class.Model) diff --git a/lua/acf/core/globals.lua b/lua/acf/core/globals.lua index 3287ffba8..c54f1897a 100644 --- a/lua/acf/core/globals.lua +++ b/lua/acf/core/globals.lua @@ -227,7 +227,7 @@ do -- Player loaded hook util.AddNetworkString("ACF_PlayerLoaded") net.Receive("ACF_PlayerLoaded", function(_, Player) - hook.Run("ACF_OnPlayerLoaded", Player) + hook.Run("ACF_OnLoadPlayer", Player) end) else hook.Add("InitPostEntity", "ACF Player Loaded", function() @@ -287,7 +287,7 @@ do -- Smoke/Wind ----------------------------------- end end) - hook.Add("ACF_OnPlayerLoaded", "ACF Send Smoke Wind", function(Player) + hook.Add("ACF_OnLoadPlayer", "ACF Send Smoke Wind", function(Player) net.Start("acf_smokewind") net.WriteFloat(ACF.SmokeWind) net.Send(Player) diff --git a/lua/acf/core/networking/data_vars/data_vars_cl.lua b/lua/acf/core/networking/data_vars/data_vars_cl.lua index 468863b33..71873d7c2 100644 --- a/lua/acf/core/networking/data_vars/data_vars_cl.lua +++ b/lua/acf/core/networking/data_vars/data_vars_cl.lua @@ -62,7 +62,7 @@ do -- Server data var syncronization if Values[K] ~= V then Values[K] = V - hook.Run("ACF_OnServerDataUpdate", nil, K, V) + hook.Run("ACF_OnUpdateServerData", nil, K, V) end Received[K] = nil @@ -135,7 +135,7 @@ do -- Client data setter function if Forced or Client[Key] ~= Value then Client[Key] = Value - hook.Run("ACF_OnClientDataUpdate", LocalPlayer(), Key, Value) + hook.Run("ACF_OnUpdateClientData", LocalPlayer(), Key, Value) NetworkData(Key) end @@ -162,7 +162,7 @@ do -- Server data setter function if Forced or Server[Key] ~= Value then Server[Key] = Value - hook.Run("ACF_OnServerDataUpdate", Player, Key, Value) + hook.Run("ACF_OnUpdateServerData", Player, Key, Value) NetworkData(Key, true) end diff --git a/lua/acf/core/networking/data_vars/data_vars_sv.lua b/lua/acf/core/networking/data_vars/data_vars_sv.lua index 75187e65b..dd3452c1e 100644 --- a/lua/acf/core/networking/data_vars/data_vars_sv.lua +++ b/lua/acf/core/networking/data_vars/data_vars_sv.lua @@ -119,7 +119,7 @@ do -- Data syncronization end }) - hook.Add("ACF_OnPlayerLoaded", "ACF Data Var Syncronization", function(Player) + hook.Add("ACF_OnLoadPlayer", "ACF Data Var Syncronization", function(Player) -- Server data var syncronization for Key in pairs(Server) do NetworkData(Key, Player) @@ -198,7 +198,7 @@ do -- Server data setter function if Forced or Server[Key] ~= Value then Server[Key] = Value - hook.Run("ACF_OnServerDataUpdate", nil, Key, Value) + hook.Run("ACF_OnUpdateServerData", nil, Key, Value) NetworkData(Key) end diff --git a/lua/acf/core/networking/model_data/model_data_cl.lua b/lua/acf/core/networking/model_data/model_data_cl.lua index c69b7e4c2..087f08c67 100644 --- a/lua/acf/core/networking/model_data/model_data_cl.lua +++ b/lua/acf/core/networking/model_data/model_data_cl.lua @@ -22,7 +22,7 @@ end -- @param Model The model to queue the callback for. -- @param Object Anything that won't fail the IsValid check, usually panels or entities. -- @param Callback The function to call when the model data is received. -function ModelData.QueueRefresh(Model, Object, Callback) +function ModelData.CallOnReceive(Model, Object, Callback) if not IsValid(Object) then return end if not isfunction(Callback) then return end @@ -42,6 +42,22 @@ function ModelData.QueueRefresh(Model, Object, Callback) end end +function ModelData.RunCallbacks(Model) + local Data = Callbacks[Model] + + if not Data then return end + + for Object, Callback in pairs(Data) do + if IsValid(Object) then + Callback(Object, Model) + end + + Data[Object] = nil + end + + Callbacks[Model] = nil +end + function ModelData.GetModelData(Model) local Path = ModelData.GetModelPath(Model) @@ -69,7 +85,7 @@ hook.Add("ACF_OnLoadAddon", "ACF_ModelData", function() Standby[Model] = nil Models[Model] = Data - hook.Run("ACF_OnReceivedModelData", Model, Data) + hook.Run("ACF_OnReceiveModelData", Model, Data) end Entity:CallOnRemove("ACF_ModelData", function() @@ -104,7 +120,7 @@ hook.Add("ACF_OnLoadAddon", "ACF_ModelData", function() Standby[Model] = true Queue[Model] = true - hook.Run("ACF_OnRequestedModelData", Model) + hook.Run("ACF_OnRequestModelData", Model) end) Network.CreateReceiver("ACF_ModelData", function(Data) @@ -117,7 +133,7 @@ hook.Add("ACF_OnLoadAddon", "ACF_ModelData", function() Standby[Model] = nil Models[Model] = Info - hook.Run("ACF_OnReceivedModelData", Model, Info) + hook.Run("ACF_OnReceiveModelData", Model, Info) end end end) @@ -125,7 +141,7 @@ hook.Add("ACF_OnLoadAddon", "ACF_ModelData", function() hook.Remove("ACF_OnLoadAddon", "ACF_ModelData") end) -hook.Add("ACF_OnReceivedModelData", "ACF_ModelData_PanelRefresh", function(Model) +hook.Add("ACF_OnReceiveModelData", "ACF_ModelData_PanelRefresh", function(Model) local Data = Callbacks[Model] if not Data then return end @@ -139,4 +155,4 @@ hook.Add("ACF_OnReceivedModelData", "ACF_ModelData_PanelRefresh", function(Model end Callbacks[Model] = nil -end) +end) \ No newline at end of file diff --git a/lua/acf/core/networking/model_data/model_data_sv.lua b/lua/acf/core/networking/model_data/model_data_sv.lua index 72f567172..e0f323fa9 100644 --- a/lua/acf/core/networking/model_data/model_data_sv.lua +++ b/lua/acf/core/networking/model_data/model_data_sv.lua @@ -43,7 +43,7 @@ do -- Pointer entity creation hook.Remove("InitPostEntity", "ACF_ModelData") end) - hook.Add("ACF_OnPlayerLoaded", "ACF_ModelData", function(Player) + hook.Add("ACF_OnLoadPlayer", "ACF_ModelData", function(Player) Network.Send("ACF_ModelData_Entity", Player, ModelData.Entity) end) diff --git a/lua/acf/core/utilities/clock/clock.lua b/lua/acf/core/utilities/clock/clock.lua index 0d12a8fe8..224029f6d 100644 --- a/lua/acf/core/utilities/clock/clock.lua +++ b/lua/acf/core/utilities/clock/clock.lua @@ -10,5 +10,5 @@ hook.Add("Think", "ACF Clock Update", function() Clock.DeltaTime = Delta Clock.CurTime = Now - hook.Run("ACF_OnClock", New, Delta) + hook.Run("ACF_OnTick", New, Delta) end) diff --git a/lua/acf/core/validation_sv.lua b/lua/acf/core/validation_sv.lua index 61b523e04..2e1a56dd8 100644 --- a/lua/acf/core/validation_sv.lua +++ b/lua/acf/core/validation_sv.lua @@ -42,9 +42,9 @@ function ACF.IsLegal(Entity) if Entity.IsACFWeapon and not ACF.GunsCanFire then return false, "Cannot fire", "Firing disabled by the servers ACF settings." end if Entity.IsRack and not ACF.RacksCanFire then return false, "Cannot fire", "Firing disabled by the servers ACF settings." end - local Legal, Reason, Message, Timeout = hook.Run("ACF_IsLegal", Entity) + local Legal, Reason, Message, Timeout = hook.Run("ACF_OnCheckLegal", Entity) - if Legal ~= nil then return Legal, Reason, Message, Timeout end + if not Legal then return Legal, Reason, Message, Timeout end return true end @@ -171,7 +171,7 @@ function ACF.UpdateThickness(Entity, PhysObj, Area, Ductility) return math.Clamp(Armor, MinimumArmor, MaximumArmor) end -hook.Add("ACF_OnServerDataUpdate", "ACF_MaxThickness", function(_, Key, Value) +hook.Add("ACF_OnUpdateServerData", "ACF_MaxThickness", function(_, Key, Value) if Key ~= "MaxThickness" then return end MaximumArmor = math.floor(ACF.CheckNumber(Value, ACF.MaximumArmor)) diff --git a/lua/acf/core/version/version_cl.lua b/lua/acf/core/version/version_cl.lua index 6b2856c73..3efe22616 100644 --- a/lua/acf/core/version/version_cl.lua +++ b/lua/acf/core/version/version_cl.lua @@ -25,7 +25,7 @@ do -- Server syncronization and status printing ACF.CheckLocalStatus(Name) - hook.Run("ACF_UpdatedRepository", Name, Repos[Name]) + hook.Run("ACF_OnFetchRepository", Name, Repos[Name]) end end) diff --git a/lua/acf/core/version/version_sv.lua b/lua/acf/core/version/version_sv.lua index ce0623ba8..6e66c8a47 100644 --- a/lua/acf/core/version/version_sv.lua +++ b/lua/acf/core/version/version_sv.lua @@ -121,7 +121,7 @@ end do -- Client syncronization util.AddNetworkString("ACF_VersionSync") - hook.Add("ACF_OnPlayerLoaded", "ACF_VersionSync", function(Player) + hook.Add("ACF_OnLoadPlayer", "ACF_VersionSync", function(Player) local JSON = util.TableToJSON(Repos) net.Start("ACF_VersionSync") diff --git a/lua/acf/damage/explosion_sv.lua b/lua/acf/damage/explosion_sv.lua index 810c56675..7ed5dad3d 100644 --- a/lua/acf/damage/explosion_sv.lua +++ b/lua/acf/damage/explosion_sv.lua @@ -29,7 +29,7 @@ function Damage.isValidTarget(Entity) local Type = EntACF and EntACF.Type or ACF.Check(Entity) if not Type then return false end - if Ballistics.TestFilter(Entity) == false then return false end + if not Ballistics.TestFilter(Entity) then return false end if Type ~= "Squishy" then return true end diff --git a/lua/acf/damage/ke_shove_sv.lua b/lua/acf/damage/ke_shove_sv.lua index 1b30acd15..2e0531068 100644 --- a/lua/acf/damage/ke_shove_sv.lua +++ b/lua/acf/damage/ke_shove_sv.lua @@ -8,7 +8,7 @@ function ACF.KEShove(Target, Pos, Vec, KE) if not IsValid(Target) then return end if Target.ACF_Killed then return end - if hook.Run("ACF_KEShove", Target, Pos, Vec, KE) == false then return end + if not hook.Run("ACF_OnPushEntity", Target, Pos, Vec, KE) then return end local Ancestor = Target:GetAncestor() local Phys = Ancestor:GetPhysicsObject() diff --git a/lua/acf/damage/permissions/permissions_sv.lua b/lua/acf/damage/permissions/permissions_sv.lua index fe7e40004..5980b8464 100644 --- a/lua/acf/damage/permissions/permissions_sv.lua +++ b/lua/acf/damage/permissions/permissions_sv.lua @@ -627,4 +627,4 @@ local m = table.KeyFromValue(this.Modes, this.DamagePermission) if not m then this.DamagePermission = function() end hook.Run("ACF_ProtectionModeChanged", "default", nil) -end \ No newline at end of file +end diff --git a/lua/acf/entities/ammo_types/ap.lua b/lua/acf/entities/ammo_types/ap.lua index 394bd73ec..5f60ca7a2 100644 --- a/lua/acf/entities/ammo_types/ap.lua +++ b/lua/acf/entities/ammo_types/ap.lua @@ -27,7 +27,7 @@ function Ammo:GetDisplayData(Data) MaxPen = self:GetPenetration(Data, Data.MuzzleVel) } - hook.Run("ACF_GetDisplayData", self, Data, Display) + hook.Run("ACF_OnGetDisplayData", self, Data, Display) return Display end @@ -42,7 +42,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData) Data.DragCoef = Data.ProjArea * 0.0001 / Data.ProjMass Data.CartMass = Data.PropMass + Data.ProjMass - hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData) + hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData) for K, V in pairs(self:GetDisplayData(Data)) do GUIData[K] = V @@ -197,7 +197,7 @@ else return math.Round(self:GetPenetration(Bullet, Speed), 2), math.Round(Speed, 2) end - function Ammo:AddAmmoPreview(_, Setup) + function Ammo:OnCreateAmmoPreview(_, Setup) Setup.Model = self.Model Setup.FOV = 60 end @@ -239,12 +239,12 @@ else Effects.CreateEffect("ACF_Ricochet", EffectTable) end - function Ammo:AddCrateDataTrackers(Trackers) - Trackers.Projectile = true - Trackers.Propellant = true + function Ammo:OnCreateCrateInformation(_, Label) + Label:TrackClientData("Projectile") + Label:TrackClientData("Propellant") end - function Ammo:AddAmmoInformation(Base, ToolData, BulletData) + function Ammo:OnCreateAmmoInformation(Base, ToolData, BulletData) local RoundStats = Base:AddLabel() RoundStats:TrackClientData("Projectile", "SetText") RoundStats:TrackClientData("Propellant") diff --git a/lua/acf/entities/ammo_types/apcr.lua b/lua/acf/entities/ammo_types/apcr.lua index 8752b6ed5..bec3d1ce0 100644 --- a/lua/acf/entities/ammo_types/apcr.lua +++ b/lua/acf/entities/ammo_types/apcr.lua @@ -29,7 +29,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData) Data.DragCoef = Data.ProjArea * 0.0001 / Data.ProjMass Data.CartMass = Data.PropMass + Data.ProjMass - hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData) + hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData) for K, V in pairs(self:GetDisplayData(Data)) do GUIData[K] = V diff --git a/lua/acf/entities/ammo_types/apds.lua b/lua/acf/entities/ammo_types/apds.lua index 2def30f53..22bdba0c6 100644 --- a/lua/acf/entities/ammo_types/apds.lua +++ b/lua/acf/entities/ammo_types/apds.lua @@ -31,7 +31,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData) Data.DragCoef = Data.ProjArea * 0.000125 / Data.ProjMass -- Worse drag (Manually fudged to make a meaningful difference) Data.CartMass = Data.PropMass + Data.ProjMass + SabotMass - hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData) + hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData) for K, V in pairs(self:GetDisplayData(Data)) do GUIData[K] = V diff --git a/lua/acf/entities/ammo_types/apfsds.lua b/lua/acf/entities/ammo_types/apfsds.lua index 5fffbac88..8c809245a 100644 --- a/lua/acf/entities/ammo_types/apfsds.lua +++ b/lua/acf/entities/ammo_types/apfsds.lua @@ -60,7 +60,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData) Data.DragCoef = Data.ProjArea * 0.0001 / Data.ProjMass Data.CartMass = Data.PropMass + Data.ProjMass + SabotMass - hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData) + hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData) for K, V in pairs(self:GetDisplayData(Data)) do GUIData[K] = V diff --git a/lua/acf/entities/ammo_types/aphe.lua b/lua/acf/entities/ammo_types/aphe.lua index c23d3e268..caf69b5c9 100644 --- a/lua/acf/entities/ammo_types/aphe.lua +++ b/lua/acf/entities/ammo_types/aphe.lua @@ -35,7 +35,7 @@ function Ammo:GetDisplayData(Data) Display.FragMass = FragMass / Display.Fragments Display.FragVel = (Data.FillerMass * ACF.HEPower * 1000 / Display.FragMass / Display.Fragments) ^ 0.5 - hook.Run("ACF_GetDisplayData", self, Data, Display) + hook.Run("ACF_OnGetDisplayData", self, Data, Display) return Display end @@ -55,7 +55,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData) Data.CartMass = Data.PropMass + Data.ProjMass Data.FillerRatio = math.Clamp(ToolData.FillerRatio, 0, 1) - hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData) + hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData) for K, V in pairs(self:GetDisplayData(Data)) do GUIData[K] = V @@ -145,7 +145,7 @@ else Damage.explosionEffect(Position, Direction, Filler) end - function Ammo:AddAmmoControls(Base, ToolData, BulletData) + function Ammo:OnCreateAmmoControls(Base, ToolData, BulletData) local FillerRatio = Base:AddSlider("Filler Ratio", 0, 1, 2) FillerRatio:SetClientData("FillerRatio", "OnValueChanged") FillerRatio:DefineSetter(function(_, _, _, Value) @@ -157,13 +157,13 @@ else end) end - function Ammo:AddCrateDataTrackers(Trackers, ...) - Ammo.BaseClass.AddCrateDataTrackers(self, Trackers, ...) + function Ammo:OnCreateCrateInformation(Base, Label, ...) + Ammo.BaseClass.OnCreateCrateInformation(self, Base, Label, ...) - Trackers.FillerRatio = true + Label:TrackClientData("FillerRatio") end - function Ammo:AddAmmoInformation(Base, ToolData, BulletData) + function Ammo:OnCreateAmmoInformation(Base, ToolData, BulletData) local RoundStats = Base:AddLabel() RoundStats:TrackClientData("Projectile", "SetText") RoundStats:TrackClientData("Propellant") diff --git a/lua/acf/entities/ammo_types/fl.lua b/lua/acf/entities/ammo_types/fl.lua index 5abfcb2d1..86eaea765 100644 --- a/lua/acf/entities/ammo_types/fl.lua +++ b/lua/acf/entities/ammo_types/fl.lua @@ -41,7 +41,7 @@ function Ammo:GetDisplayData(Data) MaxPen = self:GetPenetration(Data, Data.MuzzleVel) } - hook.Run("ACF_GetDisplayData", self, Data, Display) + hook.Run("ACF_OnGetDisplayData", self, Data, Display) return Display end @@ -64,7 +64,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData) Data.MuzzleVel = ACF.MuzzleVelocity(Data.PropMass, Data.ProjMass, Data.Efficiency) Data.CartMass = Data.PropMass + Data.ProjMass - hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData) + hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData) for K, V in pairs(self:GetDisplayData(Data)) do GUIData[K] = V @@ -196,7 +196,7 @@ else return math.Round(self:GetPenetration(Bullet, Speed), 2), math.Round(Speed, 2) end - function Ammo:AddAmmoControls(Base, ToolData, BulletData) + function Ammo:OnCreateAmmoControls(Base, ToolData, BulletData) local Flechettes = Base:AddSlider("Flechette Amount", BulletData.MinFlechettes, BulletData.MaxFlechettes) Flechettes:SetClientData("Flechettes", "OnValueChanged") Flechettes:DefineSetter(function(Panel, _, _, Value) @@ -222,13 +222,13 @@ else end) end - function Ammo:AddCrateDataTrackers(Trackers, ...) - Ammo.BaseClass.AddCrateDataTrackers(self, Trackers, ...) + function Ammo:OnCreateCrateInformation(Base, Label, ...) + Ammo.BaseClass.OnCreateCrateInformation(self, Base, Label, ...) - Trackers.Flechettes = true + Label:TrackClientData("Flechettes") end - function Ammo:AddAmmoInformation(Menu, ToolData, BulletData) + function Ammo:OnCreateAmmoInformation(Menu, ToolData, BulletData) local RoundStats = Menu:AddLabel() RoundStats:TrackClientData("Projectile", "SetText") RoundStats:TrackClientData("Propellant") diff --git a/lua/acf/entities/ammo_types/he.lua b/lua/acf/entities/ammo_types/he.lua index 9174601d4..a20acada9 100644 --- a/lua/acf/entities/ammo_types/he.lua +++ b/lua/acf/entities/ammo_types/he.lua @@ -28,7 +28,7 @@ function Ammo:GetDisplayData(Data) FragVel = (Data.FillerMass * ACF.HEPower * 1000 / (FragMass / Fragments) / Fragments) ^ 0.5, } - hook.Run("ACF_GetDisplayData", self, Data, Display) + hook.Run("ACF_OnGetDisplayData", self, Data, Display) return Display end @@ -47,7 +47,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData) Data.DragCoef = Data.ProjArea * 0.0001 / Data.ProjMass Data.CartMass = Data.PropMass + Data.ProjMass - hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData) + hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData) for K, V in pairs(self:GetDisplayData(Data)) do GUIData[K] = V @@ -108,7 +108,7 @@ if SERVER then else ACF.RegisterAmmoDecal("HE", "damage/he_pen", "damage/he_rico") - function Ammo:AddAmmoInformation(Base, ToolData, BulletData) + function Ammo:OnCreateAmmoInformation(Base, ToolData, BulletData) local RoundStats = Base:AddLabel() RoundStats:TrackClientData("Projectile", "SetText") RoundStats:TrackClientData("Propellant") diff --git a/lua/acf/entities/ammo_types/heat.lua b/lua/acf/entities/ammo_types/heat.lua index 8eb8af20d..4c8c108ab 100644 --- a/lua/acf/entities/ammo_types/heat.lua +++ b/lua/acf/entities/ammo_types/heat.lua @@ -68,7 +68,7 @@ function Ammo:GetDisplayData(Data) FragVel = (Data.BoomFillerMass * ACF.HEPower * 1000 / Data.CasingMass) ^ 0.5, } - hook.Run("ACF_GetDisplayData", self, Data, Display) + hook.Run("ACF_OnGetDisplayData", self, Data, Display) return Display end @@ -137,7 +137,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData) Data.DragCoef = Data.ProjArea * 0.0001 / Data.ProjMass Data.CartMass = Data.PropMass + Data.ProjMass - hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData) + hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData) -- Recalculate the standoff for missiles if Data.MissileStandoff then @@ -277,7 +277,7 @@ if SERVER then Debug.Line(JetStart, PenHitPos, 15, ColorRand(100, 255)) - if Ballistics.TestFilter(Ent, Bullet) == false then TraceData.filter[#TraceData.filter + 1] = TraceRes.Entity continue end + if not Ballistics.TestFilter(Ent, Bullet) then TraceData.filter[#TraceData.filter + 1] = TraceRes.Entity continue end -- Get the (full jet's) penetration local Standoff = (PenHitPos - JetStart):Length() * 0.0254 -- Back to m @@ -492,7 +492,7 @@ else Effects.CreateEffect("ACF_Ricochet", EffectTable) end - function Ammo:AddAmmoControls(Base, ToolData, BulletData) + function Ammo:OnCreateAmmoControls(Base, ToolData, BulletData) local LinerAngle = Base:AddSlider("Liner Angle", BulletData.MinConeAng, 90, 1) LinerAngle:SetClientData("LinerAngle", "OnValueChanged") LinerAngle:TrackClientData("Projectile") @@ -521,14 +521,14 @@ else end) end - function Ammo:AddCrateDataTrackers(Trackers, ...) - Ammo.BaseClass.AddCrateDataTrackers(self, Trackers, ...) + function Ammo:OnCreateCrateInformation(Base, Label, ...) + Ammo.BaseClass.OnCreateCrateInformation(self, Base, Label, ...) - Trackers.LinerAngle = true - Trackers.StandoffRatio = true + Label:TrackClientData("LinerAngle") + Label:TrackClientData("StandoffRatio") end - function Ammo:AddAmmoInformation(Base, ToolData, BulletData) + function Ammo:OnCreateAmmoInformation(Base, ToolData, BulletData) local RoundStats = Base:AddLabel() RoundStats:TrackClientData("Projectile", "SetText") RoundStats:TrackClientData("Propellant") diff --git a/lua/acf/entities/ammo_types/heatfs.lua b/lua/acf/entities/ammo_types/heatfs.lua index b60d8f7df..3d74324dd 100644 --- a/lua/acf/entities/ammo_types/heatfs.lua +++ b/lua/acf/entities/ammo_types/heatfs.lua @@ -80,7 +80,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData) Data.DragCoef = Data.ProjArea * 0.0001 / Data.ProjMass Data.CartMass = Data.PropMass + Data.ProjMass - hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData) + hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData) -- Recalculate the standoff for missiles if Data.MissileStandoff then @@ -120,7 +120,7 @@ if SERVER then else ACF.RegisterAmmoDecal("HEATFS", "damage/heat_pen", "damage/heat_rico", function(Caliber) return Caliber * 0.1667 end) - function Ammo:AddAmmoControls(Base, ToolData, BulletData) + function Ammo:OnCreateAmmoControls(Base, ToolData, BulletData) local LinerAngle = Base:AddSlider("Liner Angle", BulletData.MinConeAng, 90, 1) LinerAngle:SetClientData("LinerAngle", "OnValueChanged") LinerAngle:TrackClientData("Projectile") diff --git a/lua/acf/entities/ammo_types/hp.lua b/lua/acf/entities/ammo_types/hp.lua index 4396eebf6..40d4add13 100644 --- a/lua/acf/entities/ammo_types/hp.lua +++ b/lua/acf/entities/ammo_types/hp.lua @@ -20,7 +20,7 @@ function Ammo:GetDisplayData(Data) Display.MaxKETransfert = Energy.Kinetic * Data.ShovePower - hook.Run("ACF_GetDisplayData", self, Data, Display) + hook.Run("ACF_OnGetDisplayData", self, Data, Display) return Display end @@ -42,7 +42,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData) Data.DragCoef = Data.ProjArea * 0.0001 / Data.ProjMass Data.CartMass = Data.PropMass + Data.ProjMass - hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData) + hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData) for K, V in pairs(self:GetDisplayData(Data)) do GUIData[K] = V @@ -99,7 +99,7 @@ if SERVER then else ACF.RegisterAmmoDecal("HP", "damage/ap_pen", "damage/ap_rico") - function Ammo:AddAmmoControls(Base, ToolData, BulletData) + function Ammo:OnCreateAmmoControls(Base, ToolData, BulletData) local HollowRatio = Base:AddSlider("Cavity Ratio", 0, 1, 2) HollowRatio:SetClientData("HollowRatio", "OnValueChanged") HollowRatio:DefineSetter(function(_, _, _, Value) @@ -111,13 +111,13 @@ else end) end - function Ammo:AddCrateDataTrackers(Trackers, ...) - Ammo.BaseClass.AddCrateDataTrackers(self, Trackers, ...) + function Ammo:OnCreateCrateInformation(Base, Label, ...) + Ammo.BaseClass.OnCreateCrateInformation(self, Base, Label, ...) - Trackers.HollowRatio = true + Label:TrackClientData("HollowRatio") end - function Ammo:AddAmmoInformation(Base, ToolData, BulletData) + function Ammo:OnCreateAmmoInformation(Base, ToolData, BulletData) local RoundStats = Base:AddLabel() RoundStats:TrackClientData("Projectile", "SetText") RoundStats:TrackClientData("Propellant") diff --git a/lua/acf/entities/ammo_types/refill.lua b/lua/acf/entities/ammo_types/refill.lua index e4d774501..5027b7145 100644 --- a/lua/acf/entities/ammo_types/refill.lua +++ b/lua/acf/entities/ammo_types/refill.lua @@ -74,10 +74,11 @@ if SERVER then local Distance = Position:DistToSqr(Crate:GetPos()) if CanRefillCrate(Refill, Crate, Distance) then - local Supply = math.ceil(ACF.RefillSpeed / Crate.BulletData.CartMass / Distance ^ 0.5) - local Transfer = math.min(Supply, Refill.Ammo, Crate.Capacity - Crate.Ammo) + local Supply = math.ceil(ACF.RefillSpeed / Crate.BulletData.CartMass / Distance ^ 0.5) + local Transfer = math.min(Supply, Refill.Ammo, Crate.Capacity - Crate.Ammo) + local CanRefill = hook.Run("ACF_AmmoCanRefill", Refill, Crate, Transfer) - if hook.Run("ACF_CanRefill", Refill, Crate, Transfer) == false then continue end + if not CanRefill then continue end if not next(Refill.SupplyingTo) then RefillEffect(Refill) @@ -165,14 +166,17 @@ if SERVER then return "" end else - function Ammo:SetupAmmoMenuSettings(Settings) - Settings.SuppressControls = true - Settings.SuppressInformation = true + function Ammo:OnCreateAmmoPreview(Preview, Setup, ...) + Ammo.BaseClass.OnCreateAmmoPreview(self, Preview, Setup, ...) + + Setup.FOV = 115 end - function Ammo:AddAmmoPreview(Preview, Setup, ...) - Ammo.BaseClass.AddAmmoPreview(self, Preview, Setup, ...) + function Ammo:PreCreateAmmoControls() + return false + end - Setup.FOV = 115 + function Ammo:PreCreateAmmoInformation() + return false end end diff --git a/lua/acf/entities/ammo_types/smoke.lua b/lua/acf/entities/ammo_types/smoke.lua index 5aba1937b..c5abb2bb0 100644 --- a/lua/acf/entities/ammo_types/smoke.lua +++ b/lua/acf/entities/ammo_types/smoke.lua @@ -36,7 +36,7 @@ function Ammo:GetDisplayData(Data) WPRadiusMax = math.Round(WPFiller * 1.25 * 2 * 0.0254, 2), } - hook.Run("ACF_GetDisplayData", self, Data, Display) + hook.Run("ACF_OnGetDisplayData", self, Data, Display) return Display end @@ -62,7 +62,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData) Data.DragCoef = Data.ProjArea * 0.0001 / Data.ProjMass Data.CartMass = Data.PropMass + Data.ProjMass - hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData) + hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData) for K, V in pairs(self:GetDisplayData(Data)) do GUIData[K] = V @@ -188,7 +188,7 @@ else Effects.CreateEffect("ACF_Smoke", EffectTable) end - function Ammo:AddAmmoControls(Base, ToolData, BulletData) + function Ammo:OnCreateAmmoControls(Base, ToolData, BulletData) local FillerRatio = Base:AddSlider("Filler Ratio", 0, 1, 2) FillerRatio:SetClientData("FillerRatio", "OnValueChanged") FillerRatio:DefineSetter(function(_, _, _, Value) @@ -210,14 +210,14 @@ else end) end - function Ammo:AddCrateDataTrackers(Trackers, ...) - Ammo.BaseClass.AddCrateDataTrackers(self, Trackers, ...) + function Ammo:OnCreateCrateInformation(Base, Label, ...) + Ammo.BaseClass.OnCreateCrateInformation(self, Base, Label, ...) - Trackers.FillerRatio = true - Trackers.SmokeWPRatio = true + Label:TrackClientData("FillerRatio") + Label:TrackClientData("SmokeWPRatio") end - function Ammo:AddAmmoInformation(Menu, ToolData, Data) + function Ammo:OnCreateAmmoInformation(Menu, ToolData, Data) local RoundStats = Menu:AddLabel() RoundStats:TrackClientData("Projectile", "SetText") RoundStats:TrackClientData("Propellant") diff --git a/lua/acf/hooks/hooks_cl.lua b/lua/acf/hooks/hooks_cl.lua new file mode 100644 index 000000000..d506d7990 --- /dev/null +++ b/lua/acf/hooks/hooks_cl.lua @@ -0,0 +1,209 @@ +local Hooks = ACF.Utilities.Hooks + + +Hooks.Add("ACF_Base_Client", function(Gamemode) + --- Called when the information about a repository is received and updated. + --- @param Name string The name of the repository that was updated. + --- @param Repository table The information about the repository. + function Gamemode:ACF_OnFetchRepository() + end + + --- Called when a new option is about to be added to the menu. + --- This hook won't be called if the option object has + --- an IsEnabled method defined and said method returns false. + --- @param Name string The name of the option object. + --- @return boolean # True if the option should be added to the menu, false otherwise. + function Gamemode:ACF_OnEnableMenuOption() + return true + end + + --- Called when a new option item is about to be added to the menu. + --- @param Option string The name of the option this item will be added to. + --- @param Name string The name of the new option item object. + function Gamemode:ACF_OnEnableMenuItem() + return true + end + + --- Called before a client settings collapsible section is created. + --- @param Name string The name of the client settings section. + --- @return boolean # True if the collapsible section can be created, false otherwise. + function Gamemode:ACF_PreLoadClientSettings() + return true + end + + --- Called when a client settings section is about to be populated. + --- @param Name string The name of the client settings section. + --- @param Panel panel The base panel where all the settings are going to be placed. + --- @return boolean # True to override the panels created by the section itself, false otherwise. + function Gamemode:ACF_OnLoadClientSettings() + return false + end + + --- Called after a client settings section has been populated. + --- @param Name string The name of the client settings section. + --- @param Panel panel The base panel where all the settings were placed. + function Gamemode:ACF_PostLoadClientSettings() + end + + --- Called before a server settings collapsible section is created. + --- @param Name string The name of the server settings section. + --- @return boolean # True if the collapsible section can be created, false otherwise. + function Gamemode:ACF_PreLoadServerSettings() + return true + end + + --- Called when a server settings section is about to be populated. + --- @param Name string The name of the server settings section. + --- @param Panel panel The base panel where all the settings are going to be placed. + --- @return boolean # True to override the panels created by the section itself, false otherwise. + function Gamemode:ACF_OnLoadServerSettings() + return false + end + + --- Called after a server settings section has been populated. + --- @param Name string The name of the server settings section. + --- @param Panel panel The base panel where all the settings were placed. + function Gamemode:ACF_PostLoadServerSettings() + end + + --- Called before the ammo menu is created. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + --- @return boolean # True to create the ammo menu, false otherwise + function Gamemode:ACF_PreCreateAmmoMenu() + return true + end + + --- Called when the ammo menu is about to be populated. + --- @param Panel panel The base ACF_Menu panel where everything will be created. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + function Gamemode:ACF_OnCreateAmmoMenu() + end + + --- Called before the ammo preview panel gets created. + --- @param Panel panel The base panel where all the controls are being placed. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + --- @return boolean # False to prevent the ammo preview panel from being created, true otherwise. + function Gamemode:ACF_PreCreateAmmoPreview() + return true + end + + --- Called after the ammo preview panel has been created but before it has been setup. + --- @param Panel panel The model preview panel used to display the ammo type model. + --- @param SetupData table The information table used for the model preview panel. + --- The Model field will define the path of the model that will get displayed. + --- The Height field will define the height of the panel. + --- The FOV field will define the amount of zoom applied to the display. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + function Gamemode:ACF_OnCreateAmmoPreview() + end + + --- Called before the projectile and propellant length panels are created. + --- @param Panel panel The base panel where all the controls are being placed. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + --- @return boolean # False to prevent the panels from being created, true otherwise. + function Gamemode:ACF_PreCreateAmmoControls() + return true + end + + --- Called after the projectile and propellant length panels have been created. + --- @param Panel panel The base panel where all the controls are being placed. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + function Gamemode:ACF_OnCreateAmmoControls() + end + + --- Called before the tracer checkbox panel gets created. + --- @param Panel panel The base panel where all the controls are being placed. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + --- @return boolean # False to prevent the checkbox from being created, true otherwise. + function Gamemode:ACF_PreCreateTracerControls() + return true + end + + --- Called after the tracer checkbox panel has been created. + --- @param Panel panel The base panel where all the controls are being placed. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + function Gamemode:ACF_OnCreateTracerControls() + end + + --- Called before the ammo information panels get created. + --- @param Panel panel The base panel where all the controls are being placed. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + --- @return boolean # False to prevent the ammo information panels from being created, true otherwise. + function Gamemode:ACF_PreCreateAmmoInformation() + return true + end + + --- Called before the ammo crate information panel gets created. + --- @param Panel panel The base panel where all the controls are being placed. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + --- @return boolean # False to prevent the ammo crate information panel from being created, true otherwise. + function Gamemode:ACF_PreCreateCrateInformation() + return true + end + + --- Called after the ammo crate information panel has been created. + --- @param Panel panel The base panel where all the controls are being placed. + --- @param Label panel The label panel where all the ammo crate information is being displayed. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + function Gamemode:ACF_OnCreateCrateInformation() + end + + --- Called after all the ammunition information panels have been created. + --- @param Panel panel The base panel where all the controls are being placed. + --- @param ToolData table A table containing the copy of the local player's data variables. + --- @param AmmoType table The ammo type object to be used on the menu. + --- @param BulletData table A bullet object used to display the stats of the chosen ammunition type. + function Gamemode:ACF_OnCreateAmmoInformation() + end + + --- Called after a clientside bullet effect has been created. + --- Used to override the default bullet effect. + --- @param Effect entity The effect entity that was created for a bullet. + --- @param BulletData table An object with the networked information from the bullet's ammo crate of origin. + --- Note that the information on this object will be much more limited than the one serverside bullet data would carry. + function Gamemode:ACF_OnCreateBulletEffect() + end + + --- Called when the ACF Menu tool is being pointed towards an entity. + --- The entity has to be, at most, 256 inches away from the player's eyes. + --- This hook will only be called if the acf_drawboxes convar is set to a non zero value. + --- For the developer's convenience, cam.Start3D and render.SetColorMaterial are called before this hook is ran. + --- @param Entity entity The entity being pointed at. + --- @param Trace table The TraceResult from the player's eye trace. + function Gamemode:ACF_OnDrawBoxes() + end + + --- Called after requesting a newly spawned model's data from the server. + --- Model data will always be invalid at this point. + --- @param Model string The model that has had its data requested. + function Gamemode:ACF_OnRequestModelData() + end + + --- Called after receiving a newly spawned model's data from the server. + --- @param Model string The model that has received new data. + --- @param Data table The data about the model that was received from the server. + function Gamemode:ACF_OnReceiveModelData() + end +end) diff --git a/lua/acf/hooks/hooks_sh.lua b/lua/acf/hooks/hooks_sh.lua new file mode 100644 index 000000000..67f047943 --- /dev/null +++ b/lua/acf/hooks/hooks_sh.lua @@ -0,0 +1,106 @@ +local Hooks = ACF.Utilities.Hooks + + +Hooks.Add("ACF_Base_Shared", function(Gamemode) + --- Called when ACF is loaded and every time it's reloaded with the acf_reload console command. + --- @param Root table The global ACF table. + function Gamemode:ACF_OnLoadAddon() + end + + --- Called when a class group object is created, not necessarily for the first time. + --- @param ID string The ID of the group that was registered. + --- @param Group table The group object that was registered. + function Gamemode:ACF_OnCreateGroup() + end + + --- Called when a grouped item object is created, not necessarily for the first time. + --- Important to not the GroupID has to reference an actually existing class group object. + --- @param ID string The ID of the group item that was registered. + --- @param Group table The group where the item was registered. + --- @param Item table The item object that was registered. + function Gamemode:ACF_OnCreateGroupItem() + end + + --- Called when a standalone item object is created, not necessarily for the first time. + --- @param ID string The ID of the standalone item that was registered. + --- @param Item table The item object that was registered. + function Gamemode:ACF_OnCreateItem() + end + + --- Called when a class object is fully created and loaded. + --- This will not be instant on startup since the object has to wait for the base objects to load. + --- @param ID string The ID of the object class that has been loaded. + --- @param Class table The object class that has been loaded. + function Gamemode:ACF_OnLoadClass() + end + + --- Called when a server data variable value gets updated. + --- @param Player entity The player that triggered the server data variable change. + --- On the clientside, if the change was done by the client then this will always be the local player. + --- On the serverside, if the change was done by the server then this will always be nil. + --- @param Key string The name of the affected server data variable. + --- @param Value any The new value assigned to the server data variable. + function Gamemode:ACF_OnUpdateServerData() + end + + --- Called when a client data variable value gets updated. + --- On the clientside, this will be called every time the client messes with the data var. + --- This means that this hook can be called multiple times on the same tick for the same data variable. + --- On the serverside, this will be called once per tick when the value gets networked. + --- @param Player entity The player that triggered the client data variable change. + --- @param Key string The name of the affected client data variable. + --- @param Value any The new value assigned to the client data variable. + function Gamemode:ACF_OnUpdateClientData() + end + + --- Called after the Think hook is called. + --- The only difference with the Think hook are the convenience arguments provided by this one. + --- @param CurTime number Returns the uptime of the server. + --- @param DeltaTime number Returns the delay between this hook's call and the previous. + --- This value will usually be similar if not the same as the server tickrate. + function Gamemode:ACF_OnTick() + end + + --- Called when an ammo type has to provide its display information. + --- The information is only used by the spawn menu and hint bubble on entities. + --- @param AmmoType table The ammo type object requesting its display information. + --- @param Bullet table The bullet object being used to get display information. + --- @param GUIData table The display information table itself. + function Gamemode:ACF_OnGetDisplayData() + end + + --- Called when a bullet object is created or updated. + --- @param AmmoType table The ammo type object used by the bullet. + --- @param Data table The table of entity information that was used on the bullet. + --- @param Bullet table The bullet object itself. + --- @param GUIData table The table of information that's only required for the clientside, such as the menu. + --- On the serverside, this will be the same as the Bullet object. + function Gamemode:ACF_OnUpdateRound() + end + + --- Called every time a scalable entity is resized. + --- @param Entity entity The entity that got resized. + --- @param PhysObj physobj The physics object from the entity that got resized. + --- @param Size vector The new size of the entity. + --- @param Scale vector The new scale of the entity. + --- This is based off the size of the model the entity it's using and the scale that was given. + function Gamemode:ACF_OnResizeEntity() + end + + --- Called when a player attempts to use the scanner. + --- @param Player entity The player attempting to use the scanner. + --- @return boolean # False to prevent the player from scanning, otherwise true. + --- @return string # A short reason why the player is not allowed to scan. Not required if the player will be allowed to scan. + function Gamemode:ACF_PreBeginScanning() + return true + end + + --- Called just before something attempts to create an effect through ACF. + --- You can either modify the fields of the EffectTable or return an entirely new one. + --- @param EffectName string The name of the effect to be created. + --- @param EffectTable table A table containing all of the attributes of the effect. + --- @return string? # A new name for the effect to be created with. + --- @return table? # A new table of effect attributes for the effect to be created with. + function Gamemode:ACF_PreCreateEffect() + end +end) diff --git a/lua/acf/hooks/hooks_sv.lua b/lua/acf/hooks/hooks_sv.lua new file mode 100644 index 000000000..9dad2589c --- /dev/null +++ b/lua/acf/hooks/hooks_sv.lua @@ -0,0 +1,239 @@ +local Hooks = ACF.Utilities.Hooks + + +Hooks.Add("ACF_Base_Server", function(Gamemode) + --- Called when the player has properly loaded onto the server. + --- It's possible to use network messages in this hook, unlike PlayerInitialSpawn. + --- @param Player entity The player entity that just finished loading. + function Gamemode:ACF_OnLoadPlayer() + end + + --- Called when the bullet will attempt to use the default flight behavior. + --- All the values on the bullet are still updated towards the next position, even if this hook returns false. + --- To prevent this, set Bullet.HandlesOwnIteration to true. + --- @param Bullet table The bullet object that will attempt to fly in the current tick. + --- @return boolean # False if the bullet shouldn't run the default flight behavior in the currect tick. + function Gamemode:ACF_PreBulletFlight() + return true + end + + --- Called when attempting to determine if a bullet should ignore a particular entity. + --- @param Entity entity The entity hit by the bullet. + --- @param Bullet table The bullet being tested. + --- @return boolean # Return false if the bullet should filter out the entity. + function Gamemode:ACF_OnFilterBullet() + return true + end + + --- Called after the default legality checks have failed to mark the entity as illegal. + --- It is advised to not return true to prevent conflict between everything that uses this function. + --- @param Entity entity The entity that is currectly being checked for legality. + --- @return boolean # True if the entity is legal, false otherwise. + --- @return string # The reason why the entity is illegal. Not required if legal. + --- @return string # A short explanation on why the entity is illegal. Not required if legal. + --- @return number # Optionally, the amount of time in seconds the entity will remain illegal for. Not required if legal. + function Gamemode:ACF_OnCheckLegal() + return true + end + + --- Called before an ACF entity is attempted to be spawned. + --- This will only be called if the class has been registered and has a spawn function assigned to it. + --- @param Class string The entity class that is trying to be spawned. + --- @param Player entity The player attempting to spawn the entity. + --- @param Position vector The position where the entity is attempting to be spawned. + --- @param Angles angle The angles at which the entity is attempting to be spawned. + --- @param Data table A table with all the information required for the entity to set itself up. + --- @return boolean # True if the entity can be spawned, false otherwise. + --- @return string # A short explanation on why the entity can't be spawned. Not required if the entity is spawned. + function Gamemode:ACF_CanCreateEntity() + return true + end + + --- Called before an ACF entity is attempted to be spawned. + --- This will only be called if the entity is valid and has an ENT:Update method assigned to it. + --- @param Entity entity The entity that is trying to be updated. + --- @param Data table A table with all the information required for the entity to set itself up. + --- @return boolean # True if the entity can be updated, false otherwise. + --- @return string # A short explanation on why the entity can't be updated. Not required if the entity is updated. + function Gamemode:ACF_CanUpdateEntity() + return true + end + + --- Called when an ACF entity creates or updates its Wire inputs. + --- It's recommended to just push entries into the List parameter. + --- @param Entity entity The entity to create or update Wire inputs on. + --- @param List table A numerically indexed list of inputs. + --- @param Data table A key-value table with entity information, either ToolData or dupe data. + --- @param ... any A list of entries that could further add inputs without having to use the hook, usually definition groups or items. + function Gamemode:ACF_OnSetupInputs() + end + + --- Called when an ACF entity creates or updates its Wire outputs. + --- It's recommended to just push entries into the List parameter. + --- @param Entity entity The entity to create or update Wire outputs on. + --- @param List table A numerically indexed list of outputs. + --- @param Data table A key-value table with entity information, either ToolData or dupe data. + --- @param ... any A list of entries that could further add outputs without having to use the hook, usually definition groups or items. + function Gamemode:ACF_OnSetupOutputs() + end + + --- Called when an entity is attempted to be pushed by ACF.KEShove. + --- This won't be called if the entity is not valid. + --- @param Entity entity The entity that's trying to be pushed. + --- @param Position vector The world position at which the entity is attempted to be pushed. + --- @param Direction vector The direction in which the entity is attempting to be pushed. + --- @param Energy number The kinetic energy that's attempting to be applied to the entity. + --- @return boolean # True if the entity should be pushed by kinetic energy, false otherwise. + function Gamemode:ACF_OnPushEntity() + return true + end + + --- Called before a given entity receives ACF damage. + --- @param Entity entity The entity to be damaged. + --- @param DmgResult DamageResult A DamageResult object. + --- @param DmgInfo DamageInfo A DamageInfo object. + --- @return boolean # True if the given entity can be damaged, false otherwise. + function Gamemode:ACF_PreDamageEntity() + return true + end + + --- Called when a given entity is about to receive ACF damage. + --- @param Entity entity The entity to be damaged. + --- @param DmgResult DamageResult A DamageResult object. + --- @param DmgInfo DamageInfo A DamageInfo object. + function Gamemode:ACF_OnDamageEntity() + end + + --- Called after a given entity receives ACF damage. + --- @param Entity entity The entity to be damaged. + --- @param DmgResult DamageResult A DamageResult object. + --- @param DmgInfo DamageInfo A DamageInfo object. + function Gamemode:ACF_PostDamageEntity() + end + + --- Called whenever the data table needs to be verified prior attempting to spawn an entity. + --- @param Class string The entity class that's being verified. + --- @param Data table The table of entity information that's being verified. + --- @param ... any One or many tables or objects that are related to the entity, these will vary on every class. + function Gamemode:ACF_VerifyData() + end + + --- Called before an entity is attempted to be spawned. + --- This will happen after the Data table is verified. + --- @param Class string The class of the entity that's about to be spawned. + --- @param Player entity The player attempting to spawn the entity. + --- @param Data table The table of entity information that will be used on the entity. + --- @param ... any One or many tables or objects that are related to the entity, these will vary on every class. + --- @return boolean # True if the entity can be spawned, false otherwise. + function Gamemode:ACF_PreEntitySpawn() + return true + end + + --- Called after the entity is successfully spawned and almost fully initialized. + --- @param Class string The class of the entity that was spawned. + --- @param Entity entity The entity that was spawned. + --- @param Data table The table of entity information that was used on the entity. + --- @param ... any One or many tables or objects that are related to the entity, these will vary on every class. + function Gamemode:ACF_OnEntitySpawn() + end + + --- Called before an entity is attempted to be updated. + --- This will happen after the Data table is verified. + --- @param Class string The class of the entity that's about to be updated. + --- @param Entity entity The entity that's about to be updated. + --- @param Data table The table of entity information that will be used on the entity. + --- @param ... any One or many tables or objects that are related to the entity, these will vary on every class. + --- @return boolean # True if the entity can be updated, false otherwise. + --- @return string # The reason why the entity couldn't be updated. Not required if the entity can be updated. + function Gamemode:ACF_PreEntityUpdate() + return true + end + + --- Called after an entity is successfully updated. + --- @param Class string The class of the entity that was updated. + --- @param Entity entity The entity that was updated. + --- @param Data table The table of entity information that was used on the entity. + --- @param ... any One or many tables or objects that are related to the entity, these will vary on every class. + function Gamemode:ACF_OnEntityUpdate() + end + + --- Called when an entity is about to be updated or removed. + --- @param Class string The class of the entity that's about to be updated or removed. + --- @param Entity entity The entity that's about to be updated or removed. + --- @param ... any One or many tables or objects that are related to the entity, these will vary on every class. + function Gamemode:ACF_OnEntityLast() + end + + --- Called when an entity is set to store or use ammo type information. + --- @param AmmoType table The ammo type class that's about to be used. + --- @param Entity entity The entity that will be using the ammo type. + --- @param Data table The table of entity information that was used on the entity. + --- @param ... any One or many tables or objects that are related to the entity, these will vary on every class. + function Gamemode:ACF_OnAmmoFirst() + end + + --- Called when an ammo type object is about to be replaced by another one or just removed. + --- @param AmmoType table The ammo type object that will be replaced or removed. + --- @param Entity entity The entity containing the ammo type object. + function Gamemode:ACF_OnAmmoLast() + end + + --- Called when an ammo crate attempts to replenish another one. + --- @param Refill entity The ammo crate that will be providing ammunition. + --- @param Crate entity The ammo crate that will get replenished. + --- @param Amount number The quantity of ammunition that will get replenished. + --- @return boolean # True if the crate can be replenished by the refill with the given amount, false otherwise. + function Gamemode:ACF_AmmoCanRefill() + return true + end + + --- Called any time an ammo crate gets damaged and is about to start burning its ammunition. + --- @param Entity entity The affected ammo crate. + --- @return boolean # True if the ammo crate can start burning, false otherwise. + function Gamemode:ACF_AmmoCanBurn() + return true + end + + --- Called when an ammo crate attempts to create an explosion, usually due to damage. + --- @param Entity entity The affected ammo crate. + --- @return boolean # True if the ammo crate can explode, false otherwise. + function Gamemode:ACF_AmmoCanExplode() + return true + end + + --- Called when a fuel tank attempts to replenish another one. + --- @param Refill entity The tank that will be providing fuel. + --- @param FuelTank entity The tank that will be replenished. + --- @param Amount number The quantity of fuel that will get replenished. + --- @return boolean # True if the FuelTank can be replenished by the Refill with the given amount, false otherwise. + function Gamemode:ACF_FuelCanRefill() + return true + end + + --- Called when a fuel tank attempts to create an explosion, usually due to damage. + --- @param Entity entity The affected fuel tank. + --- @return boolean # True if the fuel tank can explode, false otherwise. + function Gamemode:ACF_FuelCanExplode() + return true + end + + --- Called when a weapon attempts to fire a projectile. + --- @param Entity entity The weapon attempting to fire. + --- @return boolean # True if the weapon can be fired, false otherwise. + function Gamemode:ACF_WeaponCanFire() + return true + end + + --- Called when a player switches between safezones. + --- @param Player entity The affected player. + --- @param Zone? string | nil The zone which the player moved into, could be nil. + --- @param OldZone? string | nil The zone which the player moved from, could be nil. + function Gamemode:ACF_PlayerChangedZone() + end + + --- Called when the active protection mode is changed on the server. + --- @param Mode string The currently active protection mode. + --- @param OldMode? string | nil The protection mode that was being used before, will be nil on startup. + function Gamemode:ACF_ProtectionModeChanged() + end +end) diff --git a/lua/acf/menu/items_cl/ammo_menu.lua b/lua/acf/menu/items_cl/ammo_menu.lua index 2e3ef23bd..94c168021 100644 --- a/lua/acf/menu/items_cl/ammo_menu.lua +++ b/lua/acf/menu/items_cl/ammo_menu.lua @@ -1,4 +1,5 @@ +local hook = hook local ACF = ACF local Classes = ACF.Classes local AmmoTypes = Classes.AmmoTypes @@ -10,22 +11,6 @@ local CrateText = [[ Crate Mass : %s Crate Capacity : %s round(s)]] ----Quick copy helper function for menu settings. ----@param Settings? table Lookup table containing the keys for each menu aspect that has to be omitted. ----This table can use the following keys: SuppressMenu, SuppressPreview, SuppressControls, SuppressTracer, SuppressInformation and SuppressCrateInformation. ----@return table Copy The copy of the original settings table. -local function CopySettings(Settings) - local Copy = {} - - if Settings then - for K, V in pairs(Settings) do - Copy[K] = V - end - end - - return Copy -end - ---Gets a key-value table of all the ammo type objects a given weapon class can make use of. ---@param Class string The ammo type ID that will be checked. ---@return table Result The ammo type objects said weapon class can use. @@ -66,34 +51,90 @@ end ---Creates the entity preview panel on the ACF menu. ---@param Base userdata The panel being populated with the preview. ----@param Settings table The lookup table containing all the settings for the menu. ---This function will only use SuppressPreview. If it's defined, this function will effectively do nothing. ---@param ToolData table The copy of the local player's client data variables. -local function AddPreview(Base, Settings, ToolData) - if Settings.SuppressPreview then return end +local function AddPreview(Base, ToolData) + if Ammo.PreCreateAmmoPreview then + local Result = Ammo:PreCreateAmmoPreview(Base, ToolData, BulletData) + + if not Result then return end + end + + local Result = hook.Run("ACF_PreCreateAmmoPreview", Base, ToolData, Ammo, BulletData) + + if not Result then return end local Preview = Base:AddModelPreview(nil, true) local Setup = {} - if Ammo.AddAmmoPreview then - Ammo:AddAmmoPreview(Preview, Setup, ToolData, BulletData) + if Ammo.OnCreateAmmoPreview then + Ammo:OnCreateAmmoPreview(Preview, Setup, ToolData, BulletData) end - hook.Run("ACF_AddAmmoPreview", Preview, Setup, ToolData, Ammo, BulletData) + hook.Run("ACF_OnCreateAmmoPreview", Preview, Setup, ToolData, Ammo, BulletData) Preview:UpdateModel(Setup.Model) Preview:UpdateSettings(Setup) end +local function AddTracer(Base, ToolData) + if Ammo.PreCreateTracerControls then + local Result = Ammo:PreCreateTracerControls(Base, ToolData, BulletData) + + if not Result then + ACF.SetClientData("Tracer", false) + + return + end + end + + local Result = hook.Run("ACF_PreCreateTracerControls", Base, ToolData, Ammo, BulletData) + + if not Result then + ACF.SetClientData("Tracer", false) + + return + end + + local Tracer = Base:AddCheckBox("Tracer") + Tracer:SetClientData("Tracer", "OnChange") + Tracer:DefineSetter(function(Panel, _, _, Value) + ToolData.Tracer = Value + + Ammo:UpdateRoundData(ToolData, BulletData) + + ACF.SetClientData("Projectile", BulletData.ProjLength) + ACF.SetClientData("Propellant", BulletData.PropLength) + + Panel:SetText("Tracer : " .. BulletData.Tracer .. " cm") + Panel:SetValue(ToolData.Tracer) + + return ToolData.Tracer + end) + + if Ammo.OnCreateTracerControls then + Ammo:OnCreateTracerControls(Base, ToolData, BulletData) + end + + hook.Run("ACF_OnCreateTracerControls", Base, ToolData, Ammo, BulletData) +end + ---Creates the ammunition control panels on the ACF menu. ---@param Base userdata The panel being populated with the ammunition controls. ----@param Settings table The lookup table containing all the settings for the menu. ---This function makes use of SuppressControls and SuppressTracer. ---If the first is defined, this function will effectively do nothing. ---If the latter is defined, only the Tracer checkbox will be omitted and the Tracer client data variable will be set to false. ---@param ToolData table The copy of the local player's client data variables. -local function AddControls(Base, Settings, ToolData) - if Settings.SuppressControls then return end +local function AddControls(Base, ToolData) + if Ammo.PreCreateAmmoControls then + local Result = Ammo:PreCreateAmmoControls(Base, ToolData, BulletData) + + if not Result then return end + end + + local Result = hook.Run("ACF_PreCreateAmmoControls", Base, ToolData, Ammo, BulletData) + + if not Result then return end local RoundLength = Base:AddLabel() RoundLength:TrackClientData("Projectile", "SetText", "GetText") @@ -143,78 +184,72 @@ local function AddControls(Base, Settings, ToolData) return BulletData.PropLength end) - if Ammo.AddAmmoControls then - Ammo:AddAmmoControls(Base, ToolData, BulletData) + if Ammo.OnCreateAmmoControls then + Ammo:OnCreateAmmoControls(Base, ToolData, BulletData) end - hook.Run("ACF_AddAmmoControls", Base, ToolData, Ammo, BulletData) - - -- We'll create the tracer checkbox after all the other controls - if not Settings.SuppressTracer then - local Tracer = Base:AddCheckBox("Tracer") - Tracer:SetClientData("Tracer", "OnChange") - Tracer:DefineSetter(function(Panel, _, _, Value) - ToolData.Tracer = Value - - Ammo:UpdateRoundData(ToolData, BulletData) - - ACF.SetClientData("Projectile", BulletData.ProjLength) - ACF.SetClientData("Propellant", BulletData.PropLength) + hook.Run("ACF_OnCreateAmmoControls", Base, ToolData, Ammo, BulletData) - Panel:SetText("Tracer : " .. BulletData.Tracer .. " cm") - Panel:SetValue(ToolData.Tracer) - - return ToolData.Tracer - end) - else - ACF.SetClientData("Tracer", false) -- Disabling the tracer, as it takes up spaces on ammo. - end + AddTracer(Base, ToolData) end ---Creates the ammunition information panels on the ACF menu. ---@param Base userdata The panel being populated with the ammunition information. ----@param Settings table The lookup table containing all the settings for the menu. ---This function makes use of SuppressInformation and SuppressCrateInformation ---If the first is defined, this function will effectively do nothing. ---If the latter is defined, only the information regarding the ammo crate (armor, mass and capacity by default) will be omitted. ---@param ToolData table The copy of the local player's client data variables. -local function AddInformation(Base, Settings, ToolData) - if Settings.SuppressInformation then return end - - if not Settings.SuppressCrateInformation then - local Trackers = {} - - local Crate = Base:AddLabel() - Crate:TrackClientData("Weapon", "SetText") - Crate:TrackClientData("CrateSizeX") - Crate:TrackClientData("CrateSizeY") - Crate:TrackClientData("CrateSizeZ") - Crate:DefineSetter(function() - local Class = GetWeaponClass(ToolData) - local Rounds = ACF.GetAmmoCrateCapacity(BoxSize, Class, ToolData, BulletData) - local Empty = GetEmptyMass() - local Load = math.floor(BulletData.CartMass * Rounds) - local Mass = ACF.GetProperMass(math.floor(Empty + Load)) - - return CrateText:format(ACF.AmmoArmor, Mass, Rounds) - end) - - if Ammo.AddCrateDataTrackers then - Ammo:AddCrateDataTrackers(Trackers, ToolData, BulletData) - end +local function AddInformation(Base, ToolData) + if Ammo.PreCreateCrateInformation then + local Result = Ammo:PreCreateCrateInformation(Base, ToolData, BulletData) - hook.Run("ACF_AddCrateDataTrackers", Trackers, ToolData, Ammo, BulletData) + if not Result then return end + end - for Tracker in pairs(Trackers) do - Crate:TrackClientData(Tracker) - end + local Result = hook.Run("ACF_PreCreateCrateInformation", Base, ToolData, Ammo, BulletData) + + if not Result then return end + + local Crate = Base:AddLabel() + Crate:TrackClientData("Weapon", "SetText") + Crate:TrackClientData("CrateSizeX") + Crate:TrackClientData("CrateSizeY") + Crate:TrackClientData("CrateSizeZ") + Crate:DefineSetter(function() + local Class = GetWeaponClass(ToolData) + local Rounds = ACF.GetAmmoCrateCapacity(BoxSize, Class, ToolData, BulletData) + local Empty = GetEmptyMass() + local Load = math.floor(BulletData.CartMass * Rounds) + local Mass = ACF.GetProperMass(math.floor(Empty + Load)) + + return CrateText:format(ACF.AmmoArmor, Mass, Rounds) + end) + + if Ammo.OnCreateCrateInformation then + Ammo:OnCreateCrateInformation(Base, Crate, ToolData, BulletData) end - if Ammo.AddAmmoInformation then - Ammo:AddAmmoInformation(Base, ToolData, BulletData) + hook.Run("ACF_OnCreateCrateInformation", Base, Crate, ToolData, Ammo, BulletData) +end + +local function AddInformation(Base, ToolData) + if Ammo.PreCreateAmmoInformation then + local Result = Ammo:PreCreateAmmoInformation(Base, ToolData, BulletData) + + if not Result then return end + end + + local Result = hook.Run("ACF_PreCreateAmmoInformation", Base, ToolData, Ammo, BulletData) + + if not Result then return end + + AddCrateInformation(Base, ToolData) + + if Ammo.OnCreateAmmoInformation then + Ammo:OnCreateAmmoInformation(Base, ToolData, BulletData) end - hook.Run("ACF_AddAmmoInformation", Base, ToolData, Ammo, BulletData) + hook.Run("ACF_OnCreateAmmoInformation", Base, ToolData, Ammo, BulletData) end local function AddGraph(Base, ToolData) @@ -345,31 +380,41 @@ function ACF.UpdateAmmoMenu(Menu, Settings) local Base = Menu.AmmoBase BulletData = Ammo:ClientConvert(ToolData) - Settings = CopySettings(Settings) - if Ammo.SetupAmmoMenuSettings then - Ammo:SetupAmmoMenuSettings(Settings, ToolData, BulletData) + Menu:ClearTemporal(Base) + + if Ammo.PreCreateAmmoMenu then + local Result = Ammo:PreCreateAmmoMenu(ToolData, BulletData) + + if not Result then return end end - hook.Run("ACF_SetupAmmoMenuSettings", Settings, ToolData, Ammo, BulletData) + local Result = hook.Run("ACF_PreCreateAmmoMenu", ToolData, Ammo, BulletData) + + if not Result then return end - Menu:ClearTemporal(Base) Menu:StartTemporal(Base) + if Ammo.OnCreateAmmoMenu then + Ammo:OnCreateAmmoMenu(Base, ToolData, BulletData) + end + if not Settings.SuppressMenu then - AddPreview(Base, Settings, ToolData) - AddControls(Base, Settings, ToolData) - AddInformation(Base, Settings, ToolData) AddGraph(Base, ToolData) end + hook.Run("ACF_OnCreateAmmoMenu", Base, ToolData, Ammo, BulletData) + + AddPreview(Base, ToolData) + AddControls(Base, ToolData) + AddInformation(Base, ToolData) + Menu:EndTemporal(Base) end ---Creates the basic information and panels on the ammunition menu. ---@param Menu userdata The panel in which the entire ACF menu is being placed on. ----@param Settings? table The lookup table containing all the settings for the menu. -function ACF.CreateAmmoMenu(Menu, Settings) +function ACF.CreateAmmoMenu(Menu) Menu:AddTitle("Ammo Settings") local List = Menu:AddComboBox() @@ -431,7 +476,7 @@ function ACF.CreateAmmoMenu(Menu, Settings) Desc:SetText(Data.Description) - ACF.UpdateAmmoMenu(Menu, Settings) + ACF.UpdateAmmoMenu(Menu) end Menu.AmmoBase = Base diff --git a/lua/acf/menu/items_cl/fun_entities.lua b/lua/acf/menu/items_cl/fun_entities.lua index 5399e9085..76dc3ec09 100644 --- a/lua/acf/menu/items_cl/fun_entities.lua +++ b/lua/acf/menu/items_cl/fun_entities.lua @@ -192,7 +192,7 @@ do -- Procedural Armor ACF.AddMenuItem(2, "Fun Stuff", "Armor", "brick", CreateMenu) end -hook.Add("ACF_AllowMenuOption", "Allow Fun Menu", function(_, Name) +hook.Add("ACF_OnEnableMenuOption", "Enable Fun Menu", function(Name) if Name ~= "Fun Stuff" then return end if not ACF.GetServerBool("ShowFunMenu") then return false end end) diff --git a/lua/acf/menu/items_cl/updates.lua b/lua/acf/menu/items_cl/updates.lua index f9c4d95f0..9022c2cda 100644 --- a/lua/acf/menu/items_cl/updates.lua +++ b/lua/acf/menu/items_cl/updates.lua @@ -81,7 +81,7 @@ end ACF.AddMenuItem(1, "About the Addon", "Updates", "newspaper", CreateMenu) -hook.Add("ACF_UpdatedRepository", "ACF Updates Menu", function(Name, Repo) +hook.Add("ACF_OnFetchRepository", "ACF Updates Menu", function(Name, Repo) if Name ~= "ACF-3" then return end Repository = Repo diff --git a/lua/acf/menu/items_cl/weapons.lua b/lua/acf/menu/items_cl/weapons.lua index ef8f07926..3c65d9e4f 100644 --- a/lua/acf/menu/items_cl/weapons.lua +++ b/lua/acf/menu/items_cl/weapons.lua @@ -165,7 +165,7 @@ local function GetMass(Panel, Caliber, Class, Weapon) if not Base then if ModelData.IsOnStandby(Model) then - ModelData.QueueRefresh(Model, Panel, function() + ModelData.CallOnReceive(Model, Panel, function() Panel:SetText(Panel:GetText()) end) end diff --git a/lua/acf/menu/operations/acf_copy.lua b/lua/acf/menu/operations/acf_copy.lua index 48a5cfa11..0e59a4850 100644 --- a/lua/acf/menu/operations/acf_copy.lua +++ b/lua/acf/menu/operations/acf_copy.lua @@ -25,7 +25,7 @@ if SERVER then DisabledData[Data] = State end) - hook.Add("ACF_OnPlayerLoaded", "ACF Copy Data", function(Player) + hook.Add("ACF_OnLoadPlayer", "ACF Copy Data", function(Player) CopiedData[Player] = {} Disabled[Player] = {} end) diff --git a/lua/acf/menu/spawn_menu_cl.lua b/lua/acf/menu/spawn_menu_cl.lua index 1d35ad729..348fa20a7 100644 --- a/lua/acf/menu/spawn_menu_cl.lua +++ b/lua/acf/menu/spawn_menu_cl.lua @@ -1,9 +1,12 @@ +local hook = hook +local ACF = ACF + ACF.MenuOptions = ACF.MenuOptions or {} -ACF.MenuLookup = ACF.MenuLookup or {} -ACF.MenuCount = ACF.MenuCount or 0 +ACF.MenuLookup = ACF.MenuLookup or {} +ACF.MenuCount = ACF.MenuCount or 0 local Options = ACF.MenuOptions -local Lookup = ACF.MenuLookup +local Lookup = ACF.MenuLookup do -- Menu population functions local function DefaultAction(Menu) @@ -98,13 +101,17 @@ do -- ACF Menu context panel local function AllowOption(Option) if Option.IsEnabled and not Option:IsEnabled() then return false end - return hook.Run("ACF_AllowMenuOption", Option.Index, Option.Name) ~= false + local Allow = hook.Run("ACF_OnEnableMenuOption", Option.Name) + + return Allow end local function AllowItem(Item) if Item.IsEnabled and not Item:IsEnabled() then return false end - return hook.Run("ACF_AllowMenuItem", Item.Index, Item.Option, Item.Name) ~= false + local Allow = hook.Run("ACF_OnEnableMenuItem", Item.Option, Item.Name) + + return Allow end local function UpdateTree(Tree, Old, New) @@ -246,9 +253,42 @@ do -- Client and server settings -- ACF.RemoveServerSettings(Name) -- ACF.GenerateServerSettings(MenuPanel) + --- Uses the following hooks: + -- ACF_PreLoadServerSettings + -- ACF_OnLoadServerSettings + -- ACF_PostLoadServerSettings + -- ACF_PreLoadClientSettings + -- ACF_OnLoadClientSettings + -- ACF_PostLoadClientSettings + for Realm, Destiny in pairs(Settings) do - local Hook = "ACF_On" .. Realm .. "SettingsLoaded" - local Message = "No %sside settings have been registered." + local PreHook = "ACF_PreLoad" .. Realm .. "Settings" + local OnHook = "ACF_OnLoad" .. Realm .. "Settings" + local PostHook = "ACF_PostLoad" .. Realm .. "Settings" + local Message = "No %sside settings have been registered." + + local function CreateSection(Menu, Name, Data) + local Result = hook.Run(PreHook, Name) + + if not Result then return end + + local Base, Section = Menu:AddCollapsible(Name, false) + + function Section:OnToggle(Bool) + if not Bool then return end + if self.Created then return end + + local Result = hook.Run(OnHook, Name, Base) + + if not Result then + Data.Create(Base) + end + + hook.Run(PostHook, Name, Base) + + self.Created = true + end + end ACF["Add" .. Realm .. "Settings"] = function(Index, Name, Function) if not isnumber(Index) then return end @@ -273,22 +313,12 @@ do -- Client and server settings if not next(Destiny) then Menu:AddTitle("Nothing to see here.") Menu:AddLabel(Message:format(Realm)) + return end for Name, Data in SortedPairsByMemberValue(Destiny, "Index") do - local Base, Section = Menu:AddCollapsible(Name, false) - - function Section:OnToggle(Bool) - if not Bool then return end - if self.Created then return end - - Data.Create(Base) - - hook.Run(Hook, Name, Base) - - self.Created = true - end + CreateSection(Menu, Name, Data) end end end diff --git a/lua/acf/menu/tool_functions.lua b/lua/acf/menu/tool_functions.lua index 8b0648e64..1efecf050 100644 --- a/lua/acf/menu/tool_functions.lua +++ b/lua/acf/menu/tool_functions.lua @@ -485,7 +485,7 @@ end do -- Clientside Tool interaction if SERVER then -- When the client specifies a new tool mode, switch to the new stage and operation. - hook.Add("ACF_OnClientDataUpdate", "ACF ToolMode", function(Player, Key, Value) + hook.Add("ACF_OnUpdateClientData", "ACF ToolMode", function(Player, Key, Value) --- Check if the key is of the form (e.g. "ToolMode:acf_menu"/"ToolMode:acf_copy") local Header, Name = unpack(string.Explode(":", Key), 1, 2) if Header ~= "ToolMode" then return end diff --git a/lua/acf/scanner/scanner_sh.lua b/lua/acf/scanner/scanner_sh.lua index 91d03dee6..bd591d595 100644 --- a/lua/acf/scanner/scanner_sh.lua +++ b/lua/acf/scanner/scanner_sh.lua @@ -283,7 +283,7 @@ if SERVER then function scanning.BeginScanning(playerScanning, targetPlayer) if not IsValid(playerScanning) then return end if not IsValid(targetPlayer) then scanning.EndScanning() return end - if hook.Run("ACF_PreBeginScanning", playerScanning) == false then return end + if not hook.Run("ACF_PreBeginScanning", playerScanning) then return end if playerScanning:InVehicle() then return end scanningPlayers[playerScanning] = { @@ -942,7 +942,7 @@ if CLIENT then Derma_Message("You cannot scan a target while being in a vehicle. Exit the vehicle, then try again.", "Scanning Blocked", "OK") return end local canScan, whyNot = hook.Run("ACF_PreBeginScanning", LocalPlayer()) - if canScan == false then + if not canScan then Derma_Message("Scanning has been blocked by the server: " .. (whyNot or ""), "Scanning Blocked", "OK") return end diff --git a/lua/effects/acf_bullet_effect.lua b/lua/effects/acf_bullet_effect.lua index 7490d4f77..23899f943 100644 --- a/lua/effects/acf_bullet_effect.lua +++ b/lua/effects/acf_bullet_effect.lua @@ -87,11 +87,7 @@ function EFFECT:Init(Data) self.DrawEffect = CanDraw - local CustomEffect = hook.Run("ACF_BulletEffect", BulletData.AmmoType) - - if CustomEffect then - self.ApplyMovement = CustomEffect - end + hook.Run("ACF_OnCreateBulletEffect", self, BulletData) end end diff --git a/lua/entities/acf_ammo/init.lua b/lua/entities/acf_ammo/init.lua index 707132078..e92bd2f11 100644 --- a/lua/entities/acf_ammo/init.lua +++ b/lua/entities/acf_ammo/init.lua @@ -27,7 +27,6 @@ local ActiveCrates = ACF.AmmoCrates local Utilities = ACF.Utilities local TimerCreate = timer.Create local TimerExists = timer.Exists -local HookRun = hook.Run do -- Spawning and Updating -------------------- local Classes = ACF.Classes @@ -139,7 +138,7 @@ do -- Spawning and Updating -------------------- Class.VerifyData(Data, Class, Ammo) end - HookRun("ACF_VerifyData", "acf_ammo", Data, Class, Ammo) + hook.Run("ACF_VerifyData", "acf_ammo", Data, Class, Ammo) end end end @@ -161,7 +160,7 @@ do -- Spawning and Updating -------------------- OldAmmo:OnLast(Entity) end - HookRun("ACF_OnAmmoLast", OldAmmo, Entity) + hook.Run("ACF_OnAmmoLast", OldAmmo, Entity) end Entity.RoundData = Ammo @@ -172,7 +171,7 @@ do -- Spawning and Updating -------------------- Ammo:OnFirst(Entity) end - HookRun("ACF_OnAmmoFirst", Ammo, Entity, Data, Class, Weapon) + hook.Run("ACF_OnAmmoFirst", Ammo, Entity, Data, Class, Weapon) Ammo:Network(Entity, Entity.BulletData) end @@ -285,7 +284,7 @@ do -- Spawning and Updating -------------------- local Ammo = AmmoTypes.Get(Data.AmmoType) -- The class representing this ammo type local Model = "models/holograms/hq_rcube_thin.mdl" - local CanSpawn = HookRun("ACF_PreEntitySpawn", "acf_ammo", Player, Data, Class, Weapon, Ammo) + local CanSpawn = hook.Run("ACF_PreEntitySpawn", "acf_ammo", Player, Data, Class, Weapon, Ammo) if CanSpawn == false then return false end @@ -320,7 +319,7 @@ do -- Spawning and Updating -------------------- Class.OnSpawn(Crate, Data, Class, Weapon, Ammo) end - HookRun("ACF_OnEntitySpawn", "acf_ammo", Crate, Data, Class, Weapon, Ammo) + hook.Run("ACF_OnEntitySpawn", "acf_ammo", Crate, Data, Class, Weapon, Ammo) Crate:UpdateOverlay(true) @@ -371,14 +370,14 @@ do -- Spawning and Updating -------------------- local Blacklist = Ammo.Blacklist local Extra = "" - local CanUpdate, Reason = HookRun("ACF_PreEntityUpdate", "acf_ammo", self, Data, Class, Weapon, Ammo) + local CanUpdate, Reason = hook.Run("ACF_PreEntityUpdate", "acf_ammo", self, Data, Class, Weapon, Ammo) if CanUpdate == false then return CanUpdate, Reason end if OldClass.OnLast then OldClass.OnLast(self, OldClass) end - HookRun("ACF_OnEntityLast", "acf_ammo", self, OldClass) + hook.Run("ACF_OnEntityLast", "acf_ammo", self, OldClass) ACF.SaveEntity(self) @@ -390,7 +389,7 @@ do -- Spawning and Updating -------------------- Class.OnUpdate(self, Data, Class, Weapon, Ammo) end - HookRun("ACF_OnEntityUpdate", "acf_ammo", self, Data, Class, Weapon, Ammo) + hook.Run("ACF_OnEntityUpdate", "acf_ammo", self, Data, Class, Weapon, Ammo) if Data.Weapon ~= OldWeapon or Caliber ~= OldCaliber or self.Unlinkable then -- Unlink if the weapon type or caliber has changed @@ -513,9 +512,11 @@ do -- ACF Activation and Damage ----------------- local Ratio = (HitRes.Damage / self.BulletData.RoundVolume) ^ 0.2 if (Ratio * self.Capacity / self.Ammo) > math.random() then + local CanBurn = hook.Run("ACF_AmmoCanBurn", self) + self.Inflictor = Inflictor - if HookRun("ACF_AmmoCanCookOff", self) ~= false then + if CanBurn then self.Damaged = Clock.CurTime + (5 - Ratio * 3) -- Time to cook off is 5 - (How filled it is * 3) local Interval = 0.01 + self.BulletData.RoundVolume ^ 0.5 / 100 @@ -535,7 +536,10 @@ do -- ACF Activation and Damage ----------------- function ENT:Detonate() if self.Exploding then return end - if HookRun("ACF_AmmoExplode", self) == false then return end + + local CanExplode = hook.Run("ACF_AmmoCanExplode", self) + + if not CanExplode then return end self.Exploding = true @@ -703,7 +707,7 @@ do -- Misc -------------------------------------- Class.OnLast(self, Class) end - HookRun("ACF_OnEntityLast", "acf_ammo", self, Class) + hook.Run("ACF_OnEntityLast", "acf_ammo", self, Class) ActiveCrates[self] = nil diff --git a/lua/entities/acf_armor/init.lua b/lua/entities/acf_armor/init.lua index 315d28e8f..50138bf54 100644 --- a/lua/entities/acf_armor/init.lua +++ b/lua/entities/acf_armor/init.lua @@ -132,7 +132,7 @@ do -- Spawning and Updating OldArmor:OnLast(self) end - hook.Run("ACF_OnEntityLast", "acf_armor", self, OldClass) + hook.Run("ACF_OnEntityLast", "acf_armor", self, OldArmor) ACF.SaveEntity(self) diff --git a/lua/entities/acf_engine/init.lua b/lua/entities/acf_engine/init.lua index fb1f4fe3c..25e4e70ba 100644 --- a/lua/entities/acf_engine/init.lua +++ b/lua/entities/acf_engine/init.lua @@ -125,7 +125,6 @@ local min = math.min local TimerCreate = timer.Create local TimerSimple = timer.Simple local TimerRemove = timer.Remove -local HookRun = hook.Run local TickInterval = engine.TickInterval local function GetPitchVolume(Engine) @@ -275,7 +274,7 @@ do -- Spawn and Update functions Class.VerifyData(Data, Class, Engine) end - HookRun("ACF_VerifyData", "acf_engine", Data, Class, Engine) + hook.Run("ACF_VerifyData", "acf_engine", Data, Class, Engine) end end @@ -352,7 +351,7 @@ do -- Spawn and Update functions if not Player:CheckLimit(Limit) then return false end - local CanSpawn = HookRun("ACF_PreEntitySpawn", "acf_engine", Player, Data, Class, Engine) + local CanSpawn = hook.Run("ACF_PreEntitySpawn", "acf_engine", Player, Data, Class, Engine) if CanSpawn == false then return false end @@ -398,7 +397,7 @@ do -- Spawn and Update functions Class.OnSpawn(Entity, Data, Class, Engine) end - HookRun("ACF_OnEntitySpawn", "acf_engine", Entity, Data, Class, Engine) + hook.Run("ACF_OnEntitySpawn", "acf_engine", Entity, Data, Class, Engine) Entity:UpdateOverlay(true) @@ -425,7 +424,7 @@ do -- Spawn and Update functions local OldClass = self.ClassData local Feedback = "" - local CanUpdate, Reason = HookRun("ACF_PreEntityUpdate", "acf_engine", self, Data, Class, Engine) + local CanUpdate, Reason = hook.Run("ACF_PreEntityUpdate", "acf_engine", self, Data, Class, Engine) if CanUpdate == false then return CanUpdate, Reason end @@ -433,7 +432,7 @@ do -- Spawn and Update functions OldClass.OnLast(self, OldClass) end - HookRun("ACF_OnEntityLast", "acf_engine", self, OldClass) + hook.Run("ACF_OnEntityLast", "acf_engine", self, OldClass) ACF.SaveEntity(self) @@ -445,7 +444,7 @@ do -- Spawn and Update functions Class.OnUpdate(self, Data, Class, Engine) end - HookRun("ACF_OnEntityUpdate", "acf_engine", self, Data, Class, Engine) + hook.Run("ACF_OnEntityUpdate", "acf_engine", self, Data, Class, Engine) if next(self.Gearboxes) then local Count, Total = 0, 0 @@ -875,7 +874,7 @@ function ENT:OnRemove() Class.OnLast(self, Class) end - HookRun("ACF_OnEntityLast", "acf_engine", self, Class) + hook.Run("ACF_OnEntityLast", "acf_engine", self, Class) self:DestroySound() diff --git a/lua/entities/acf_fueltank/init.lua b/lua/entities/acf_fueltank/init.lua index 6e4e41a24..9731eb3eb 100644 --- a/lua/entities/acf_fueltank/init.lua +++ b/lua/entities/acf_fueltank/init.lua @@ -256,6 +256,7 @@ do -- Spawn and Update functions local Feedback = "" local CanUpdate, Reason = HookRun("ACF_PreEntityUpdate", "acf_fueltank", self, Data, Class, FuelTank) + if CanUpdate == false then return CanUpdate, Reason end if OldClass.OnLast then @@ -340,7 +341,9 @@ function ENT:ACF_OnDamage(DmgResult, DmgInfo) if self.Exploding or NoExplode or not self.IsExplosive then return HitRes end if HitRes.Kill then - if HookRun("ACF_FuelExplode", self) == false then return HitRes end + local CanExplode = HookRun("ACF_FuelCanExplode", self) + + if not CanExplode then return HitRes end local Inflictor = DmgInfo:GetInflictor() @@ -358,7 +361,9 @@ function ENT:ACF_OnDamage(DmgResult, DmgInfo) -- It's gonna blow if math.random() < (ExplodeChance + Ratio) then - if HookRun("ACF_FuelExplode", self) == false then return HitRes end + local CanExplode = HookRun("ACF_FuelCanExplode", self) + + if not CanExplode then return HitRes end self.Inflictor = Inflictor @@ -544,10 +549,13 @@ do local Position = self:GetPos() for Tank in pairs(ACF.FuelTanks) do - if CanRefuel(self, Tank, Position:DistToSqr(Tank:GetPos())) then - local Exchange = math.min(DeltaTime * ACF.RefuelSpeed * ACF.FuelRate, self.Fuel, Tank.Capacity - Tank.Fuel) + local Distance = Position:DistToSqr(Tank:GetPos()) + + if CanRefuel(self, Tank, Distance) then + local Exchange = math.min(DeltaTime * ACF.RefuelSpeed * ACF.FuelRate, self.Fuel, Tank.Capacity - Tank.Fuel) + local CanRefill = hook.Run("ACF_FuelCanRefill", self, Tank, Exchange) - if HookRun("ACF_CanRefuel", self, Tank, Exchange) == false then continue end + if not CanRefill then continue end self:Consume(Exchange) Tank:Consume(-Exchange) diff --git a/lua/entities/acf_gearbox/init.lua b/lua/entities/acf_gearbox/init.lua index 85eee5951..04adb42bd 100644 --- a/lua/entities/acf_gearbox/init.lua +++ b/lua/entities/acf_gearbox/init.lua @@ -14,7 +14,6 @@ local Clock = Utilities.Clock local Clamp = math.Clamp local abs = math.abs local min = math.min -local HookRun = hook.Run local MaxDistance = ACF.LinkDistance * ACF.LinkDistance local function CalcWheel(Entity, Link, Wheel, SelfWorld) @@ -102,7 +101,7 @@ do -- Spawn and Update functions ----------------------- Class.VerifyData(Data, Class) end - HookRun("ACF_VerifyData", "acf_gearbox", Data, Class) + hook.Run("ACF_VerifyData", "acf_gearbox", Data, Class) end end @@ -229,7 +228,7 @@ do -- Spawn and Update functions ----------------------- if not Player:CheckLimit(Limit) then return end - local CanSpawn = HookRun("ACF_PreEntitySpawn", "acf_gearbox", Player, Data, Class, Gearbox) + local CanSpawn = hook.Run("ACF_PreEntitySpawn", "acf_gearbox", Player, Data, Class, Gearbox) if CanSpawn == false then return false end @@ -274,7 +273,7 @@ do -- Spawn and Update functions ----------------------- Class.OnSpawn(Entity, Data, Class, Gearbox) end - HookRun("ACF_OnEntitySpawn", "acf_gearbox", Entity, Data, Class, Gearbox) + hook.Run("ACF_OnEntitySpawn", "acf_gearbox", Entity, Data, Class, Gearbox) Entity:UpdateOverlay(true) @@ -309,14 +308,14 @@ do -- Spawn and Update functions ----------------------- local OldClass = self.ClassData local Feedback = "" - local CanUpdate, Reason = HookRun("ACF_PreEntityUpdate", "acf_gearbox", self, Data, Class, Gearbox) + local CanUpdate, Reason = hook.Run("ACF_PreEntityUpdate", "acf_gearbox", self, Data, Class, Gearbox) if CanUpdate == false then return CanUpdate, Reason end if OldClass.OnLast then OldClass.OnLast(self, OldClass) end - HookRun("ACF_OnEntityLast", "acf_gearbox", self, OldClass) + hook.Run("ACF_OnEntityLast", "acf_gearbox", self, OldClass) ACF.SaveEntity(self) @@ -328,7 +327,7 @@ do -- Spawn and Update functions ----------------------- Class.OnUpdate(self, Data, Class, Gearbox) end - HookRun("ACF_OnEntityUpdate", "acf_gearbox", self, Data, Class, Gearbox) + hook.Run("ACF_OnEntityUpdate", "acf_gearbox", self, Data, Class, Gearbox) if next(self.Engines) then local Count, Total = 0, 0 @@ -1115,7 +1114,7 @@ do -- Miscellaneous ------------------------------------ Class.OnLast(self, Class) end - HookRun("ACF_OnEntityLast", "acf_gearbox", self, Class) + hook.Run("ACF_OnEntityLast", "acf_gearbox", self, Class) for Engine in pairs(self.Engines) do self:Unlink(Engine) diff --git a/lua/entities/acf_gun/init.lua b/lua/entities/acf_gun/init.lua index 9dbaa2433..de1b96159 100644 --- a/lua/entities/acf_gun/init.lua +++ b/lua/entities/acf_gun/init.lua @@ -13,7 +13,6 @@ local Utilities = ACF.Utilities local Clock = Utilities.Clock local Sounds = Utilities.Sounds local TimerCreate = timer.Create -local HookRun = hook.Run local EMPTY = { Type = "Empty", PropMass = 0, ProjMass = 0, Tracer = 0 } -- TODO: Replace with CFrame as soon as it's available @@ -92,7 +91,7 @@ do -- Spawn and Update functions -------------------------------- Class.VerifyData(Data, Class) end - HookRun("ACF_VerifyData", "acf_gun", Data, Class) + hook.Run("ACF_VerifyData", "acf_gun", Data, Class) end end @@ -221,7 +220,7 @@ do -- Spawn and Update functions -------------------------------- if not Player:CheckLimit(Limit) then return false end -- Check gun spawn limits local Weapon = Weapons.GetItem(Class.ID, Data.Weapon) - local CanSpawn = HookRun("ACF_PreEntitySpawn", "acf_gun", Player, Data, Class, Weapon) + local CanSpawn = hook.Run("ACF_PreEntitySpawn", "acf_gun", Player, Data, Class, Weapon) if CanSpawn == false then return false end @@ -265,7 +264,7 @@ do -- Spawn and Update functions -------------------------------- Class.OnSpawn(Entity, Data, Class, Weapon) end - HookRun("ACF_OnEntitySpawn", "acf_gun", Entity, Data, Class, Weapon) + hook.Run("ACF_OnEntitySpawn", "acf_gun", Entity, Data, Class, Weapon) Entity:UpdateOverlay(true) @@ -295,7 +294,7 @@ do -- Spawn and Update functions -------------------------------- local Weapon = Weapons.GetItem(Class.ID, Data.Weapon) local OldClass = self.ClassData - local CanUpdate, Reason = HookRun("ACF_PreEntityUpdate", "acf_gun", self, Data, Class, Weapon) + local CanUpdate, Reason = hook.Run("ACF_PreEntityUpdate", "acf_gun", self, Data, Class, Weapon) if CanUpdate == false then return CanUpdate, Reason end @@ -307,7 +306,7 @@ do -- Spawn and Update functions -------------------------------- OldClass.OnLast(self, OldClass) end - HookRun("ACF_OnEntityLast", "acf_gun", self, OldClass) + hook.Run("ACF_OnEntityLast", "acf_gun", self, OldClass) ACF.SaveEntity(self) @@ -319,7 +318,7 @@ do -- Spawn and Update functions -------------------------------- Class.OnUpdate(self, Data, Class, Weapon) end - HookRun("ACF_OnEntityUpdate", "acf_gun", self, Data, Class, Weapon) + hook.Run("ACF_OnEntityUpdate", "acf_gun", self, Data, Class, Weapon) if next(self.Crates) then for Crate in pairs(self.Crates) do @@ -518,15 +517,17 @@ do -- Metamethods -------------------------------- return false end + if self.TurretLink and IsValid(self.Turret) then -- Special link to a turret, will block the gun from firing if the gun is not aligned with the turret's target angle local Turret = self.Turret if not Turret.Active then return false end if self:GetForward():Dot(Turret.SlewFuncs.GetWorldTarget(Turret):Forward()) < 0.9961 then return false end end - if HookRun("ACF_FireShell", self) == false then return false end -- Something hooked into ACF_FireShell said no - return true + local CanFire = hook.Run("ACF_WeaponCanFire", self) + + return CanFire end function ENT:GetSpread() @@ -930,7 +931,7 @@ do -- Metamethods -------------------------------- Class.OnLast(self, Class) end - HookRun("ACF_OnEntityLast", "acf_gun", self, Class) + hook.Run("ACF_OnEntityLast", "acf_gun", self, Class) for Crate in pairs(self.Crates) do self:Unlink(Crate) diff --git a/lua/entities/acf_piledriver/init.lua b/lua/entities/acf_piledriver/init.lua index 582de99bf..3d6ab8a2d 100644 --- a/lua/entities/acf_piledriver/init.lua +++ b/lua/entities/acf_piledriver/init.lua @@ -326,9 +326,11 @@ do -- Firing ------------------------------------ function ENT:CanShoot() if not ACF.GunsCanFire then return false end if not ACF.AllowFunEnts then return false end - if hook.Run("ACF_FireShell", self) == false then return false end + if self.CurrentShot == 0 then return false end - return self.CurrentShot > 0 + local CanFire = hook.Run("ACF_WeaponCanFire", self) + + return CanFire end function ENT:Shoot() diff --git a/lua/entities/acf_piledriver/shared.lua b/lua/entities/acf_piledriver/shared.lua index 344bc51be..605e3aec5 100644 --- a/lua/entities/acf_piledriver/shared.lua +++ b/lua/entities/acf_piledriver/shared.lua @@ -7,7 +7,7 @@ ENT.IsACFPiledriver = true cleanup.Register("acf_piledriver") -hook.Add("ACF_UpdateRoundData", "ACF Piledriver Ammo", function(Ammo, _, Data, GUIData) +hook.Add("ACF_OnUpdateRound", "ACF Piledriver Ammo", function(Ammo, _, Data, GUIData) if not Ammo.SpikeLength then return end local Cavity = ACF.RoundShellCapacity(Data.PropMass, Data.ProjArea, Data.Caliber, Data.ProjLength) diff --git a/lua/entities/base_scalable/cl_init.lua b/lua/entities/base_scalable/cl_init.lua index 0345c1961..29f606c49 100644 --- a/lua/entities/base_scalable/cl_init.lua +++ b/lua/entities/base_scalable/cl_init.lua @@ -89,7 +89,7 @@ do -- Size and scale setter methods -- We have updated ScaleData but no ModelData yet -- We'll wait for it and instantly tell the entity to rescale if Path and ModelData.IsOnStandby(Path) then - ModelData.QueueRefresh(Path, Entity, function() + ModelData.CallOnReceive(Path, Entity, function() local Saved = Entity.SavedScale if not Saved then return end @@ -112,7 +112,7 @@ do -- Size and scale setter methods if IsValid(PhysObj) then if Entity.OnResized then Entity:OnResized(Size, Scale) end - hook.Run("ACF_OnEntityResized", Entity, PhysObj, Size, Scale) + hook.Run("ACF_OnResizeEntity", Entity, PhysObj, Size, Scale) end return true diff --git a/lua/entities/base_scalable/init.lua b/lua/entities/base_scalable/init.lua index 825ab024d..97e7485fd 100644 --- a/lua/entities/base_scalable/init.lua +++ b/lua/entities/base_scalable/init.lua @@ -52,7 +52,7 @@ do -- Size and scale setter methods if IsValid(PhysObj) then if Entity.OnResized then Entity:OnResized(Size, Scale) end - hook.Run("ACF_OnEntityResized", Entity, PhysObj, Size, Scale) + hook.Run("ACF_OnResizeEntity", Entity, PhysObj, Size, Scale) end return true diff --git a/lua/tests/acf/ballistics/ballistics_sv/create_bullet.lua b/lua/tests/acf/ballistics/ballistics_sv/create_bullet.lua index 4dc8cf51f..047249044 100644 --- a/lua/tests/acf/ballistics/ballistics_sv/create_bullet.lua +++ b/lua/tests/acf/ballistics/ballistics_sv/create_bullet.lua @@ -19,7 +19,7 @@ return { afterEach = function() table.Empty( ACF.Ballistics.Bullets ) - hook.Remove( "ACF_OnClock", "ACF Iterate Bullets" ) + hook.Remove( "ACF_OnTick", "ACF Iterate Bullets" ) end, afterAll = function( State ) diff --git a/lua/tests/acf/core/validation_sv/is_legal.lua b/lua/tests/acf/core/validation_sv/is_legal.lua index 3b551cdfb..f16c3eb53 100644 --- a/lua/tests/acf/core/validation_sv/is_legal.lua +++ b/lua/tests/acf/core/validation_sv/is_legal.lua @@ -163,9 +163,9 @@ return { }, { - name = "Is not Legal when ACF_IsLegal hook returns", + name = "Is not Legal when ACF_OnCheckLegal hook returns", func = function( State ) - hook.Add( "ACF_IsLegal", "TestFailure", function() + hook.Add( "ACF_OnCheckLegal", "TestFailure", function() return false, "Test reason", "Test message", "Test timeout" end ) @@ -178,7 +178,7 @@ return { expect( Timeout ).to.equal( "Test timeout" ) end, - cleanup = function() hook.Remove( "ACF_IsLegal", "TestFailure" ) end + cleanup = function() hook.Remove( "ACF_OnCheckLegal", "TestFailure" ) end }, { diff --git a/lua/tests/acf/damage/damage_sv/acf_keshove.lua b/lua/tests/acf/damage/damage_sv/acf_keshove.lua index 83453ae93..f2f151308 100644 --- a/lua/tests/acf/damage/damage_sv/acf_keshove.lua +++ b/lua/tests/acf/damage/damage_sv/acf_keshove.lua @@ -52,7 +52,7 @@ return { { name = "Does not shove the entity if ACF_KEShove hook returns false", func = function( State ) - hook.Add( "ACF_KEShove", "Test", function() return false end ) + hook.Add( "ACF_OnPushEntity", "Test", function() return false end ) local Ent = State.Ent ACF.KEShove( Ent, Ones, Ones, 1 ) @@ -61,7 +61,7 @@ return { end, cleanup = function() - hook.Remove( "ACF_KEShove", "Test" ) + hook.Remove( "ACF_OnPushEntity", "Test" ) end }, diff --git a/lua/vgui/acf_panel.lua b/lua/vgui/acf_panel.lua index 3239d6991..40fb93880 100644 --- a/lua/vgui/acf_panel.lua +++ b/lua/vgui/acf_panel.lua @@ -608,7 +608,7 @@ function PANEL:AddModelPreview(Model, Rotate) if not Center then if ModelData.IsOnStandby(Path) then - ModelData.QueueRefresh(Path, self, function() + ModelData.CallOnReceive(Path, self, function() self:UpdateModel(Path, Material) end) end diff --git a/lua/weapons/gmod_tool/stools/acf_menu.lua b/lua/weapons/gmod_tool/stools/acf_menu.lua index 5b74ae060..2b4c349ac 100644 --- a/lua/weapons/gmod_tool/stools/acf_menu.lua +++ b/lua/weapons/gmod_tool/stools/acf_menu.lua @@ -42,7 +42,8 @@ if CLIENT then return end - if Entity.CanDrawOverlay and Entity:CanDrawOverlay() == false then return end + + if Entity.CanDrawOverlay and not Entity:CanDrawOverlay() then return end if Distance <= 65536 then cam.Start3D() @@ -67,7 +68,7 @@ if CLIENT then ACF.CreateSpawnMenu(ACF.SpawnMenu.Panel) end) - hook.Add("ACF_DrawBoxes", "ACF Draw Hitboxes", function(Entity) + hook.Add("ACF_OnDrawBoxes", "ACF Draw Hitboxes", function(Entity) if not Entity.HitBoxes then return end if not next(Entity.HitBoxes) then return end diff --git a/lua/weapons/gmod_tool/stools/acfarmorprop.lua b/lua/weapons/gmod_tool/stools/acfarmorprop.lua index 0c88baab3..650ef39e3 100644 --- a/lua/weapons/gmod_tool/stools/acfarmorprop.lua +++ b/lua/weapons/gmod_tool/stools/acfarmorprop.lua @@ -64,7 +64,7 @@ local function UpdateArmor(_, Entity, Data) duplicator.StoreEntityModifier(Entity, "ACF_Armor", { Thickness = Data.Thickness, Ductility = Ductility }) end -hook.Add("ACF_OnServerDataUpdate", "ACF_ArmorTool_MaxThickness", function(_, Key, Value) +hook.Add("ACF_OnUpdateServerData", "ACF_ArmorTool_MaxThickness", function(_, Key, Value) if Key ~= "MaxThickness" then return end MaximumArmor = math.floor(ACF.CheckNumber(Value, ACF.MaximumArmor))