so I am making a hud in which your health bar is the color of your team, and you set your team with a menu that pops up as soon as you join the game. What the hud is doing is it is saying there is no team to call from as soon as you join (understandable, so i set it to automatically place you on a 3rd team, and AFK/ not set team), but even after you set the team, it spits out the error unless i resave my hud file. is there anyway around this?
Show code.
Show the error, too.
[lua]
function GM:HUDPaint()
if teamChosen == 1 then
col = Color( 0, 255, 0, 255 )
if ply:Team() == 1 then -- this is line 25 (from the error)
col = Color( 255, 0, 0, 255 )
elseif ply:Team() == 2 then
col = Color( 0, 0, 255, 255 )
end
draw.RoundedBox( 8, ScrW()/2 - 255, ScrH() - 80, 510, 60, Color( 65, 65, 65, 125 ) )
draw.RoundedBox( 8, ScrW()/2 - ply:Health()*2.5, ScrH() - 75, ply:Health()*5, 50, col )
end
end
[/lua]
teamChosen is set to 1 after the person chooses a team from a menu that pops up on join (thought it would fix the error, it didn't)
error -
[lua]
[ERROR] gamemodes/dogfight/gamemode/cl_hud.lua:25: attempt to call method 'Team' (a nil value)
1. unknown - gamemodes/dogfight/gamemode/cl_hud.lua:25
[/lua]
[editline]lol[/editline]
after I resave cl_hud.lua, it somehow fixes itself, but I have to do this every time I start the game
You don't have ply defined anywhere, so you'll have to use LocalPlayer().
[code]function GM:HUDPaint()
if teamChosen == 1 then
col = Color( 0, 255, 0, 255 )
if LocalPlayer():Team() == 1 then -- this is line 25 (from the error)
col = Color( 255, 0, 0, 255 )
elseif LocalPlayer():Team() == 2 then
col = Color( 0, 0, 255, 255 )
end
draw.RoundedBox( 8, ScrW()/2 - 255, ScrH() - 80, 510, 60, Color( 65, 65, 65, 125 ) )
draw.RoundedBox( 8, ScrW()/2 - LocalPlayer():Health()*2.5, ScrH() - 75, LocalPlayer():Health()*5, 50, col )
end
end[/code]
[QUOTE=wakeboarderCWB;41654276]You don't have ply defined anywhere, so you'll have to use LocalPlayer().
[code]function GM:HUDPaint()
if teamChosen == 1 then
col = Color( 0, 255, 0, 255 )
if LocalPlayer():Team() == 1 then -- this is line 25 (from the error)
col = Color( 255, 0, 0, 255 )
elseif LocalPlayer():Team() == 2 then
col = Color( 0, 0, 255, 255 )
end
draw.RoundedBox( 8, ScrW()/2 - 255, ScrH() - 80, 510, 60, Color( 65, 65, 65, 125 ) )
draw.RoundedBox( 8, ScrW()/2 - LocalPlayer():Health()*2.5, ScrH() - 75, LocalPlayer():Health()*5, 50, col )
end
end[/code][/QUOTE]
I had it defined above the code, after the function to erase the default HUD, and the problem fixes if i resave the file, until I start up the gamemode again.
[editline]30th July 2013[/editline]
ok, so even after I defined ply to LocalPlayer(), I decided to try LocalPlayer(). It worked. but, because I don't want to open a new thread, GM:ShowSpare2 does not seem to be registering as a gamemode hook, and F4 is not working when I use it, what is it?
You know, the way you have it done works, but it can be done a lot shorter:
[lua]local col = team.GetColor( LocalPlayer():Team() )[/lua]
[QUOTE=MrGregsWorld;41656232]You know, the way you have it done works, but it can be done a lot shorter:
[lua]local col = team.GetColor( LocalPlayer():Team() )[/lua][/QUOTE]
I was just throwing team.GetColor( ply:Team() ) in the color section of draw.RoundedBox, and automatically assigning people to an AFK/un specified team on join, which had the color green, but ditched it as I was still getting the error I was having earlier
Sorry, you need to Log In to post a reply to this thread.