Garry's Mod

Garry's Mod

[TTT2] Defective [ROLE]
65 Comments
Sl0ter 2 May @ 4:33am 
strange is that the same model has the detectiv hat but not as defective:
i will try something. one by one adding a workshop until it does not work anymore
blackmagicfine  [author] 2 May @ 12:42am 
@Sl0ter: What part of this is strange? The default playermodel is "css_phoenix", which is the guy with the ski mask. Bots generally spawn with this player model (via the "bot" command). So you can spawn a bot and change their role to Detective/Defective for verification on your end.

If that playermodel doesn't show up wearing a hat, it could be an issue with some addon you've gotten from the workshop. I think it's unlikely to be an issue with the Defective itself, but I've been wrong in the past on these sorts of things.

A bit of history: The reason not all playermodels can wear the hat is because a lot of the custom ones deviate too much from the standard model. Most of them don't even have head hitboxes, even if they do have "heads" (TTT2 can show you which ones do and don't in the F1 menu under playermodels). If you want a playermodel to be hattable, it can be done, but I forget if it's something the admin has to force or if the playmodel's creator has to make that change.
Sl0ter 1 May @ 9:00am 
@blackmagicfine
that's strange.
blackmagicfine  [author] 26 Apr @ 10:15pm 
@Sl0ter: The defective is supposed to wear the detective hat, yes. However, most custom playermodels do not support the wearing of detective hats in general. I just verified that the logic is still working for me (support for detective hats was added several years ago).
Sl0ter 26 Apr @ 1:55am 
should the detective hat work as defective?
the detective has a hat but the defective doesn't.
if the role is reversed it's the same.
ramley 27 Mar @ 11:08am 
I see. Understandable
Thanks anyway!
blackmagicfine  [author] 27 Mar @ 10:54am 
I see. Yeah I don't think there's an easy way to do this without introducing some hacky code that'll inevitably run into weird edge cases. In general though, the idea of having a role be worth two traitor slots is kind of interesting, but this would require a change in the TTT2 source code, rather than something I introduce here.
ramley 27 Mar @ 1:48am 
The thought process is trying to make it so a defective basically takes up two traitors
eg. two defectives = 4 traitors, one defective = two traitors
i think it'd be capable of stirring more chaos is all
if it's not possible though that's perfectly fine
blackmagicfine  [author] 27 Mar @ 1:25am 
@ramley: The short answer is that the settings can't easily force there to be a specific number of players with a given role, or in general change the role selection process while roles are being selected (Even the Anonymous role I made has a bit of a hack to workaround this). It would essentially involve changing player roles right after the round started and hope that no one notices.

But what is the use case for this behavior? Are you trying to make it so that, for example, there's only two Traitors when a Defective is chosen (and both of those Traitors would be Defectives)?
ramley 27 Mar @ 1:08am 
It works, thanks
One more thing, though, is there a way to make it so defective can change the number of traitors when it spawns, or is that out of the scope of what the settings can do?
blackmagicfine  [author] 27 Mar @ 12:16am 
@ramley: I think you could make this happen by following similar settings to how I created the Anonymous TTT2 role.

I think setting these two ConVars to the specified values will do the trick (haven't tested myself):
ttt_defective_pct 1.0
ttt_defective_max 99
A percentage of 1.0 will attempt to force every Traitor into a Defective, and raising the max to a sufficiently high value is needed (the default value of "1" will make it so that only one Defective can spawn)
I'll also note that ttt_defective_random controls the actual chance of the Defective role being considered during role selection. You shouldn't have to change this).

