Skip to content

Commit

Permalink
Merge pull request #101 from ACF-Team/hook-docs
Browse files Browse the repository at this point in the history
Merge hook-docs branch
  • Loading branch information
thecraftianman authored Jan 15, 2025
2 parents c505ccb + 0ab12dc commit 2f6ad01
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 77 deletions.
4 changes: 2 additions & 2 deletions lua/acf/core/acfm_globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ game.AddParticles("particles/flares_fx.pcf")
PrecacheParticleSystem("ACFM_Flare")

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

hook.Remove("ACF_OnLoadAddon", "ACF Missiles Checker")
hook.Remove("ACF_OnLoadAddon", "ACF Missiles Update Checker")
end)
end
4 changes: 2 additions & 2 deletions lua/acf/core/classes/missiles/ammo_blacklist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ local function AddToBlacklist(Weapon, Ammo)
end
end

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

for _, Ammo in ipairs(Group.Blacklist) do
AddToBlacklist(ID, Ammo)
end
end)

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

Expand Down
4 changes: 2 additions & 2 deletions lua/acf/core/laser/laser_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ function ACF.FilterLaserEntity(Entity)
net.Broadcast()
end

hook.Add("ACF_OnPlayerLoaded", "ACF Laser Setup", function(Player)
hook.Add("ACF_OnLoadPlayer", "ACF Laser Setup", function(Player)
net.Start("ACF_SyncLaserSources")
net.WriteTable(Sources)
net.Send(Player)
end)

hook.Add("OnMissileLaunched", "ACF Laser Filter Update", function(Missile)
hook.Add("ACF_OnLaunchMissile", "ACF Laser Filter Update", function(Missile)
ACF.FilterLaserEntity(Missile)
end)
2 changes: 1 addition & 1 deletion lua/acf/core/utilities/entity_tracking_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ hook.Add("PlayerSpawnedVehicle", "ACF Entity Tracking", function(_, Entity)
end)
end)

hook.Add("ACF_OnClock", "ACF Entity Tracking", function()
hook.Add("ACF_OnTick", "ACF Entity Tracking", function()
for Ancestor in pairs(Ancestors) do
UpdateValues(Ancestor)
end
Expand Down
18 changes: 9 additions & 9 deletions lua/acf/entities/ammo_types/flare.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Ammo:GetDisplayData(Data)
BurnTime = Data.BurnTime,
}

hook.Run("ACF_GetDisplayData", self, Data, Display)
hook.Run("ACF_OnRequestDisplayData", self, Data, Display)

return Display
end
Expand All @@ -40,7 +40,7 @@ function Ammo:UpdateRoundData(ToolData, Data, GUIData)
Data.BurnTime = Data.FillerMass / Data.BurnRate
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
Expand Down Expand Up @@ -123,11 +123,11 @@ else
function Ammo:ImpactEffect()
end

function Ammo:SetupAmmoMenuSettings(Settings)
Settings.SuppressTracer = true
function Ammo:PreCreateTracerControls()
return false
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(_, _, Key, Value)
Expand All @@ -141,13 +141,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")
Expand Down
12 changes: 6 additions & 6 deletions lua/acf/entities/ammo_types/glatgm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ else
end
end

function Ammo:SetupAmmoMenuSettings(Settings)
Settings.SuppressTracer = true
function Ammo:PreCreateTracerControls()
return false
end

function Ammo:AddAmmoPreview(Preview, Setup, ToolData, BulletData)
Ammo.BaseClass.AddAmmoPreview(self, Preview, Setup, ToolData, BulletData)
function Ammo:OnCreateAmmoPreview(Preview, Setup, ToolData, BulletData)
Ammo.BaseClass.OnCreateAmmoPreview(self, Preview, Setup, ToolData, BulletData)

local Caliber = BulletData.Caliber
local Model, FOV, Height
Expand All @@ -123,7 +123,7 @@ else
Setup.Height = Height or Setup.Height
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")
Expand Down Expand Up @@ -151,7 +151,7 @@ else
end)
end

function Ammo:AddAmmoInformation(Base, ToolData, BulletData)
function Ammo:OnCreateAmmoInformation(Base, ToolData, BulletData)
local RoundStats = Base:AddLabel()
RoundStats:TrackClientData("Projectile", "SetText")
RoundStats:TrackClientData("Propellant")
Expand Down
2 changes: 1 addition & 1 deletion lua/acf/entities/components/computers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ do -- Optical guidance computer
return math.floor(Value * 0.00254) * 393.7
end

hook.Add("OnMissileLaunched", "ACF Optical Computer Filter", function(Missile)
hook.Add("ACF_OnLaunchMissile", "ACF Optical Computer Filter", function(Missile)
for Computer in pairs(Computers) do
local Filter = Computer.Filter

Expand Down
25 changes: 25 additions & 0 deletions lua/acf/hooks/hooks_missiles_sv.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
local Hooks = ACF.Utilities.Hooks


Hooks.Add("ACF_Missiles_Server", function(Gamemode)
--- Called after a missile is fired.
--- @param Entity entity The missile entity that was launched.
function Gamemode:ACF_OnLaunchMissile()
end

--- Called when a missile attempts to create an explosion.
--- @param Entity entity The affected missile.
--- @param Data table The bullet data of the affected missile.
--- @return boolean # True if the missile can explode, false otherwise.
function Gamemode:ACF_PreExplodeMissile()
return true
end

--- Called when a missile plays its sound if the ACF Sound Extension Project by looterz is installed.
--- This is a legacy hook from ACF-2 and may be removed at any time.
--- @deprecated
--- @param Entity entity The missile entity to play sound on.
--- @param Sound string The sound to play.
function Gamemode:ACF_SOUND_MISSILE()
end
end)
9 changes: 6 additions & 3 deletions lua/acf/menu/items_cl/missiles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local ACF = ACF
local Classes = ACF.Classes
local Missiles = Classes.Missiles
local Racks = Classes.Racks
local Settings = { SuppressTracer = true }

local function GetRackList(Data)
local Result = {}
Expand Down Expand Up @@ -78,7 +77,7 @@ local function CreateMenu(Menu)
local RackPreview = RackBase:AddModelPreview(nil, true)
local RackInfo = RackBase:AddLabel()

local AmmoList = ACF.CreateAmmoMenu(Menu, Settings)
local AmmoList = ACF.CreateAmmoMenu(Menu)

ACF.SetClientData("PrimaryClass", "acf_rack")
ACF.SetClientData("SecondaryClass", "acf_ammo")
Expand Down Expand Up @@ -120,7 +119,7 @@ local function CreateMenu(Menu)

Menu.AmmoBase.MissileData = Data

ACF.UpdateAmmoMenu(Menu, Settings)
ACF.UpdateAmmoMenu(Menu)
end

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

ACF.AddMenuItem(101, "Entities", "Missiles", "wand", CreateMenu)

hook.Add("ACF_PreCreateTracerControls", "ACF Missiles Remove Tracer Checkbox", function(_, ToolData)
if ToolData.PrimaryClass == "acf_rack" then return false end
end)
6 changes: 3 additions & 3 deletions lua/acf/missiles/acfm_effects_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ local Overrides =
end
}

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

if Custom then
return Custom
Effect.ApplyMovement = Custom
end
end)
18 changes: 3 additions & 15 deletions lua/acf/missiles/acfm_roundinject.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local Entities = Classes.Entities
local Guidances = Classes.Guidances
local Fuzes = Classes.Fuzes

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

local PenMul = ACF.GetGunValue(ToolData.Weapon, "PenMul")
Expand Down Expand Up @@ -51,7 +51,7 @@ if CLIENT then
return Result
end

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

local Missile = Base.MissileData
Expand Down Expand Up @@ -123,18 +123,6 @@ if CLIENT then
ACF.LoadSortedList(GuidanceList, GetGuidanceList(Missile), "Name")
ACF.LoadSortedList(FuzeList, GetFuzeList(Missile), "Name")
end)

