TTT - Killer Notifier

Hi guys, so I have a killer notifier on my server that has the usual who you were killed by and what role they were. But to me it seems abit… empty.
It’s not fancy enough :stuck_out_tongue:

I want to make a small modifcation to it, however I do not know how to do this as I am not that great with lua coding.


if(CLIENT) then return end

hook.Add("PlayerDeath", "TTT_PlayerDeath_SayRole", function(victim, weapon, killer)
    if gmod.GetGamemode().Name == "Trouble in Terrorist Town" then
	    if killer:IsPlayer() then
	        victim:ChatPrint("You were killed by "..killer:GetName()..", he was "..string.Capitalize(killer:GetRoleString())..".")
		elseif killer == victim then
		    victim:ChatPrint("You just killed yourself...")
		else
		    victim:ChatPrint("You were killed by the world.")
		end
	end
end)

At the moment, it displays a message when the player dies as: “You were killed by <name>, they were <role>.” what I would love to know is how to modify it so that it shows a colour on the text of the role.
Innocent = Green
Traitor = Red
Detective = Blue

Could anyone assist me in this rather small modification?

Here’s one I made: https://dl.dropboxusercontent.com/u/26074909/tutoring/_zipped_code/acecool_ttt_kill_notifier.rar

Extract to garrysmod/addons/ so that acecool_ttt_kill_notifier is in addons and lua/ is the starting sub-folder.

It handles colors for roles, proper grammar, etc…

Amazing! Thank you so much! :smiley:

For future reference though if you wanted to add colours you’d need to use the net library and then chat.AddText to print the the text box.

Or you could ply:SendLua() the lua

I thought that method was generally looked down upon?

It is, to be honest, but it’s a lazy way and it’s not crucial for it to get through. The chances of it not reaching the client is very small

Here’s an example using SendLua for those interested, I use it in one of the tutorial systems ( donator manager ) for when the client runs the server concommand donators or donators /?


// Only admins / rcon should be able to execute the function
if ( !IsValid( _p ) || !_p:IsAdmin( ) ) then return; end

// just "donators" in console
if ( !_args || ( istable( _args ) && table.Count( _args ) < 1 ) ) then
	_p:SendLua( [[chat.AddText( Color( 150, 150, 255, 255 ), "Welcome to Donator Manager.
The Console Command looks like this: \"donators /<command> <argument> <argument2>\"
Use donators /? for help!" )]] );
	return;
end

// using "donators /?" in console
if ( _cmd == "/?" ) then
	_p:SendLua( [[chat.AddText( Color( 150, 150, 255, 255 ), "Welcome to Donator Manager. The Console Command looks like this: \"donators /<command> <argument> <argument2>\", available commands:" )]] );
	_p:SendLua( [[chat.AddText( Color( 0, 255, 0, 255 ), "	donators /adduser [ days || -1 = permanent ] - adds the user you're looking at to the donators table." )]] );
	_p:SendLua( [[chat.AddText( Color( 0, 255, 0, 255 ), "	donators /adduser steamid ]] .. _p:SteamID( ) .. [[ [ days || -1 = permanent ] - adds the users steamid you typed to the donators table." )]] );
	_p:SendLua( [[chat.AddText( Color( 0, 255, 0, 255 ), "	donators /adduser name ]] .. _p:Nick( ) .. [[ [ days || -1 = permanent ] - adds the users steamid of the players partial name you typed to the donators table ** IF PEOPLE HAVE SIMILAR NAMES, TYPE MORE OF THE NAME **." )]] );
	_p:SendLua( [[chat.AddText( Color( 255, 0, 0, 255 ), "	donators /deluser - removes the user you're looking at to the donators table." )]] );
	_p:SendLua( [[chat.AddText( Color( 255, 0, 0, 255 ), "	donators /deluser steamid ]] .. _p:SteamID( ) .. [[ - removes the users steamid you typed to the donators table." )]] );
	_p:SendLua( [[chat.AddText( Color( 255, 0, 0, 255 ), "	donators /deluser name ]] .. _p:Nick( ) .. [[ - removes the users steamid of the players partial name you typed to the donators table ** IF PEOPLE HAVE SIMILAR NAMES, TYPE MORE OF THE NAME **." )]] );
	_p:SendLua( [[chat.AddText( Color( 255, 255, 255, 255 ), "	* donators /list - lists all donators currently in the server." )]] );
	_p:SendLua( [[chat.AddText( Color( 255, 255, 255, 255 ), "	* donators /listall - lists all donator steamids; if they're in the server their name will be beside their id." )]] );
	_p:SendLua( [[chat.AddText( Color( 255, 255, 255, 255 ), "	* donators /reload - forces the file to be re-opened, useful if edited in text-editor." )]] );
	_p:SendLua( [[chat.AddText( Color( 255, 255, 255, 255 ), "	* donators /save - forces the file to be saved, useful if you think the server will crash and you've made changes and do not want to wait for the scheduled save." )]] );
end

I can’t recall if it uses UMSG or NET. SendLua isn’t ideal.