A script (killer.lua) is causing my server to crash.

One of the developers on my community created this LUA script, which tells the player who killed him and was the killer a traitor, innocent etc.

Here is the code:



function ChatMessage( victim, inflictor, killer )
    if(victim:Alive()) then
        victim:Kill()
    end

    if( IsValid( killer ) and IsValid( victim ) ) then
        if(killer:Nick() == victim:Nick()) then   
            LANG.Msg("slain", {victim = victim:Nick(), role = ResolvePlayerRole(victim)} )
        else
               if( killer:IsPlayer() and victim:IsPlayer() ) then
                   victim:SendLua( [[chat.AddText( ]] .. ResolveRoleColour( killer ) .. [[, "You were killed by ]] .. killer:Nick() .. ResolvePlayerRole( killer ) .. [[!" )]] )
              end
          end
    end
end
hook.Add( "PlayerDeath", "DoChat", ChatMessage )
 
function ResolvePlayerRole( ply )
        return ( "a" and ply:IsTraitor() ) or ( "a" and ply:IsDetective() ) or "an innocent"
end
 
function ResolveRoleColour( ply )
        return ( ply:IsTraitor() and "Color( 255, 0, 0 )" ) or ( ply:IsDetective() and "Color( 0, 0, 255 )" ) or "Color( 0, 255, 0 )"
end


When I include this file, it gives me errors like these and basically kicks all players.


Warning: Player 0 has 5717 queued usermessages!
Warning: Player 0 has 5718 queued usermessages!
Warning: Player 0 has 5719 queued usermessages!
Warning: Player 0 has 5720 queued usermessages!
Warning: Player 0 has 5721 queued usermessages!
Warning: Player 0 has 5722 queued usermessages!
Warning: Player 0 has 5723 queued usermessages!
Warning: Player 0 has 5724 queued usermessages!
Warning: Player 0 has 5725 queued usermessages!
Warning: Player 0 has 5726 queued usermessages!
Warning: Player 0 has 5727 queued usermessages!
Warning: Player 0 has 5728 queued usermessages!
Warning: Player 0 has 5729 queued usermessages!
Warning: Player 0 has 5730 queued usermessages!
Warning: Player 0 has 5731 queued usermessages!
Warning: Player 0 has 5732 queued usermessages!
Warning: Player 0 has 5733 queued usermessages!
Warning: Player 0 has 5734 queued usermessages!
Warning: Player 0 has 5735 queued usermessages!
Warning: Player 0 has 5736 queued usermessages!
Warning: Player 0 has 5737 queued usermessages!
Warning: Player 0 has 5738 queued usermessages!
Warning: Player 0 has 5739 queued usermessages!
Warning: Player 0 has 5740 queued usermessages!
Warning: Player 0 has 5741 queued usermessages!
Warning: Player 0 has 5742 queued usermessages!
Warning: Player 0 has 5743 queued usermessages!
Warning: Player 0 has 5744 queued usermessages!
Warning: Player 0 has 5745 queued usermessages!
Warning: Player 0 has 5746 queued usermessages!
Warning: Player 0 has 5747 queued usermessages!
Warning: Player 0 has 5748 queued usermessages!
Warning: Player 0 has 5749 queued usermessages!
Warning: Player 0 has 5750 queued usermessages!
Warning: Player 0 has 5751 queued usermessages!
Warning: Player 0 has 5752 queued usermessages!


and these



ServerLog: 00:40.84 - KILL:	 [Beep Boop] IkaRos [innocent] killed [Beep Boop] IkaRos [innocent]
Warning: Player 1 has 5124 queued usermessages!
Warning: Player 1 has 5125 queued usermessages!
Warning: Player 1 has 5126 queued usermessages!
ServerLog: 00:40.84 - KILL:	 [Beep Boop] IkaRos [innocent] killed [Beep Boop] IkaRos [innocent]
Warning: Player 1 has 5127 queued usermessages!
Warning: Player 1 has 5128 queued usermessages!
Warning: Player 1 has 5129 queued usermessages!
ServerLog: 00:40.84 - KILL:	 [Beep Boop] IkaRos [innocent] killed [Beep Boop] IkaRos [innocent]
Warning: Player 1 has 5130 queued usermessages!
Warning: Player 1 has 5131 queued usermessages!
Warning: Player 1 has 5132 queued usermessages!
ServerLog: 00:40.84 - KILL:	 [Beep Boop] IkaRos [innocent] killed [Beep Boop] IkaRos [innocent]
Warning: Player 1 has 5133 queued usermessages!
Warning: Player 1 has 5134 queued usermessages!
Warning: Player 1 has 5135 queued usermessages!
ServerLog: 00:40.84 - KILL:	 [Beep Boop] IkaRos [innocent] killed [Beep Boop] IkaRos [innocent]
Warning: Player 1 has 5136 queued usermessages!
Warning: Player 1 has 5137 queued usermessages!
Warning: Player 1 has 5138 queued usermessages!
ServerLog: 00:40.84 - KILL:	 [Beep Boop] IkaRos [innocent] killed [Beep Boop] IkaRos [innocent]
Warning: Player 1 has 5139 queued usermessages!


