Skip to content

Commit 2f6ad01

Browse files
Merge pull request #101 from ACF-Team/hook-docs
Merge hook-docs branch
2 parents c505ccb + 0ab12dc commit 2f6ad01

File tree

17 files changed

+97
-77
lines changed

17 files changed

+97
-77
lines changed

lua/acf/core/acfm_globals.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ game.AddParticles("particles/flares_fx.pcf")
1515
PrecacheParticleSystem("ACFM_Flare")
1616

1717
do -- Update checker
18-
hook.Add("ACF_OnLoadAddon", "ACF Missiles Checker", function()
18+
hook.Add("ACF_OnLoadAddon", "ACF Missiles Update Checker", function()
1919
ACF.AddRepository("ACF-Team", "ACF-3-Missiles", "lua/acf/core/acfm_globals.lua")
2020

21-
hook.Remove("ACF_OnLoadAddon", "ACF Missiles Checker")
21+
hook.Remove("ACF_OnLoadAddon", "ACF Missiles Update Checker")
2222
end)
2323
end

lua/acf/core/classes/missiles/ammo_blacklist.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ local function AddToBlacklist(Weapon, Ammo)
1818
end
1919
end
2020

21-
hook.Add("ACF_OnNewClassGroup", "ACF External Ammo Blacklist", function(ID, Group)
21+
hook.Add("ACF_OnCreateGroup", "ACF External Ammo Blacklist", function(ID, Group)
2222
if not Group.Blacklist then return end
2323

2424
for _, Ammo in ipairs(Group.Blacklist) do
2525
AddToBlacklist(ID, Ammo)
2626
end
2727
end)
2828

29-
hook.Add("ACF_OnClassLoaded", "ACF External Ammo Blacklist", function(ID, Class)
29+
hook.Add("ACF_OnLoadClass", "ACF External Ammo Blacklist", function(ID, Class)
3030
if not AmmoTypes.Get(ID) then return end
3131
if not Blacklisted[ID] then return end
3232

lua/acf/core/laser/laser_sv.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ function ACF.FilterLaserEntity(Entity)
5353
net.Broadcast()
5454
end
5555

56-
hook.Add("ACF_OnPlayerLoaded", "ACF Laser Setup", function(Player)
56+
hook.Add("ACF_OnLoadPlayer", "ACF Laser Setup", function(Player)
5757
net.Start("ACF_SyncLaserSources")
5858
net.WriteTable(Sources)
5959
net.Send(Player)
6060
end)
6161

62-
hook.Add("OnMissileLaunched", "ACF Laser Filter Update", function(Missile)
62+
hook.Add("ACF_OnLaunchMissile", "ACF Laser Filter Update", function(Missile)
6363
ACF.FilterLaserEntity(Missile)
6464
end)

lua/acf/core/utilities/entity_tracking_sv.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ hook.Add("PlayerSpawnedVehicle", "ACF Entity Tracking", function(_, Entity)
9595
end)
9696
end)
9797

98-
hook.Add("ACF_OnClock", "ACF Entity Tracking", function()
98+
hook.Add("ACF_OnTick", "ACF Entity Tracking", function()
9999
for Ancestor in pairs(Ancestors) do
100100
UpdateValues(Ancestor)
101101
end

lua/acf/entities/ammo_types/flare.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function Ammo:GetDisplayData(Data)
2121
BurnTime = Data.BurnTime,
2222
}
2323

24-
hook.Run("ACF_GetDisplayData", self, Data, Display)
24+
hook.Run("ACF_OnRequestDisplayData", self, Data, Display)
2525

2626
return Display
2727
end
@@ -40,7 +40,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData)
4040
Data.BurnTime = Data.FillerMass / Data.BurnRate
4141
Data.CartMass = Data.PropMass + Data.ProjMass
4242

43-
hook.Run("ACF_UpdateRoundData", self, ToolData, Data, GUIData)
43+
hook.Run("ACF_OnUpdateRound", self, ToolData, Data, GUIData)
4444

4545
for K, V in pairs(self:GetDisplayData(Data)) do
4646
GUIData[K] = V
@@ -123,11 +123,11 @@ else
123123
function Ammo:ImpactEffect()
124124
end
125125

126-
function Ammo:SetupAmmoMenuSettings(Settings)
127-
Settings.SuppressTracer = true
126+
function Ammo:PreCreateTracerControls()
127+
return false
128128
end
129129

130-
function Ammo:AddAmmoControls(Base, ToolData, BulletData)
130+
function Ammo:OnCreateAmmoControls(Base, ToolData, BulletData)
131131
local FillerRatio = Base:AddSlider("Filler Ratio", 0, 1, 2)
132132
FillerRatio:SetClientData("FillerRatio", "OnValueChanged")
133133
FillerRatio:DefineSetter(function(_, _, Key, Value)
@@ -141,13 +141,13 @@ else
141141
end)
142142
end
143143

144-
function Ammo:AddCrateDataTrackers(Trackers, ...)
145-
Ammo.BaseClass.AddCrateDataTrackers(self, Trackers, ...)
144+
function Ammo:OnCreateCrateInformation(Base, Label, ...)
145+
Ammo.BaseClass.OnCreateCrateInformation(self, Base, Label, ...)
146146

147-
Trackers.FillerRatio = true
147+
Label:TrackClientData("FillerRatio")
148148
end
149149

150-
function Ammo:AddAmmoInformation(Base, ToolData, BulletData)
150+
function Ammo:OnCreateAmmoInformation(Base, ToolData, BulletData)
151151
local RoundStats = Base:AddLabel()
152152
RoundStats:TrackClientData("Projectile", "SetText")
153153
RoundStats:TrackClientData("Propellant")

lua/acf/entities/ammo_types/glatgm.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ else
9696
end
9797
end
9898

99-
function Ammo:SetupAmmoMenuSettings(Settings)
100-
Settings.SuppressTracer = true
99+
function Ammo:PreCreateTracerControls()
100+
return false
101101
end
102102

103-
function Ammo:AddAmmoPreview(Preview, Setup, ToolData, BulletData)
104-
Ammo.BaseClass.AddAmmoPreview(self, Preview, Setup, ToolData, BulletData)
103+
function Ammo:OnCreateAmmoPreview(Preview, Setup, ToolData, BulletData)
104+
Ammo.BaseClass.OnCreateAmmoPreview(self, Preview, Setup, ToolData, BulletData)
105105

106106
local Caliber = BulletData.Caliber
107107
local Model, FOV, Height
@@ -123,7 +123,7 @@ else
123123
Setup.Height = Height or Setup.Height
124124
end
125125

126-
function Ammo:AddAmmoControls(Base, ToolData, BulletData)
126+
function Ammo:OnCreateAmmoControls(Base, ToolData, BulletData)
127127
local LinerAngle = Base:AddSlider("Liner Angle", BulletData.MinConeAng, 90, 1)
128128
LinerAngle:SetClientData("LinerAngle", "OnValueChanged")
129129
LinerAngle:TrackClientData("Projectile")
@@ -151,7 +151,7 @@ else
151151
end)
152152
end
153153

154-
function Ammo:AddAmmoInformation(Base, ToolData, BulletData)
154+
function Ammo:OnCreateAmmoInformation(Base, ToolData, BulletData)
155155
local RoundStats = Base:AddLabel()
156156
RoundStats:TrackClientData("Projectile", "SetText")
157157
RoundStats:TrackClientData("Propellant")

lua/acf/entities/components/computers.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ do -- Optical guidance computer
266266
return math.floor(Value * 0.00254) * 393.7
267267
end
268268

269-
hook.Add("OnMissileLaunched", "ACF Optical Computer Filter", function(Missile)
269+
hook.Add("ACF_OnLaunchMissile", "ACF Optical Computer Filter", function(Missile)
270270
for Computer in pairs(Computers) do
271271
local Filter = Computer.Filter
272272

lua/acf/hooks/hooks_missiles_sv.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
local Hooks = ACF.Utilities.Hooks
2+
3+
4+
Hooks.Add("ACF_Missiles_Server", function(Gamemode)
5+
--- Called after a missile is fired.
6+
--- @param Entity entity The missile entity that was launched.
7+
function Gamemode:ACF_OnLaunchMissile()
8+
end
9+
10+
--- Called when a missile attempts to create an explosion.
11+
--- @param Entity entity The affected missile.
12+
--- @param Data table The bullet data of the affected missile.
13+
--- @return boolean # True if the missile can explode, false otherwise.
14+
function Gamemode:ACF_PreExplodeMissile()
15+
return true
16+
end
17+
18+
--- Called when a missile plays its sound if the ACF Sound Extension Project by looterz is installed.
19+
--- This is a legacy hook from ACF-2 and may be removed at any time.
20+
--- @deprecated
21+
--- @param Entity entity The missile entity to play sound on.
22+
--- @param Sound string The sound to play.
23+
function Gamemode:ACF_SOUND_MISSILE()
24+
end
25+
end)

lua/acf/menu/items_cl/missiles.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ local ACF = ACF
22
local Classes = ACF.Classes
33
local Missiles = Classes.Missiles
44
local Racks = Classes.Racks
5-
local Settings = { SuppressTracer = true }
65

76
local function GetRackList(Data)
87
local Result = {}
@@ -78,7 +77,7 @@ local function CreateMenu(Menu)
7877
local RackPreview = RackBase:AddModelPreview(nil, true)
7978
local RackInfo = RackBase:AddLabel()
8079

81-
local AmmoList = ACF.CreateAmmoMenu(Menu, Settings)
80+
local AmmoList = ACF.CreateAmmoMenu(Menu)
8281

8382
ACF.SetClientData("PrimaryClass", "acf_rack")
8483
ACF.SetClientData("SecondaryClass", "acf_ammo")
@@ -120,7 +119,7 @@ local function CreateMenu(Menu)
120119

121120
Menu.AmmoBase.MissileData = Data
122121

123-
ACF.UpdateAmmoMenu(Menu, Settings)
122+
ACF.UpdateAmmoMenu(Menu)
124123
end
125124

126125
function RackList:OnSelect(Index, _, Data)
@@ -142,3 +141,7 @@ local function CreateMenu(Menu)
142141
end
143142

144143
ACF.AddMenuItem(101, "Entities", "Missiles", "wand", CreateMenu)
144+
145+
hook.Add("ACF_PreCreateTracerControls", "ACF Missiles Remove Tracer Checkbox", function(_, ToolData)
146+
if ToolData.PrimaryClass == "acf_rack" then return false end
147+
end)

lua/acf/missiles/acfm_effects_cl.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ local Overrides =
4949
end
5050
}
5151

52-
hook.Add("ACF_BulletEffect", "ACF Missiles Custom Effects", function(AmmoType)
53-
local Custom = Overrides[AmmoType]
52+
hook.Add("ACF_OnCreateBulletEffect", "ACF Missiles Custom Effects", function(Effect, BulletData)
53+
local Custom = Overrides[BulletData.AmmoType]
5454

5555
if Custom then
56-
return Custom
56+
Effect.ApplyMovement = Custom
5757
end
5858
end)

lua/acf/missiles/acfm_roundinject.lua

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local Entities = Classes.Entities
44
local Guidances = Classes.Guidances
55
local Fuzes = Classes.Fuzes
66

7-
hook.Add("ACF_UpdateRoundData", "ACF Missile Ammo", function(_, ToolData, Data)
7+
hook.Add("ACF_OnUpdateRound", "ACF Missile Ammo", function(_, ToolData, Data)
88
if ToolData.Destiny ~= "Missiles" then return end
99

1010
local PenMul = ACF.GetGunValue(ToolData.Weapon, "PenMul")
@@ -51,7 +51,7 @@ if CLIENT then
5151
return Result
5252
end
5353

54-
hook.Add("ACF_AddAmmoControls", "ACF Add Missiles Menu", function(Base, ToolData, Ammo, BulletData)
54+
hook.Add("ACF_OnCreateAmmoControls", "ACF Add Missiles Menu", function(Base, ToolData, Ammo, BulletData)
5555
if ToolData.Destiny ~= "Missiles" then return end
5656

5757
local Missile = Base.MissileData
@@ -123,18 +123,6 @@ if CLIENT then
123123
ACF.LoadSortedList(GuidanceList, GetGuidanceList(Missile), "Name")
124124
ACF.LoadSortedList(FuzeList, GetFuzeList(Missile), "Name")
125125
end)
126-
127-
--[[
128-
-- Unused, uncomment if needed
129-
hook.Add("ACF_AddAmmoInformation", "ACF Add Missiles Menu", function(Base, ToolData, Ammo, BulletData)
130-
if ToolData.Destiny ~= "Missiles" then return end
131-
132-
local Guidance = BulletData.Guidance
133-
local Fuze = BulletData.Fuze
134-
local GuidanceBase = Base:AddPanel("ACF_Panel")
135-
local FuzeBase = Base:AddPanel("ACF_Panel")
136-
end)
137-
]]
138126
else
139127
local Display = "%s: %s%s\n\n%s: %s%s"
140128
local AllowedClass = {
@@ -175,7 +163,7 @@ else
175163
return Result
176164
end
177165

178-
hook.Add("ACF_VerifyData", "ACF Missile Ammo", function(EntClass, Data, ...)
166+
hook.Add("ACF_OnVerifyData", "ACF Missile Ammo", function(EntClass, Data, ...)
179167
if not AllowedClass[EntClass] then return end
180168
if Data.Destiny ~= "Missiles" then return end
181169

lua/entities/acf_computer/init.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ AddCSLuaFile("cl_init.lua")
44

55
include("shared.lua")
66

7+
local hook = hook
78
local ACF = ACF
89
local Contraption = ACF.Contraption
910
local Damage = ACF.Damage
@@ -72,7 +73,6 @@ end)
7273
local CheckLegal = ACF.CheckLegal
7374
local UnlinkSound = "physics/metal/metal_box_impact_bullet%s.wav"
7475
local MaxDistance = ACF.LinkDistance * ACF.LinkDistance
75-
local HookRun = hook.Run
7676

7777
local function CheckDistantLinks(Entity, Source)
7878
local Position = Entity:GetPos()
@@ -117,7 +117,7 @@ do -- Spawn and update function
117117
Class.VerifyData(Data, Class)
118118
end
119119

120-
HookRun("ACF_VerifyData", "acf_computer", Data, Class)
120+
hook.Run("ACF_OnVerifyData", "acf_computer", Data, Class)
121121
end
122122
end
123123

@@ -225,7 +225,7 @@ do -- Spawn and update function
225225
Class.OnSpawn(Entity, Data, Class, Computer)
226226
end
227227

228-
HookRun("ACF_OnEntitySpawn", "acf_computer", Entity, Data, Class, Computer)
228+
hook.Run("ACF_OnSpawnEntity", "acf_computer", Entity, Data, Class, Computer)
229229

230230
WireLib.TriggerOutput(Entity, "Entity", Entity)
231231

@@ -268,7 +268,7 @@ do -- Spawn and update function
268268
OldClass.OnLast(self, OldClass)
269269
end
270270

271-
HookRun("ACF_OnEntityLast", "acf_computer", self, OldClass)
271+
hook.Run("ACF_OnEntityLast", "acf_computer", self, OldClass)
272272

273273
ACF.SaveEntity(self)
274274

@@ -280,7 +280,7 @@ do -- Spawn and update function
280280
Class.OnUpdate(self, Data, Class, Computer)
281281
end
282282

283-
HookRun("ACF_OnEntityUpdate", "acf_computer", self, Data, Class, Computer)
283+
hook.Run("ACF_OnUpdateEntity", "acf_computer", self, Data, Class, Computer)
284284

285285
self:UpdateOverlay(true)
286286

@@ -371,7 +371,7 @@ function ENT:OnRemove()
371371
OldClass.OnLast(self, OldClass)
372372
end
373373

374-
HookRun("ACF_OnEntityLast", "acf_computer", self, OldClass)
374+
hook.Run("ACF_OnEntityLast", "acf_computer", self, OldClass)
375375

376376
for Weapon in pairs(self.Weapons) do
377377
self:Unlink(Weapon)

lua/entities/acf_glatgm/init.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ local function ClampAngle(Object, Limit)
3232
end
3333

3434
local function DetonateMissile(Missile, Inflictor)
35-
if hook.Run("ACF_AmmoExplode", Missile, Missile.BulletData) == false then return end
35+
local CanExplode = hook.Run("ACF_PreExplodeMissile", Missile, Missile.BulletData)
36+
37+
if not CanExplode then return end
3638

3739
if IsValid(Inflictor) and Inflictor:IsPlayer() then
3840
Missile.Inflictor = Inflictor
@@ -115,7 +117,7 @@ function MakeACF_GLATGM(Gun, BulletData)
115117

116118
Missiles[Entity] = true
117119

118-
hook.Run("OnMissileLaunched", Entity)
120+
hook.Run("ACF_OnLaunchMissile", Entity)
119121

120122
return Entity
121123
end

0 commit comments

Comments
 (0)