Skip to content

Commit 676df2d

Browse files
authored
Support for new TTT entity ttt_filter_role (#1789)
closes #1786 new ttt_filter_role entity is from Facepunch/garrysmod#2225
1 parent dabf76f commit 676df2d

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
77
### Added
88

99
- Added option to select preferred unit of length for distance displays (by @wgetJane)
10+
- Port new TTT entity ttt_filter_role to TTT2 (Facepunch/garrysmod/pull/2225 by @figardo, ported by @wgetJane)
1011

1112
### Changed
1213
- Updated Russian and English localization files (by @Satton2)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
-- @class ENT
3+
-- @section ttt_filter_role
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 role, team = hook.Run("TTT2ModifyLogicRoleCheck", activator, self, activator, caller, "")
48+
local activatorRole = roles.GetByIndex(role, roles.INNOCENT):GetBaseRole()
49+
local activatorTeam = (gameloop.GetRoundState() == ROUND_PREP) and TEAM_INNOCENT or team
50+
51+
if
52+
self.checkingRole == ROLE_TRAITOR and util.IsEvilTeam(activatorTeam)
53+
or self.checkingRole == ROLE_INNOCENT and not util.IsEvilTeam(activatorTeam)
54+
or self.checkingRole == activatorRole and not (self.checkingRole == ROLE_TRAITOR or self.checkingRole == ROLE_INNOCENT)
55+
or self.checkingRole == ROLE_NONE
56+
then
57+
Dev(2, activator, "passed filter_role test of", self:GetName())
58+
59+
return true
60+
end
61+
62+
Dev(2, activator, "failed filter_role test of", self:GetName())
63+
64+
return false
65+
end

0 commit comments

Comments
 (0)