If I recall correctly, to make this work I believe you'll also need the Defective on its own layer, with a higher priority than any other Traitor subroles that you may have. This should prevent issues where TTT2 selects a Traitor subrole (ex. Glutton) first for one Traitor, and only afterwards encounters the selection logic for the Defective.
ramley 26 Mar @ 11:54pm 
Sorry I realize that was bad wording
I mean prevent traitors from spawning (so just defective spawns)
ramley 26 Mar @ 11:48pm 
I've seen videos of this role where it was able to spawn in place of a traitor, but i don't see any way of doing that in the settings. Was this removed or was that a custom version?
Cpt.Haxray 23 Mar @ 12:51pm 
the Color set in the convar seems perfect, but i'll wait to see if I get any feedback/complaints from some colorblind players of mine.
Cpt.Haxray 23 Mar @ 12:08pm 
Cheers. Really appreciate the change :)
blackmagicfine  [author] 23 Mar @ 1:32am 
@Cpt.Haxray: Hey Haxray, long time no talk, just saw your comment (been busy these past few weeks). I have added ttt2_defective_color_mode for you. It is 0 by default (for the default purple color), but if you set it to 1 the Defective will have a more red color. Changes you make to this ConVar won't become apparent until the server restarts or the map changes.

Let me know if you want it to be a different shade of red (and if so, provide the RGB values)
Cpt.Haxray 14 Mar @ 5:34pm 
Would you be willing to consider adding a convar or changing the default role color? It is incredibly confusing for Traitor teammates if they miss the notification at the start of the round, or in the heat of the moment.

This has been a common complaint both on the server I used to run, and on multiple other servers. Changing the default to a shade of Red would make it a lot harder to accidentally teamkill your defective teammate.
Buttercup 28 Mar, 2024 @ 7:39pm 
seems to be working now, thanks for fixing it :)
blackmagicfine  [author] 27 Mar, 2024 @ 2:08am 
@Musp: Thanks for providing this information! I think I rootcaused the bug. The short of it is that the logic for handling the rare Defective + Spy combination is pretty convoluted. There's a lot of logic that has the Spy's handling take priority over the Defective's. However, for body confirmation it seems like I missed a spot. It should be fixed now, but please check on your end though and let me know how it goes.
Buttercup 25 Mar, 2024 @ 5:22pm 
I don't have any experience using GitHub so here's a video that shows the issue:
https://youtu.be/jmveQPf7Wg4

also here is a link to the collection of addons I'm using, hope this helps:
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2913451164
blackmagicfine  [author] 24 Mar, 2024 @ 9:59pm 
@Musp: I am unable to reproduce your issue. The only way that this can happen that I'm aware of is if you change ttt2_defective_corpse_reveal_mode mid-game (for example, after you have killed the def).

It could be that there's some sort of conflicting addon that you have. Or perhaps there's some combination of ConVars that I haven't properly tested. If you wish, you could submit a bug on GitHub, though I would need more information from you (ex. video, addon list, etc.)
Buttercup 23 Mar, 2024 @ 2:21pm 
I have ttt2_defective_corpse_reveal_mode set to 0 but when a det searches the corpse of a def it shows the role icon on the body as def instead of det. Any way to fix this :)
blackmagicfine  [author] 24 Nov, 2023 @ 4:01pm 
@SylpheedW: Something I forgot to mention is that even if the Masterchief is demoted the music that plays when they're first selected will still play.
blackmagicfine  [author] 24 Nov, 2023 @ 2:57pm 
@SylpheedW: I am unable to reproduce your issue. I tested it out with a few other detective roles, such as the Vigilante and Banker. I also tested dynamically changing the role mid game, but it all seems to work fine on my end. I looked at the Masterchief's code and it seems fine. Perhaps this issue is related to a different addon or convar?
SylpheedW 24 Nov, 2023 @ 9:42am 
Hi @blackmagicfine
I have the problem that the detective still gets the role "Master Chief" even though ttt2_defective_special_det_handling_mode is set to "1".
Could you please look into this?
Voxel | Julia 25 Jun, 2023 @ 3:24am 
Thank you!
blackmagicfine  [author] 24 Jun, 2023 @ 7:44pm 
@Pixelblock: The feature was more involved than I originally anticipated, but it is done. When you set ttt2_defective_special_det_handling_mode to 3 you will activate "VISAGE" mode. Quick rundown:

1. The Defective may receive a visage of a special detective role. Probabilities are determined by that role's own chances of popping up in game
2. The Defective will be notified of the role they are disguised as through a rather large popup that disappears after a few seconds
3. Everyone who can see the Defective's true role (including the Defective themselves) will further be notified via chat message
4. Those who can see the Defective's true role will see a line like "Disguised as <ROLE>" when hovering their cursor over the Defective

