Skip to content
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: 0 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,6 @@ globals = {
"ShouldShowTraitorExtraInfo",
"StartsWithVowel",
"SyncShopConVars",
"UnregisterRoleHooks",
"UpdateRoleColors",
"UpdateRoleColours",
"UpdateRoleState",
Expand Down
5 changes: 0 additions & 5 deletions API/METHODS_GLOBAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,6 @@ Whether the given string starts with a vowel.\
*Realm:* Client and Server\
*Added in:* 1.0.8

### UnregisterRoleHooks(role)
Unregisters a role as active, causing its managed hooks to be removed if they are active.\
*Realm:* Client and Server\
*Added in:* 2.5.1

### UpdateRoleColours()/UpdateRoleColors()
Updates the role color tables based on the color convars and color type convar.\
*Realm:* Client and Server\
Expand Down
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
### Developer
- Added `TTTHUDInfoPositionOverride` hook to override the position of the player information HUD (role, health, ammo etc.)
- Added new `x` and `y` parameters to `TTTHUDInfoPaint` hook which provide the raw position of the player information HUD (i.e. agnostic of any existing labels)
- Changed role registration system so role hooks are only removed in the prep phase of the next round
- This fixes some issues with role logic ending early or experiencing odd bugs when a player's role is changed after their role ability is already active
- Also removes `UnregisterRoleHooks` global method

## 2.5.1
**Released: July 25th, 2026**
Expand Down
7 changes: 0 additions & 7 deletions docs/api/methods_global.html
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,6 @@ <h3><a id="updaterolecoloursupdaterolecolors" href="#updaterolecoloursupdaterole
<em>Added in:</em> 1.0.0
</p>

<h3><a id="unregisterrolehooksrole" href="#nuregisterrolehooksrole">UnregisterRoleHooks(role)</a></h3>
<p>
Unregisters a role as active, causing its managed hooks to be removed if they are active.<br>
<em>Realm:</em> Client and Server<br>
<em>Added in:</em> 2.5.1
</p>

<h3><a id="updaterolestrings" href="#updaterolestrings">UpdateRoleStrings()</a></h3>
<p>
Updates the role string tables based on the role name convars.<br>
Expand Down
37 changes: 2 additions & 35 deletions gamemodes/terrortown/gamemode/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1212,13 +1212,8 @@ function RegisterRole(tbl)
CallHook("TTTRoleRegistered", nil, roleID)
end

local role_hooks_registered = {}
local banned_hooks = {"Initialize", "PreRegisterSWEP", "TTTBeginRound", "TTTPlayerRoleChanged", "TTTPrepareRound", "TTTRoleSpawnsArtificially", "TTTSelectRoles", "TTTSyncEventIDs", "TTTSyncWinIDs", "TTTTutorialRoleText", "TTTUpdateRoleState"}
local function RegisterHooks(role)
local key = ROLE_HOOK_REGISTRATION_KEY[role] or role
role_hooks_registered[key] = (role_hooks_registered[key] or 0) + 1
if role_hooks_registered[key] ~= 1 then return end

for hookName, hookData in pairs(ROLE_REGISTERED_HOOKS[role]) do
if not hookData then continue end
if TableHasValue(banned_hooks, hookName) then
Expand All @@ -1238,10 +1233,6 @@ local function RegisterHooks(role)
end

local function UnregisterHooks(role)
local key = ROLE_HOOK_REGISTRATION_KEY[role] or role
role_hooks_registered[key] = (role_hooks_registered[key] or 0) - 1
if role_hooks_registered[key] ~= 0 then return end

for hookName, hookData in pairs(ROLE_REGISTERED_HOOKS[role]) do
if not hookData then continue end

Expand Down Expand Up @@ -1273,35 +1264,12 @@ function RegisterRoleHooks(role)
end
end

function UnregisterRoleHooks(role)
local oldHooks = ROLE_REGISTERED_HOOKS[role]
local oldDepRoles = ROLE_HOOK_REGISTRATION_DEPENDENCIES[role]
if not oldHooks and not oldDepRoles then return end

if oldHooks then
UnregisterHooks(role)
end
if oldDepRoles then
for _, r in ipairs(oldDepRoles) do
if ROLE_REGISTERED_HOOKS[r] then
UnregisterHooks(r)
end
end
end
end

AddHook("TTTPlayerRoleChanged", "HookRegistration_TTTPlayerRoleChanged", function(ply, oldRole, newRole)
if oldRole == newRole then return end
if not ROLE_REGISTERED_HOOKS[oldRole] and
not ROLE_HOOK_REGISTRATION_DEPENDENCIES[oldRole] and
not ROLE_REGISTERED_HOOKS[newRole] and
if not ROLE_REGISTERED_HOOKS[newRole] and
not ROLE_HOOK_REGISTRATION_DEPENDENCIES[newRole] then return end

-- Delay this by a frame so cleanup can run first
timer.Simple(0, function()
UnregisterRoleHooks(oldRole)
RegisterRoleHooks(newRole)
end)
RegisterRoleHooks(newRole)
end)
AddHook("TTTPrepareRound", "HookRegistration_TTTPrepareRound", function()
-- Delay this by a frame so cleanup can run first
Expand All @@ -1311,7 +1279,6 @@ AddHook("TTTPrepareRound", "HookRegistration_TTTPrepareRound", function()
UnregisterHooks(role)
end
end
role_hooks_registered = {}
end)
end)

Expand Down
Loading