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

Buttons: Post Button Init Hook #1610

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Added force role admin command (by @mexikoedi)
- Added `draw.RefreshAvatars(id64)` to refresh avatar icons (by @mexikoedi)
- Added `GM:TTT2OnButtonUse(ply, ent, oldState)`: a hook that is triggered when a button is pressed and that is able to prevent that button press (by @TimGoll)
- Added `GM:TTT2PostButtonInitialization(buttonList)`: a hook that is called after all buttons on the map have been initialized (by @TimGoll)

### Changed

Expand Down
17 changes: 17 additions & 0 deletions lua/ttt2/libraries/buttons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ if SERVER then
-- @internal
-- @realm server
function button.SetUp()
local buttonList = {}

for i = 1, #validButtons do
local classButton = validButtons[i]
local buttonsTable = ents.FindByClass(classButton)

buttonList[classButton] = buttonsTable

for j = 1, #buttonsTable do
local foundButton = buttonsTable[j]

Expand All @@ -33,7 +37,20 @@ if SERVER then
foundButton:SetNWInt("button_class", i)
end
end

---
-- @realm server
-- stylua: ignore
hook.Run("TTT2PostButtonInitialization", buttonList)
end

---
-- Hook that is called after all buttons were initialized on the map. This happens after
-- a map cleanup when a new round starts or when the list is rebuilt after a hotreload.
-- @param table buttonList A table with all buttons found on the map
-- @hook
-- @realm server
function GM:TTT2PostButtonInitialization(buttonList) end
end

---
Expand Down
Loading