Help with Frags!

So I want to display the player with the most kills. But I get an error and it doesn’t work. All of this code is client side. If you know hwo to make it better or show me a better method. Then please enlighten me! :slight_smile:




local imagessplat = Material("Endgame.png")
 local mostkills = -1 local winrar for k,v in pairs(player.GetAll()) do if v:Frags() > mostkills then mostkills = v:Frags() winrar = v --End round for most kills calculation.
	end 
	end

function GM:DrawEndHUD()

	
 
surface.SetMaterial(imagessplat)
surface.SetDrawColor(225, 225, 225,220 )
       surface.DrawTexturedRect(0, ScrH()-1080, 1920, 1100 )

	
	draw.DrawText( "The round winner is", "MyFont2", ScrW() * 0.42, ScrH() * 0.5, Color( 144,200,149,255 ), TEXT_ALIGN_CENTER ) --End round scoring for most kills.
	draw.DrawText( "kills!", "MyFont2", ScrW() * 0.65, ScrH() * 0.5, Color( 144,200,149,255 ), TEXT_ALIGN_CENTER )
	draw.SimpleText( winrar:GetName(),"MyFont2", ScrW() * 0.56, ScrH() * 0.5, Color( 144,200,149,255), TEXT_ALIGN_CENTER )
	draw.SimpleText( mostkills, "MyFont2", ScrW() * 0.63, ScrH() * 0.5, Color( 144,200,149,255 ), TEXT_ALIGN_CENTER )
	
	
	
	
	
	
	
end 



Many thanks.

Duby

Please use the code tags when posting code, or else it’s a bitch to read.
Also posting the error would be helpful.

The error is the following.

Duby|2|STEAM_0:0:59565612

[ERROR] gamemodes/slayer/gamemode/cl_init.lua:51: attempt to index upvalue ‘winrar’ (a nil value)

  1. DrawEndHUD - gamemodes/slayer/gamemode/cl_init.lua:51
  2. unknown - gamemodes/slayer/gamemode/cl_init.lua:75

Also sorry what is the tags for code again?

[c0de] code goes here [/c0de]
Except replace c0de with code.

Post what’s on line 51.

Line 51 is this line of code.



draw.SimpleText( winrar:GetName(),"MyFont2", ScrW() * 0.56, ScrH() * 0.5, Color( 144,200,149,255), TEXT_ALIGN_CENTER )


A little tip, you can draw all your text in a single line:


draw.SimpleText( "The winner of the round is"..winner:Nick().." with "..winner:Frags().." kills!", "MyFont2", ScrW()*4.2, ScrH()*0.5, Color( 144,200,149,255 ), TEXT_ALIGN_CENTER )

[editline]27th February 2014[/editline]

Didn’t actually answer your problem. Perhaps the function is being called when “winrar” is still nil? Do a print before your drawing or encase the drawing with “if winrar … end”.

I am sorry but can you explain in a little more detail with what you are trying to say? :o

Put this code:


local imagessplat = Material("Endgame.png")
 local mostkills = -1
local winrar
for k,v in pairs(player.GetAll()) do if v:Frags() > mostkills then
	mostkills = v:Frags()
	winrar = v --End round for most kills calculation.
end 


Inside your drawing hook.

snip