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 #430

Open
wants to merge 31 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
98aafb0
Why does this file keep appearing
TwistedTail Oct 24, 2022
c2a8b5d
Added default gamemode hook functions
TwistedTail Oct 24, 2022
62150c3
Merge branch 'dev' into branch-docs
TwistedTail Nov 21, 2022
412aaf5
Merge branch 'dev' into branch-docs
TwistedTail Dec 9, 2022
0204777
Updated damage related gamemode hooks
TwistedTail Dec 19, 2022
ea1101e
Finished documenting clientside gamemode hooks
TwistedTail Feb 12, 2023
bfdee28
Replaced use of hook.Call
TwistedTail Feb 16, 2023
b3991a0
Added Permissions related hooks to the Gamemode table
TwistedTail Feb 17, 2023
a05a1fe
Simplified model data code
TwistedTail May 1, 2023
50e6db1
Renamed ACF_UpdatedRepository hook
TwistedTail May 1, 2023
62d0715
Renamed ACF_AllowMenuOption and ACF_AllowMenuItem hooks
TwistedTail May 1, 2023
6595239
Rectified hook naming convention, added more hooks
TwistedTail May 30, 2023
f6d7d7c
Improved and updated all menu creation related hooks
TwistedTail Jun 2, 2023
84421f1
Updated ACF_BulletEffect hook
TwistedTail Jun 2, 2023
ad97c13
Updated ACF_DrawBoxes hook
TwistedTail Jun 2, 2023
43d1ac0
Renamed ACF_OnAddonLoaded hook
TwistedTail Jun 3, 2023
681d5f3
Merge branch 'master' into hook-docs
thecraftianman Dec 27, 2023
056bfe6
Merge branch 'master' into hook-docs
thecraftianman Jan 6, 2024
8ed69c6
Merge branch 'master' into hook-docs
thecraftianman Jan 6, 2024
f3f116c
Document the last untouched hooks
thecraftianman Jan 8, 2024
70eb944
Merge branch 'master' into hook-docs
thecraftianman Jan 13, 2024
f2ae0b5
Merge branch 'master' into hook-docs
thecraftianman Jan 20, 2024
4a5129f
Renamed ModelData hooks
TwistedTail Feb 18, 2024
272299a
Renamed a few shared hooks
TwistedTail Feb 18, 2024
1d49605
Updated a few serverside hooks
TwistedTail Feb 18, 2024
1100c5a
Merge branch 'master' into hook-docs
thecraftianman Aug 5, 2024
85361e4
Merge branch 'master' into hook-docs
thecraftianman Aug 30, 2024
3b1ebc5
Standardize hook docs with function docs
thecraftianman Aug 30, 2024
e05b6ba
Fix seats legal hook
thecraftianman Aug 30, 2024
5adb9f4
Merge branch 'dev' into hook-docs
TwistedTail Sep 23, 2024
d0110fc
Changed hook usage not considering default return value
TwistedTail Sep 23, 2024
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
2 changes: 1 addition & 1 deletion lua/acf/ballistics/ballistics_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions lua/acf/ballistics/ballistics_sv.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local hook = hook
local ACF = ACF
local Ballistics = ACF.Ballistics
local Damage = ACF.Damage
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -200,15 +200,17 @@ 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)

return true
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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lua/acf/contraption/seats_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lua/acf/core/classes/entities/registration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions lua/acf/core/classes/grouped.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lua/acf/core/classes/object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lua/acf/core/classes/simple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lua/acf/core/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lua/acf/core/networking/data_vars/data_vars_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lua/acf/core/networking/data_vars/data_vars_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
28 changes: 22 additions & 6 deletions lua/acf/core/networking/model_data/model_data_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -117,15 +133,15 @@ 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)

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
Expand All @@ -139,4 +155,4 @@ hook.Add("ACF_OnReceivedModelData", "ACF_ModelData_PanelRefresh", function(Model
end

Callbacks[Model] = nil
end)
end)
2 changes: 1 addition & 1 deletion lua/acf/core/networking/model_data/model_data_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion lua/acf/core/utilities/clock/clock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions lua/acf/core/validation_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion lua/acf/core/version/version_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion lua/acf/core/version/version_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion lua/acf/damage/explosion_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lua/acf/damage/ke_shove_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lua/acf/damage/permissions/permissions_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
Loading
Loading