View difference between Paste ID: 5A43jjmy and PJFCQbWv
SHOW: | | - or go back to the newest paste.
1
-- Reset player states when the round ends and begins
2
hook.Add("TTTEndRound", "weapon_ttt_deputy", function(result)
3
  for k, v in pairs(player.GetAll()) do
4
      v.DeputyFakeDetective = false
5
      v.DeputyActive = false
6
  end
7
end)
8
9
hook.Add("TTTBeginRound", "weapon_ttt_deputy", function()
10
  for k, v in pairs(player.GetAll()) do
11
      v.DeputyFakeDetective = false
12
      v.DeputyActive = false
13
  end
14
end)
15
16
-- Actually override the functions
17
hook.Add("InitPostEntity", "TTTDeputyInitPostEntity", function()
18
  local Player = FindMetaTable("Player")
19
  if Player then
20
    if !isfunction(Player.GetDetectiveOld) then
21
      Player.GetDetectiveOld = Player.GetDetective
22
    end
23
24
    function Player:GetDetective()
25
      if self:GetRole() == ROLE_DETECTIVE then return self:GetDetectiveOld() end
26
27
      return self.DeputyActive && self.DeputyFakeDetective
28
29
    end
30
31
    Player.IsDetective = Player.GetDetective
32
  end
33
end)
34
35
-- For testing
36
concommand.Add("ttt_deputy_forceall", function(ply, cmd, args)
37
  for k, v in pairs(player.GetAll()) do
38
    v.DeputyActive = true
39
40
    if v:IsActiveTraitor() then
41
      v.DeputyFakeDetective = true
42
    end
43
  end
44
end)
45
46
concommand.Add("ttt_deputy_resetall", function(ply, cmd, args)
47
  for k, v in pairs(player.GetAll()) do
48
    v.DeputyActive = false
49
50
    if v:IsActiveTraitor() then
51
      v.DeputyFakeDetective = false
52
    end
53
  end
54
end)
55
56
--- Test 1 (Bot03 is Traitor):
57
-- ttt_deputy_forceall
58
-- lua_run for k, v in pairs(player.GetAll()) do print(v:Nick(), v:GetDetective()) end
59
-- Bot01 false
60
-- Bot02 false
61
-- Bot03 true -- This is correct! But the HUD isn't updating!
62
-- Doctor Jew false
63
64
--- Test 2 (Bot03 is Traitor):
65
-- ttt_deputy_forceall
66
-- lua_run for k, v in pairs(player.GetAll()) do print(v:Nick(), v:IsDetective()) end
67
-- Bot01 false
68
-- Bot02 false
69
-- Bot03 true -- This is correct! But the HUD isn't updating!
70
-- Doctor Jew false