The changes were substantial, so let me know if you (or anyone else!) runs into any issues.
Voxel | Julia 21 Jun, 2023 @ 4:03pm 
I do know that not having the abilitys of thier presumed role is a big risk for the def, but i also think this is the best way of handeling it. It would be amazing if you could add this new mode as it would solve my problem perfectly!
blackmagicfine  [author] 21 Jun, 2023 @ 1:26pm 
@Pixelblock: I assume that you have ttt2_defective_special_det_handling_mode set to 0. By default it is 1, which forces special Dets (ex. Sheriff, Sniffer, Banker, etc) to be regular Dets, which prevents the problem that you're observing entirely.

If you want, I can add a new mode for ttt2_defective_special_det_handling_mode. This new mode would assign a probability for the Def to look like a Sheriff/Sniffer/Banker/etc. while also not altering the role of special Dets. However, I should warn you that this will put the Def at a significant disadvantage: They would not have the abilities of their assumed role. This is particularly evident if the Def is masquerading as a Sheriff or Sniffer, as they would not have a Magnifying Glass or Deputy Deagle and thus would be extremely easy to identify.

I would be unwilling to also give the Def the abilities of the special Det role that they're masquerading as: This would require hardcoding for every special Det role (i.e. buggy)
Voxel | Julia 21 Jun, 2023 @ 12:35pm 
It would be nice if the defective could also be displayed as another configurable dt role. This would stop defectives being easily identifyable in rounds where the dt always has another role
blackmagicfine  [author] 1 May, 2023 @ 9:41pm 
@Dill: Short answer:
Set ttt2_defective_inform_everyone to 0
Set ttt2_defective_disable_spawn_if_no_detective to 0
Set ttt2_defective_demote_detective_pct to 1.0

For a more technical answer: TTT2 doesn't allow for fine role selection logic such as "Only enable this role if this other role is or is not present". The above two options hack in what you desire (your players won't notice the difference).
hashbrown pussy 1 May, 2023 @ 1:39pm 
Is there any way I can make it so that defectives spawn ONLY when detectives don't?
Kanjuro 10 Apr, 2022 @ 5:26am 
God, now I'm feeling stupid. It was actually the Spy, who with default settings, always spawns and is confirmed as a Traitor when other Traitors still live. In all my testing scenarios I seem to have never killed him last, so he never was revealed as a Spy. Seems like his role is doing exactly what it was supposed to do: confusing the heck out of his evil opponents. ^^ Still, thank you for all your precious time. Great and fun addons, btw.
blackmagicfine  [author] 9 Apr, 2022 @ 5:59pm 
@Kanjuro: I'm not able to reproduce this.

Round Info should be able to see that the Defective is a Traitor. It does on my end at least. It does this both at the start of the round (by saying that there's 2 traitors in the game in chat), and when the Defective kills you (by displaying a pop-up saying as much).

There's a couple things that could have gone wrong here. One possibility is that you have a conflicting addon that is reinterpreting the Defective as an Innocent. Another possibility is that you have a conflicting addon or strange role distribution settings (ex. making "ttt_min_inno_pct" too low) which have added a 3rd traitor to your scenario, when you only want 2 (This doesn't explain why Round Info is telling you that the Defective is Innocent though).

