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