Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge hook-docs branch #101

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 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()
ACF.AddRepository("ACF-Team", "ACF-3-Missiles", "lua/acf/core/acfm_globals.lua")
hook.Add("ACF_OnLoadAddon", "ACF Missiles Update Checker", function()
ACF.AddRepository("TwistedTail", "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_OnMissileLaunched", "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_OnGetDisplayData", 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_OnMissileLaunched", "ACF Optical Computer Filter", function(Missile)
for Computer in pairs(Computers) do
local Filter = Computer.Filter

Expand Down
24 changes: 24 additions & 0 deletions lua/acf/hooks/hooks_missiles_sv.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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_OnMissileLaunched()
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_MissileCanExplode()
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.
--- @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_PreCreateTraceControls", "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)
16 changes: 2 additions & 14 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
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_VerifyData", "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_OnEntitySpawn", "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_OnEntityUpdate", "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_MissileCanExplode", 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_OnMissileLaunched", Entity)

return Entity
end
Expand Down
14 changes: 8 additions & 6 deletions lua/entities/acf_missile/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local Damage = ACF.Damage
local Debug = ACF.Debug
local Missiles = Classes.Missiles
local InputActions = ACF.GetInputActions("acf_missile")
local HookRun = hook.Run
local hook = hook
local Inputs = { "Detonate (Force the missile to explode.)" }
local Outputs = { "Entity (The missile itself.) [ENTITY]" }

Expand Down Expand Up @@ -291,7 +291,9 @@ local function CalcFlight(Missile)
end

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

if not CanExplode then return end

if IsValid(Inflictor) and Inflictor:IsPlayer() then
Missile.Inflictor = Inflictor
Expand All @@ -308,7 +310,7 @@ hook.Add("CanDrive", "acf_missile_CanDrive", function(_, Entity)
if ActiveMissiles[Entity] then return false end
end)

hook.Add("OnMissileLaunched", "ACF Missile Rack Filter", function(Missile)
hook.Add("ACF_OnMissileLaunched", "ACF Missile Rack Filter", function(Missile)
local Count = #Missile.Filter

for K in pairs(ActiveMissiles) do
Expand Down Expand Up @@ -406,7 +408,7 @@ function MakeACF_Missile(Player, Pos, Ang, Rack, MountPoint, Crate)
Missile.Inputs = WireLib.CreateInputs(Missile, Inputs)
Missile.Outputs = WireLib.CreateOutputs(Missile, Outputs)

HookRun("ACF_OnEntitySpawn", "acf_missile", Missile, Data, Class, Crate)
hook.Run("ACF_OnEntitySpawn", "acf_missile", Missile, Data, Class, Crate)

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

Expand Down Expand Up @@ -465,7 +467,7 @@ function ENT:CreateBulletData(Crate)
Ammo:OnFirst(self)
end

HookRun("ACF_OnAmmoFirst", Ammo, self, Data)
hook.Run("ACF_OnAmmoFirst", Ammo, self, Data)

Ammo:Network(self, self.BulletData)
end
Expand Down Expand Up @@ -547,7 +549,7 @@ function ENT:Launch(Delay, IsMisfire)
UpdateBodygroups(self, "OnLaunch")
UpdateSkin(self)

HookRun("OnMissileLaunched", self)
hook.Run("ACF_OnMissileLaunched", self)
end

function ENT:DoFlight(ToPos, ToDir)
Expand Down
Loading
Loading