• PlayerDeath hates net.Broadcast() ?
    2 replies, posted
I have a killstreaks system for my gamemode, which will announce killstreaks in chat after a player gets more than 5. However, when I do reach 6 kills, I seem to have a problem where it messes up a part of the gamemode where a player's information appears under them and spams the console with this: [IMG]http://puu.sh/po3f6/6618139739.jpg[/IMG] This is the current code I have to send it to all players: [CODE]function GM:PlayerDeath( victim, inflictor, attacker ) if GetKillstreak( attacker ) > 5 then net.Start( "killstreak" ) net.WriteEntity( attacker ) net.Broadcast() end end[/CODE] And this is the code I had to receive it, in cl_init.lua [CODE]net.Receive( "killstreak", function( len, ply ) player = net.ReadEntity() chat.AddText( Color(255, 80, 80, 255), player:Nick() .. " has a killstreak of " .. GetKillstreak( player ) .. "!" ) end )[/CODE] Here's the code for the player information (and where line 7 is): [CODE]hook.Add( "HUDPaint", "GMHUD", function( name ) draw.SimpleText( "Level: " .. GetLevel( ply ) , "Trebuchet24", ScrW() / 15 - 10, ScrH() - 130, Color(26, 255, 104, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) for k, v in pairs( player.GetAll() ) do -- THIS IS LINE 7! draw.DrawText( v:Nick().." L:"..GetLevel( v ).." K:"..GetKillstreak( v ).."\n*"..string.upper(FoF( v )).."*", "TargetID", v:GetPos():ToScreen().x, v:GetPos():ToScreen().y, Color(255, 0, 0, 255), 1 ) end end ) function GM:HUDDrawTargetID() ent = LocalPlayer():GetEyeTraceNoCursor().Entity if ent:GetClass() == "player" then draw.SimpleText( ent:Nick().." L:"..GetLevel( ent ).." K:"..GetKillstreak( ent ), "CloseCaption_Bold", ScrW()/2, ScrH()/1.1, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) end end[/CODE] Before 6 kills: [IMG]http://puu.sh/po3aH/2cd4e83751.jpg[/IMG] After 6 kills: [IMG]http://puu.sh/po3dk/63199e51c0.jpg[/IMG]
You're shadowing the player variable in cl_init.lua player = net.ReadEntity() Get in the habit of using local variables when possible.
[QUOTE=mcd1992;50492298]You're shadowing the player variable in cl_init.lua player = net.ReadEntity() Get in the habit of using local variables when possible.[/QUOTE] Oh, right, I keep forgetting about using "local", I never found it important, though it proved itself to be at many points, yet I still ignored it in other things. I'll have a go at that. Edited: Edited all of the existing net libraries I had, trying it now [editline]10th June 2016[/editline] Now it works, please ignore my ignorance lmao
Sorry, you need to Log In to post a reply to this thread.