I'm not sure how this could come about in the Defective's source code alone. Try taking out addons that can mess with a player's role and see if you are still able to reproduce the issue.
Kanjuro 9 Apr, 2022 @ 1:27pm 
I thought so too, but if I have 7 players which normally consist of 4 normal innocents, 2 traitors and 1 detective and I were to enable the defective (which, for testing purposes, has a 100% chance to spawn and to replace the detective), I will end up with 4 innocents and 3 traitors (of which 1 is the defective). The basic role distribution settings for detective and defective are the same, if that matters. Additionally, the addon "[TTT2] Round Info" also detects the defective as an innocent, which would give him away, but that might just be an incompatibility.
blackmagicfine  [author] 9 Apr, 2022 @ 11:44am 
@Kanjuro: This is already the case. The Defective is a traitor subrole and takes up a traitor slot.
Kanjuro 9 Apr, 2022 @ 9:36am 
Would it be possible to add a ConVar that counts a defective, that replaced a detective, towards the maximum percentage of traitors? So having originally 2 traitors and 1 detective wouldn't leave the traitor team with 3 people, but 2 (1 defective and 1 other traitor role).
Hannes 11 Feb, 2022 @ 5:32am 
Thanks, very much appreciated! ^^
blackmagicfine  [author] 11 Feb, 2022 @ 1:53am 
@Hannes: It should be fixed now. Looks like I neglected to add some end-of-round cleanup logic for this scenario.
Hannes 9 Feb, 2022 @ 10:50am 
Everything is on default except for the "corpse reveal mode" (it's on 1) and the "special det handling" (it's on 2).
blackmagicfine  [author] 9 Feb, 2022 @ 10:41am 
@Hannes: Just so we're on the same page, could you share with me your rolespecific ConVars?
Hannes 9 Feb, 2022 @ 7:33am 
Oh, but after some more testing, I think this only happens, if the Detectives and Defective are the last ones in the round and only then can do damage to each other in order for the round to end...
Hannes 9 Feb, 2022 @ 6:33am 
I hope my explanation wasn't too confusing xD.
Hannes 9 Feb, 2022 @ 6:32am 
So, I did a little testing with roles on my server and in one round I just got randomly turned into a Detective (Mayor in my case). After some more testing I found out that this problem is because of the Defective: If there is a Defective in the round, he will turn every special Detective into a normal one, so far so good. However, after the round ends and a new one starts: If there are Detectives in this round and they all get killed, the players that were supposed to be special Detectives in the previous round will change their role into that special Detective (doesn't matter what role they had up to this point)
blackmagicfine  [author] 14 Oct, 2021 @ 12:05pm 
With the recent update to TTT2 (v0.10.0b), a lot of things changed that impacted the Defective. In theory, it should be less hardcoded now, and my testing revealed nothing strange, but please report any strange behavior you happen to find.

In addition, credits were reworked. I ended up removing ttt2_defective_gain_traitor_credits, as the Defective now gains credits like a Traitor by default. I don't think this will impact the Defective's ability to mimic a Detective, as Traitors tend to gain more credits than Detectives in general.

Finally, I decoupled the Defective's starting credits from the Detective's, so you may need to set that value manually in your server.
|UGA|PatPeter 9 Sep, 2021 @ 11:25pm 
I created a master configuration file for all of the TTT roles in the first 3 pages of the Workshop search: https://gist.github.com/PatPeter/70b1c090d8c8c311d99632dca76ec513
blackmagicfine  [author] 20 Mar, 2021 @ 8:17pm 
Ok, I have uploaded the new feature. It is known as "ttt2_defective_demote_detective_pct"
SmilinTurd 8 Mar, 2021 @ 10:44pm 
Absolutely love it, perfect solution. thanks heaps. We play with only 1 detective anyway so the second concern is no issue for us. I do agree that it does mess with one of the core mechanics, but we have a group that for the most part the traitors lose, so a chance of the detective being 1 of the traitors will make it extra spicy. love your work.
blackmagicfine  [author] 7 Mar, 2021 @ 9:30pm 
I'm of the belief that doing that would destroy the core mechanic of the detective (that they're trustworthy). That's why the popup message is shown by default.

I think what I could do is have a ConVar that is a percentage (0.0 by default). If that percentage is hit, then in the beginning of a round where there is at least one def, I could "demote" a det into an innocent for each def in game. This demotion would also affect special det roles such as the Sheriff or Vigilante. The popup that normally informs everyone (when ttt2_defective_inform_everyone is enabled) would also be prevented from showing up if there are no dets in general, but could still show up if there's a mix of the two.

ttt2_defective_disable_spawn_if_no_detective would need to be disabled for this.

Keep in mind that if there are more dets than defs, than there would still be a mix of the two with this ConVar. Reason for this is because flat out demoting all dets seems pretty OP to me.

Would that work for you?
SmilinTurd 7 Mar, 2021 @ 8:10pm 
Any chance to have it where that the defective can "replace" the detective. So when spawning roles, theres is not a real detective but a singular defective that everyone believes to be the detective?