local healthcolors = { healthy = Color(0,255,0,255), hurt = Color(170,230,10,255), wounded = Color(230,215,10,255), badwound= Color(255,140,0,255), death = Color(255,0,0,255), rag = Color(200,200,200,255) } local function HealthToString(health) if health > 90 then return "Healthy", healthcolors.healthy elseif health > 70 then return "Hurt", healthcolors.hurt elseif health > 45 then return "Wounded", healthcolors.wounded elseif health > 20 then return "Badly Wounded", healthcolors.badwound else return "Near Death", healthcolors.death end end local karmacolors_greenred = { max = Color(0,255,0,180), high = Color(170,230,10,180), med = Color(230,215,10,180), low = Color(255,140,0,180), min = Color(255,0,0,180), }; local karmacolors_yellows = { max = Color(255,255,255,255), high = Color(255,240,135,255), med = Color(245,220,60,255), low = Color(255,180,0,255), min = Color(255,130,0,255), }; local karmacolors = karmacolors_yellows local function KarmaToString(karma) if karma > 890 then return "Reputable", karmacolors.max elseif karma > 800 then return "Crude", karmacolors.high elseif karma > 650 then return "Trigger-happy", karmacolors.med elseif karma > 500 then return "Dangerous", karmacolors.low else return "Liability", karmacolors.min end end local ClassHint = { prop_ragdoll = { name="Corpse", hint= Format("Press %s to search. %s + %s to search covertly.", Key("+use", "USE"), Key("+walk", "WALK"), Key("+use", "USE"))} }; -- Basic access for servers to add/modify hints. They override hints stored on -- the entities themselves. function GM:AddClassHint(cls, hint) ClassHint[cls] = table.Copy(hint) end local function DrawPropSpecLabels(client) if (not client:IsSpec()) and (GetRoundState() != ROUND_POST) then return end surface.SetFont("TabLarge") surface.SetTextColor(220,200,0,120) local tgt = nil local scrpos = nil local text = nil local w = 0 for _, ply in pairs(player.GetAll()) do if ply:IsSpec() then tgt = ply:GetObserverTarget() if IsValid(tgt) and tgt:GetNWEntity("spec_owner", nil) == ply then scrpos = tgt:GetPos():ToScreen() if not IsOffScreen(scrpos) then text = ply:Nick() w, _ = surface.GetTextSize(text) surface.SetTextPos(scrpos.x - w / 2, scrpos.y) surface.DrawText(text) end end end end end surface.CreateFont("TargetID", 16, 1000, true, false, "TargetIDSmall2") local minimalist = CreateConVar("ttt_minimal_targetid", "0", FCVAR_ARCHIVE) local magnifier = surface.GetTextureID("gui/silkicons/magnifier") local ring_tex = surface.GetTextureID("effects/select_ring") function GM:HUDDrawTargetID() local client = LocalPlayer() DrawPropSpecLabels(client) local trace = client:GetEyeTrace(MASK_SHOT) local ent = trace.Entity if not IsValid(ent) then return end -- some bools for caching what kind of ent we are looking at local target_traitor = false local target_detective = false local target_corpse = false local text = nil local color = COLOR_WHITE -- if a vehicle, we identify the driver instead if IsValid(ent:GetNWEntity("ttt_driver", nil)) then ent = ent:GetNWEntity("ttt_driver", nil) if ent == client then return end end local cls = ent:GetClass() local minimal = minimalist:GetBool() local hint = (not minimal) and (ent.TargetIDHint or ClassHint[cls]) if ent:IsPlayer() then if ent:GetNWBool("disguised", false) then client.last_id = nil if client:IsTraitor() or client:IsSpec() then text = ent:Nick() .. "(DISGUISED)" else -- Do not show anything return end color = COLOR_RED else text = ent:Nick() client.last_id = ent end -- in minimalist targetID, colour nick with health level if minimal then _, color = HealthToString(ent:Health()) end if client:IsTraitor() and GAMEMODE.round_state == ROUND_ACTIVE then target_traitor = ent:IsTraitor() end target_detective = ent:IsDetective() elseif cls == "prop_ragdoll" then -- only show this if the ragdoll has a nick, else it could be a mattress if CORPSE.GetPlayerNick(ent, false) == false then return end target_corpse = true if CORPSE.GetFound(ent, false) or not DetectiveMode() then text = CORPSE.GetPlayerNick(ent, "A Terrorist") else text = "Unidentified body" color = COLOR_YELLOW end elseif not hint then -- Not something to ID and not something to hint about return end local x_orig = ScrW() / 2.0 local x = x_orig local y = ScrH() / 2.0 local w, h = 0,0 -- text width/height, reused several times if target_traitor or target_detective then surface.SetTexture(ring_tex) if target_traitor then surface.SetDrawColor(255, 0, 0, 200) else surface.SetDrawColor(0, 0, 255, 220) end surface.DrawTexturedRect(x-32, y-32, 64, 64) end y = y + 30 local font = "TargetID" surface.SetFont( font ) -- Draw main title, ie. nickname if text then w, h = surface.GetTextSize( text ) x = x - w / 2 draw.SimpleText( text, font, x+1, y+1, COLOR_BLACK ) draw.SimpleText( text, font, x, y, color ) -- for ragdolls searched by detectives, add icon if ent.search_result and client:IsDetective() then -- if I am detective and I know a search result for this corpse, then I -- have searched it or another detective has surface.SetTexture(magnifier) surface.SetDrawColor(200, 200, 255, 255) surface.DrawTexturedRect(x + w + 5, y + 4, 16, 16) end y = y + h + 4 end -- Minimalist target ID only draws a health-coloured nickname, no hints, no -- karma, no tag if minimal then return end -- Draw subtitle: health or type local clr = healthcolors.rag if ent:IsPlayer() then text, clr = HealthToString(ent:Health()) elseif hint then text = hint.name else return end font = "TargetIDSmall2" surface.SetFont( font ) w, h = surface.GetTextSize( text ) x = x_orig - w / 2 draw.SimpleText( text, font, x+1, y+1, COLOR_BLACK ) draw.SimpleText( text, font, x, y, clr ) font = "TargetIDSmall" surface.SetFont( font ) -- Draw second subtitle: karma if ent:IsPlayer() and KARMA.IsEnabled() then text, clr = KarmaToString(ent:GetBaseKarma()) w, h = surface.GetTextSize( text ) y = y + h + 5 x = x_orig - w / 2 draw.SimpleText( text, font, x+1, y+1, COLOR_BLACK ) draw.SimpleText( text, font, x, y, clr ) end -- Draw key hint if hint and hint.hint then if not hint.fmt then text = hint.hint else text = hint.fmt(ent, hint.hint) end w, h = surface.GetTextSize(text) x = x_orig - w / 2 y = y + h + 5 draw.SimpleText( text, font, x+1, y+1, COLOR_BLACK ) draw.SimpleText( text, font, x, y, COLOR_LGRAY ) end text = nil if target_traitor then text = "FELLOW TRAITOR" clr = COLOR_RED elseif target_detective then text = "DETECTIVE" clr = COLOR_BLUE elseif ent.sb_tag and ent.sb_tag.txt != nil then text = ent.sb_tag.txt clr = ent.sb_tag.color elseif target_corpse and client:IsActiveTraitor() and CORPSE.GetCredits(ent, 0) > 0 then text = "Search to receive unspent credits." clr = COLOR_YELLOW end if text then w, h = surface.GetTextSize( text ) x = x_orig - w / 2 y = y + h + 5 draw.SimpleText( text, font, x+1, y+1, COLOR_BLACK ) draw.SimpleText( text, font, x, y, clr ) end end