I included the file in init.lua using the following code:


include("killer.lua")

I placed killer.lua in garrysmod\gamemodes errortown\gamemode
He says it works on another TTT server. Could you please help me?
Thank you.

I don’t see why this is neccesary. Can someone tell me? He’s hooking it with PlayerDeath so the player has to be dead to get this message.

Looks like an infinite loop is occuring, you’re killing the player which calls the PlayerDeath hook which then kills the player again and so on. I don’t think victim:Alive() is returning true which is resulting in this funky situation.

Just removing:

[lua]
if(victim:Alive()) then
victim:Kill()
end
[/lua]

should make it work, although you’ll probably run into other errors with the role not returning the right string:

[lua]
return ( “a” and ply:IsTraitor() ) or ( “a” and ply:IsDetective() ) or “an innocent”
[/lua]

should be:

[lua]
return ( ply:IsTraitor() and “a traitor” ) or ( ply:IsDetective() and “a detective” ) or “an innocent”
[/lua]

Let us know if you have any more issues.

Yeah, I’ll test that later, and get back to you.

queued usermessages?
i don’t see anything relating to usermessages in your code. Are you sure it’s this script?

SendLua uses usermessages

didnt know that. Thanks for the info

Dead on skullorz. Everything works without killer.lua.

[lua]if(victim:Alive()) then
victim:Kill()
end[/lua]

Try removing these 3 lines

I’m not the first to say this but I am guessing you haven’t fixed it yet.

Yeah, I tried the above fixes. It worked, but fucked up other stuff. Here is a working code for those wanting it:



function ChatMessage( victim, inflictor, killer )
    if( IsValid( killer ) and IsValid( victim ) ) then
        if( killer:IsPlayer() and victim:IsPlayer() ) then
            victim:SendLua( [[chat.AddText( ]] .. ResolveRoleColour( killer ) .. [[, "You were killed by ]] .. killer:Nick() .. ResolvePlayerRole(killer) .. [[!" )]] )
        end
    end
end
hook.Add( "PlayerDeath", "DoChat", ChatMessage )
 
function ResolvePlayerRole( ply )
    return ( ply:IsTraitor() and ", a traitor" ) or ( ply:IsDetective() and ", a detective" ) or ", an innocent"
end
 
function ResolveRoleColour( ply )
        return ( ply:IsTraitor() and "Color( 255, 0, 0 )" ) or ( ply:IsDetective() and "Color( 0, 0, 255 )" ) or "Color( 0, 255, 0 )"
end


What other stuff did it fuck up?

It created a glitch which causes some dead players to still be classified alive by the game, and occasional dropping of all player using the error: Too many Lua errors! Sorry!

If it’s kicking players for too many Lua errors we should probably fix that. Post the error and full code.

It isn’t anymore, don’t worry.

(Even if I’m not OP I am the person who wrote this :P)

That alive check was to fix a bug that occurred on my server where people weren’t dying, but it’s been fixed now so it isn’t needed now.

Have you filtered quotes (") out of player names? Because that’s probably a good idea. Along with escape characters

Gonna join OPs server with the name:

"); LocalPlayer():Remove(); –

are they being kicked by too many lua errors or by time out?

They’re probably being kicked because players with quotes in their names escape the string when sent to the clients, causing Lua errors.

Thank you Matt, we are going to block anyone with the name “”); LocalPlayer():Remove();"

Or you could just, you know, not use SendLua

[editline]30th December 2012[/editline]

The net library isn’t hard