Garry's Mod

Garry's Mod

[TTT2] Mimic and Doppelganger [ROLE]
 This topic has been pinned, so it's probably important
Wasted  [developer] 30 Dec, 2020 @ 10:58am
Mimic and Doppelganger Special Role Handling Hook
As these roles have the potential to create bizarre and broken interactions with roles, I've added a means by which Addon Developers and/or Server Admins can easily edit/overwrite the ways in which Mimic/Doppelganger steal roles.

Before the Mim/Dop begin stealing a role, the hook
TTT2DoppelgangerRoleChange
is run with the argument
mimic_data

mimic_data is a table consisting of the following:
mimic_data.ply = mimic player mimic_data.tgt = targeted player mimic_data.role = the role of the targeted player mimic_data.rolestring = the raw rolename string (used to create the HUD text "Transforming into ...") mimic_data.team = the team of the targeted player mimic_data.did_steal = whether or not the Mim/Dop actually stole the target player's role (true by default) mimic_data.abort = whether or not to abort role change/steal entirely

Editing any part of this table in Lua function and returning the mimic_data table will overwrite.

An example of this is with the special handling for the Marker role:

local function DoppelMarker(mimic_data) if not MARKER then return end if not GetConVar("ttt2_dop_marker"):GetBool() then return end local ply = mimic_data.ply if not IsValid(ply) or ply:IsSpec() or not ply:Alive() then return end if ply:GetSubRole() ~= ROLE_DOPPELGANGER and ply:GetSubRole() ~= ROLE_MIMIC then return end if mimic_data.role ~= ROLE_MARKER then return end mimic_data.did_steal = false if AMNESIAC then mimic_data.role = ROLE_AMNESIAC mimic_data.team = TEAM_NONE elseif UNKNOWN then mimic_data.role = ROLE_UNKNOWN mimic_data.team = TEAM_NONE else mimic_data.role = ROLE_INNOCENT mimic_data.team = TEAM_INNOCENT end mimic_data.rolestring = roles.GetByIndex(mimic_data.role).name if MARKER_DATA then MARKER_DATA:SetMarkedPlayer(ply) end return mimic_data end hook.Add("TTT2DoppelgangerRoleChange", "TTT2DoppelMarker", DoppelMarker)

This checks if a doppelganger or a mimic is trying to become a Marker, in which case it will override, forcing them to be Amnesiac (or Unknown or Innocent) and, importantly sets the Mimic as having FAILED to steal the role. This setting prevents the target from losing their role, even though the Mimic/Doppelganger didn't actually steal it.
Last edited by Wasted; 19 Jan, 2021 @ 4:42pm