• Colored Chat Text in TTT
    14 replies, posted
Trying to get it to announce the victims killer, their role IN COLOR and whether dna was found leading to the victim or not. Somebody help me. [CODE] function wasDnaFound(finder,dnaOwner,entFoundOn) victimIdDna = dnaOwner:SteamID() end hook.Add("TTTFoundDNA","Was DNA Found", wasDnaFound) function sayThatName(victim,inflictor,killer) local killerCodeRole = killer:GetRole() local killerStringRole = "ERROR: Role not found" local victimId = victim:SteamID() if killerCodeRole == ROLE_TRAITOR then killerStringRole = Color(255, 0, 0), "traitor" elseif killerCodeRole == ROLE_INNOCENT then killerStringRole = Color(0,255,0), "innocent" elseif killerCodeRole == ROLE_DETECTIVE then killerStringRole = Color(0,0,255), "detective" end victim:PrintMessage(HUD_PRINTTALK, killer:Nick().." killed you! They were a ".."killerStringRole".." they found DNA leading to you!") if victimId == victimIdDna then victim:PrintMessage(HUD_PRINTTALK, killer:Nick().." killed you! They were a "..killerStringRole.." they found DNA leading to you!") elseif victimId ~= victimIdDna then victim:PrintMessage(HUD_PRINTTALK, killer:Nick().." killed you! They were a "..killerStringRole.." DNA was not found that lead to you!") end end hook.Add("PlayerDeath","Inform Murder Victims", sayThatName) [/CODE]
[code]local role_color = { [ROLE_TRAITOR] = Color(255,0,0,255), [ROLE_INNOCENT] = Color(0,255,0,255), [ROLE_DETECTIVE] = Color(0,0,255,255) } function TTTDeath(ply, attacker, dmginfo) if IsValid(attacker) and attacker:IsPlayer() then ply:ChatPrint(role_color[attacker:GetRole()],"You were killed by "..attacker:Nick().." who is a"..attacker:GetRoleString()..".") end end hook.Add("DoPlayerDeath", "TTTDeaths", TTTDeath)[/code] Pardon the awful spacing, did this on my phone.
[QUOTE=code_gs;43469755][code]function TTTDeath(ply, attacker, dmginfo) local role_color = { [ROLE_TRAITOR] = Color(255,0,0,255), [ROLE_INNOCENT] = Color(0,255,0,255), [ROLE_DETECTIVE] = Color(0,0,255,255) } if IsValid(attacker) and attacker:IsPlayer() then ply:ChatPrint(role_color[attacker:GetRole()],"You were killed by "..attacker:Nick().." who is a"..attacker:GetRoleString()..".") end end hook.Add("DoPlayerDeath", "TTTDeaths", TTTDeath)[/code][/QUOTE] That table should be outside the function.
[QUOTE=brandonj4;43470335]That table should be outside the function.[/QUOTE] Why? It's only used inside that function; nowhere else.
[QUOTE=code_gs;43470361]Why? It's only used inside that function; nowhere else.[/QUOTE] You're making the code do more work by creating the table every single time that function is called.
Oh, you're right. Fixed it.
lol Wheres the fixed version? BTW thanks for the dumb vote brandon >.>
chatprint refuses to accept a color and just returns error with argument 1: string expected
chat.AddText is how you display colored messages, but it is a client side function
So then how would be able to store the data clientside and call it with the server?
[CODE]ply:SendLua([[chat.AddText(Color(0,0,200), "Dem Colors")]])[/CODE] You can use that for sending players colored chat. Or maybe not. >.>
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2b09.html[/url] Works client, so you can change the color without messy networking.
[QUOTE] [url]https://github.com/garrynewman/garry...e/lang_shd.lua[/url] TTT has specific functions for this sort of stuff.[/QUOTE] I need to learn a LOT more about lue before I can even begin to COMPREHEND that stuff XD Cant I just use [QUOTE]ply:SendLua([[chat.AddText(Color(0,0,200), "Dem Colors")]]) You can use that for sending players colored chat.[/QUOTE]
[QUOTE=Fortune11709;43483983][CODE]ply:SendLua([[chat.AddText(Color(0,0,200), "Dem Colors")]])[/CODE] You can use that for sending players colored chat. Or maybe not. >.>[/QUOTE] Solved my problem solely because of this guy. Thanks everyone else for trying though.
Sorry, you need to Log In to post a reply to this thread.