Skip to content

Commit 5e5c24f

Browse files
authored
Fixed missing ttt_filter_role in fgd and added ttt_filter_subrole entity (#1842)
Fixed missing ttt_filter_role in ttt2.fgd Added ttt_filter_subrole entity Added ttt_filter_subrole in ttt2.fgd This, as the name implies, filters by subrole. Created it mainly for edgecases like the Defective role or map specific roles
1 parent 266cb8c commit 5e5c24f

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
1111
- Entities parented to destroyed doors are now transferred to their physics prop
1212
- Door props are now spawned as soon as the door is destroyed (instead of a frame later)
1313
- Reuse existing vector globals instead of creating new vectors
14+
- Added ttt_filter_subrole (by @mrxonte)
1415

1516
### Fixed
1617

1718
- Fixed markerVision null entity errors (by @mexikoedi)
19+
- Fixed missing ttt_filter_role in ttt2.fgd (by @mrxonte)
1820

1921
## [v0.14.5b](https://github.com/TTT-2/TTT2/tree/v0.14.5b) (2025-08-18)
2022

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
-- @class ENT
3+
-- @section ttt_filter_subrole
4+
5+
ENT.Type = "filter"
6+
ENT.Base = "base_filter"
7+
8+
ROLE_NONE = ROLE_NONE or 3
9+
10+
ENT.checkingRole = ROLE_NONE
11+
12+
if CLIENT then
13+
return
14+
end
15+
16+
---
17+
-- @param string key
18+
-- @param string|number value
19+
-- @realm server
20+
function ENT:KeyValue(key, value)
21+
if key == "Role" then
22+
if isstring(value) then
23+
value = _G[value] or value
24+
end
25+
26+
self.checkingRole = tonumber(value)
27+
28+
if not self.checkingRole then
29+
ErrorNoHalt("ttt_filter_role: bad value for Role key, not a number\n")
30+
31+
self.checkingRole = ROLE_NONE
32+
end
33+
end
34+
end
35+
36+
---
37+
-- @param Entity caller
38+
-- @param Entity activator
39+
-- @realm server
40+
function ENT:PassesFilter(caller, activator)
41+
if not IsValid(activator) or not activator:IsPlayer() then
42+
return
43+
end
44+
45+
---
46+
-- @realm server
47+
local activatorRole = activator:GetSubRole()
48+
49+
if self.checkingRole == activatorRole then
50+
Dev(2, activator, "passed filter_role test of", self:GetName())
51+
return true
52+
end
53+
54+
Dev(2, activator, "failed filter_role test of", self:GetName())
55+
56+
return false
57+
end

gamemodes/terrortown/ttt2.fgd

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,35 @@
237237
[
238238

239239
]
240+
241+
@FilterClass base(BaseFilter) = ttt_filter_role :
242+
"A filter that filters by the role of the activator."
243+
[
244+
Role(choices) : "Player role to filter for" : 1 : "The role to filter by. If the filter mode is Allow, only players with the given role will pass the filter. If the filter mode is Disallow, all players EXCEPT those whose role matches the given role will pass the filter." =
245+
[
246+
0 : "Innocent"
247+
1 : "Traitor"
248+
2 : "Detective"
249+
3 : "Any role"
250+
"ROLE_JACKAL" : "Jackal"
251+
"ROLE_SERIALKILLER" : "Serialkiller"
252+
"ROLE_INFECTED" : "Infected"
253+
"ROLE_JESTER" : "Jester"
254+
]
255+
]
256+
257+
@FilterClass base(BaseFilter) = ttt_filter_subrole :
258+
"A filter that filters by the subrole of the activator."
259+
[
260+
Role(choices) : "Player subrole to filter for" : 1 : "The subrole to filter by. If the filter mode is Allow, only players with the given subrole will pass the filter. If the filter mode is Disallow, all players EXCEPT those whose subrole matches the given subrole will pass the filter." =
261+
[
262+
0 : "Innocent"
263+
1 : "Traitor"
264+
2 : "Detective"
265+
3 : "Any role"
266+
"ROLE_JACKAL" : "Jackal"
267+
"ROLE_SERIALKILLER" : "Serialkiller"
268+
"ROLE_INFECTED" : "Infected"
269+
"ROLE_JESTER" : "Jester"
270+
]
271+
]

0 commit comments

Comments
 (0)