Hello,
I run a small TTT server and wanted a killer notifier so people can know who killed them. However when someone is killed by either fall damage, fire or other means they are not moved to spectators. I will attach the code I found on these forums and the error the server outputs.
Thank you for any help.
[CODE]//// sv_kill_notifier.lua by Josh 'Acecool' Moser//util.AddNetworkString( "_ttt_kill_notifier" );hook.Add( "PlayerDeath", "TTT:KillNotifier", function( victim, weapon, killer ) net.Start( "_ttt_kill_notifier", victim ); net.WriteTable( { killer = killer:EntIndex( ), role = killer:GetRole( ) } ); net.Send( victim );end );
[/CODE]
[CODE]//// cl_kill_notifer.lua by Josh 'Acecool' Moser//net.Receive( "_ttt_kill_notifier", function( byte, Player ) local _tab = net.ReadTable( ); local _killer = Entity( _tab.killer ); if ( !IsValid( _killer ) ) then return; end local _role = _tab.role; local _bDetective = _role == ROLE_DETECTIVE; local _bTraitor = _role == ROLE_TRAITOR; local _chat = { Color( 255, 255, 255 ), "You were killed by ", Color( 175, 175, 175 ), _killer:Nick() }; // Determine a or an for text output. local _textAorAN = ( _bDetective || _bTraitor ) and "a" or "an"; table.insert( _chat, Color( 255, 255, 255 ) ); table.insert( _chat, ", " .. _textAorAN ); // Determine color of output for the role, and text output. local _textRoleColor = ( _bDetective ) and Color( 0, 0, 255 ) or ( _bTraitor ) and Color( 255, 0, 0 ) or Color( 0, 255, 0 ); local _textRole = ( _bDetective ) and "Detective" or ( _bTraitor ) and "Traitor" or "Innocent"; table.insert( _chat, _textRoleColor ); table.insert( _chat, " " .. _textRole .. "!" ); // Output it chat.AddText( unpack ( _chat ) ); chat.PlaySound( );end )
[/CODE]
[CODE][ERROR] lua/autorun/server/sv_kill_notifier.lua:8: attempt to call method 'GetRole' (a nil value) 1. v - lua/autorun/server/sv_kill_notifier.lua:8 2. unknown - lua/includes/modules/hook.lua:84[/CODE]
This line seems to be causing the error.
[QUOTE=Alextmac;45605046][CODE]//// sv_kill_notifier.lua by Josh 'Acecool' Moser//[/CODE]
[/QUOTE]
Here I fixed it for you...
[CODE]
hook.Add("PlayerDeath", "TTT_PlayerDeath_SayRole", function(victim, weapon, killer)
if killer:IsPlayer() then
victim:ChatPrint("You were killed by "..killer:GetName()..", they were an"..string.Capitalize(killer:GetRoleString())..".")
elseif killer == victim then
victim:ChatPrint("You just killed yourself you nub...")
else
victim:ChatPrint("You were killed by the world.")
end
end)
[/CODE]
[QUOTE=King Traitor;45605979]This line seems to be causing the error.[/QUOTE]
Delete that otherwise someone (you know who you are) is probably gonna report you and you'll get banned :P
Thank you King Traitor, that seems to have done the trick.
Sorry, you need to Log In to post a reply to this thread.