--[[
-- Unused, uncomment if needed
hook.Add("ACF_AddAmmoInformation", "ACF Add Missiles Menu", function(Base, ToolData, Ammo, BulletData)
if ToolData.Destiny ~= "Missiles" then return end
local Guidance = BulletData.Guidance
local Fuze = BulletData.Fuze
local GuidanceBase = Base:AddPanel("ACF_Panel")
local FuzeBase = Base:AddPanel("ACF_Panel")
end)
]]
else
local Display = "%s: %s%s\n\n%s: %s%s"
local AllowedClass = {
Expand Down Expand Up @@ -175,7 +163,7 @@ else
return Result
end

hook.Add("ACF_VerifyData", "ACF Missile Ammo", function(EntClass, Data, ...)
hook.Add("ACF_OnVerifyData", "ACF Missile Ammo", function(EntClass, Data, ...)
if not AllowedClass[EntClass] then return end
if Data.Destiny ~= "Missiles" then return end

Expand Down
12 changes: 6 additions & 6 deletions lua/entities/acf_computer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AddCSLuaFile("cl_init.lua")

include("shared.lua")

local hook = hook
local ACF = ACF
local Contraption = ACF.Contraption
local Damage = ACF.Damage
Expand Down Expand Up @@ -72,7 +73,6 @@ end)
local CheckLegal = ACF.CheckLegal
local UnlinkSound = "physics/metal/metal_box_impact_bullet%s.wav"
local MaxDistance = ACF.LinkDistance * ACF.LinkDistance
local HookRun = hook.Run

local function CheckDistantLinks(Entity, Source)
local Position = Entity:GetPos()
Expand Down Expand Up @@ -117,7 +117,7 @@ do -- Spawn and update function
Class.VerifyData(Data, Class)
end

HookRun("ACF_VerifyData", "acf_computer", Data, Class)
hook.Run("ACF_OnVerifyData", "acf_computer", Data, Class)
end
end

Expand Down Expand Up @@ -225,7 +225,7 @@ do -- Spawn and update function
Class.OnSpawn(Entity, Data, Class, Computer)
end

HookRun("ACF_OnEntitySpawn", "acf_computer", Entity, Data, Class, Computer)
hook.Run("ACF_OnSpawnEntity", "acf_computer", Entity, Data, Class, Computer)

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

Expand Down Expand Up @@ -268,7 +268,7 @@ do -- Spawn and update function
OldClass.OnLast(self, OldClass)
end

HookRun("ACF_OnEntityLast", "acf_computer", self, OldClass)
hook.Run("ACF_OnEntityLast", "acf_computer", self, OldClass)

ACF.SaveEntity(self)

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

HookRun("ACF_OnEntityUpdate", "acf_computer", self, Data, Class, Computer)
hook.Run("ACF_OnUpdateEntity", "acf_computer", self, Data, Class, Computer)

self:UpdateOverlay(true)

Expand Down Expand Up @@ -371,7 +371,7 @@ function ENT:OnRemove()
OldClass.OnLast(self, OldClass)
end

HookRun("ACF_OnEntityLast", "acf_computer", self, OldClass)
hook.Run("ACF_OnEntityLast", "acf_computer", self, OldClass)

for Weapon in pairs(self.Weapons) do
self:Unlink(Weapon)
Expand Down
6 changes: 4 additions & 2 deletions lua/entities/acf_glatgm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ local function ClampAngle(Object, Limit)
end

local function DetonateMissile(Missile, Inflictor)
if hook.Run("ACF_AmmoExplode", Missile, Missile.BulletData) == false then return end
local CanExplode = hook.Run("ACF_PreExplodeMissile", Missile, Missile.BulletData)

if not CanExplode then return end

if IsValid(Inflictor) and Inflictor:IsPlayer() then
Missile.Inflictor = Inflictor
Expand Down Expand Up @@ -115,7 +117,7 @@ function MakeACF_GLATGM(Gun, BulletData)

Missiles[Entity] = true

hook.Run("OnMissileLaunched", Entity)
hook.Run("ACF_OnLaunchMissile", Entity)

return Entity
end
Expand Down
Loading

0 comments on commit 2f6ad01

Please sign in to comment.