Attempt to index local 'player' (A Nil Value) [Help!]
8 replies, posted
So I have made a rounded box that has the player(s) avatar, name, and ping. Now im trying to make it print the player(s) rank. I am using ULX and ULIB, while coding this I have come across an error that I don't really understand.
[CODE]if self.player:IsUserGroup("owner") then
self.rank = self:Add("DLabel")
self.rank:SetFont("ScoreboardTiny")
self.rank:Dock(FILL)
self.rank:DockMargin(5,5,5,5)
self.rank:SizeToContents()
self.rank:SetTextColor( Color(255, 255, 255, 255))
end[/CODE]
I don't understand because I used this coding almost word for word to draw this:
[IMG]http://gyazo.com/fa57ae1469422bc8fc4d5fd2bb71822f.png[/IMG]
Which draws a different color box when a user is a certain group... The colored box coding looks very similar:
[CODE]function PANEL:Paint(w, h)
//draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 225) ) --Individual Player Tags
if self.player:IsUserGroup("owner") then
draw.RoundedBox( 4, 0, 0, w, h, Color(0, 0, 0, 200) )
elseif self.player:IsUserGroup("superadmin") then
draw.RoundedBox( 4, 0, 0, w, h, Color(240, 45, 45, 200) )
elseif self.player:IsUserGroup("admin") then
draw.RoundedBox( 4, 0, 0, w, h, Color(45, 123, 240, 200) )
elseif self.player:IsUserGroup("moderator") then
draw.RoundedBox( 4, 0, 0, w, h, Color(45, 240, 84, 200) )
elseif self.player:IsUserGroup("vip")then
draw.RoundedBox( 4, 0, 0, w, h, Color(240, 201, 45, 200) )
elseif self.player:IsUserGroup("user") then
draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 200) )
end
end[/CODE]
If anyone could help me with this, that would be great!
If you need any further code from this file I will post it!
Don't remember if I included this but this is a scoreboard.
Give the entire error and the entire lua file the code is caused from
[CODE]function PANEL:Init()
self:SetSize(ScrW() * 0.44, ScrH() * 0.78)
self:Center()
self.body = self:Add("DPanel")
self.body:Dock(FILL)
self.body:DockMargin(5, 5, 5, 5)
self.body.Paint = function(body, w, h)
draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 20) )
end
self.header = self.body:Add("DPanel")
self.header:Dock(TOP)
self.header:SetTall(self:GetTall() * 0.15)
self.header:DockMargin(4, 4, 4, 4)
self.footer = self.body:Add("DPanel")
self.footer:Dock(BOTTOM)
self.footer:SetTall(38)
self.footer:DockMargin(4, 4, 4, 4)
self.header.Paint = function(header, w, h)
draw.RoundedBox( 4, 0, 0, w, h, Color(37, 85, 132, 200) )
end
self.header.title = self.header:Add("DLabel")
self.header.title:SetText("SubZero Deathrun")
self.header.title:SetFont("ScoreboardBig")
self.header.title:SetContentAlignment(5)
self.header.title:Dock(FILL)
self.header.hostName = self.header:Add("DLabel")
self.header.hostName:SetText( "A Small Gmod Community" )
self.header.hostName:SetFont("ScoreboardSmall")
self.header.hostName:SetContentAlignment(5)
self.header.hostName:DockMargin(3, 3, 3, 5)
self.header.hostName:Dock(BOTTOM)
self.footer.Paint = function(footer, w, h)
draw.RoundedBox( 4, 0, 0,w ,h, Color(37, 85, 132, 200) )
end
self.footer.spectators = self.footer:Add("DLabel")
self.footer.spectators:SetText( "SPECTATORS :" )
self.footer.spectators:SetFont("ScoreboardSmall")
self.footer.spectators:DockMargin(5, 5, 5, 5)
self.footer.spectators:Dock(FILL)
self.run = self.body:Add("ScoreboardTeam")
self.run:SetWide( (self:GetWide() * 0.5) - 15 )
self.run:DockMargin(5, 5, 5, 5)
self.run:Dock(LEFT)
self.run:SetTeam(TEAM_RUNNER)
self.death = self.body:Add("ScoreboardTeam")
self.death:SetWide( (self:GetWide() * 0.5) - 15 )
self.death:DockMargin(5, 5, 5, 5)
self.death:Dock(RIGHT)
self.death:SetTeam(TEAM_DEATH)
end
function PANEL:Paint(w, h)
draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 100) ) --BackPanel For Scoreboard (Behind Everything)
end
vgui.Register("Scoreboard", PANEL, "DPanel")
local PANEL = {}
function PANEL:Init()
self.title = self:Add("DLabel")
self.title:Dock(TOP)
self.title:DockMargin(5, 5, 5, 5)
self.title:SetFont("ScoreboardMedium")
self.title:SetText("N/A")
self.title:SizeToContents()
self.scroll = self:Add("DScrollPanel")
self.scroll:Dock(FILL)
self.scroll:DockMargin(5, 5, 5, 5)
self.scroll.Paint = function(scroll, w, h)
draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 200) ) ---Behind Individual Player Tags
end
end
function PANEL:SetTeam(index)
self.team = index
self.title:SetTextColor( team.GetColor(index) )
end
function PANEL:Think()
if (self.team) then
local players = team.NumPlayers(self.team)
local name = team.GetName(self.team)
if (players == 1) then
suffix = " Player"
end
self.title:SetText(name)
if self.team == TEAM_RUNNER then
self.title:SetText("RUNNERS")
self.title:SetTextColor( Color(255, 255, 255, 255) )
self.title:SetContentAlignment(5)
elseif self.team == TEAM_DEATH then
self.title:SetText("DEATH")
self.title:SetTextColor( Color(255, 255, 255, 255) )
self.title:SetContentAlignment(5)
end
for k, v in SortedPairs( player.GetAll() ) do
if (!IsValid(v.ts_Row) and v:Team() == self.team) then
local row = self.scroll:Add("ScoreboardPlayer")
row:Dock(TOP)
row:DockMargin(3, 3, 3, 0)
row:SetPlayer(v)
v.ts_Row = row
self.scroll:AddItem(row)
end
end
end
end
function PANEL:Paint(w, h)
draw.RoundedBox( 2, 0, 0, w, h, Color(37, 85, 132, 200) )
end
vgui.Register("ScoreboardTeam", PANEL, "DPanel")
local PANEL = {}
function PANEL:Init()
self:SetTall(36)
if self.player:IsUserGroup("owner") then
self.rank = self:Add("DLabel")
self.rank:SetFont("ScoreboardTiny")
self.rank:Dock(FILL)
self.rank:DockMargin(5,5,5,5)
self.rank:SizeToContents()
self.rank:SetTextColor( Color(255, 255, 255, 255))
end
self.avatar = self:Add("AvatarImage")
self.avatar:Dock(LEFT)
self.avatar:DockMargin(3, 3, 3, 3)
self.avatar:SetSize(32, 32)
self.avatar.click = self.avatar:Add("DButton")
self.avatar.click:Dock(FILL)
self.avatar.click:SetText("")
self.avatar.click.Paint = function() end
self.avatar.click.DoClick = function(avatarButton)
local menu = DermaMenu()
menu:AddOption("View Profile", function()
if ( IsValid(self.player) ) then
self.player:ShowProfile()
end
end)
local text = "Mute"
if (self.player.ts_Muted) then
text = "Unmute"
end
menu:AddOption(text, function()
if ( IsValid(self.player) ) then
self.player.ts_Muted = !self.player.ts_Muted
self.player:SetMuted(self.player.ts_Muted)
end
end)
menu:Open()
end
self.name = self:Add("DLabel")
self.name:SetFont("ScoreboardSmall")
self.name:SetText("N/A")
self.name:Dock(LEFT)
self.name:DockMargin(5, 5, 5, 5)
self.name:SizeToContents()
self.name:SetTextColor( Color(255, 255, 255, 255) )
self.ping = self:Add("DLabel")
self.ping:SetFont("ScoreboardMedium")
self.ping:SetText("")
self.ping:DockMargin(5, 5, 5, 5)
self.ping:Dock(RIGHT)
self.ping:SizeToContents()
end
function PANEL:SetPlayer(client)
if ( IsValid(client) ) then
self.player = client
self.team = client:Team()
self.avatar:SetPlayer(client)
self.initialized = true
end
end
function PANEL:Think()
if ( self.initialized and !IsValid(self.player) ) then
self:Remove()
elseif (self.initialized) then
if ( self.team != self.player:Team() ) then
self:Remove()
end
local amount = math.Clamp(self.player:Ping() / 200, 0, 1)
self.ping:SetTextColor( Color( (255 * amount), 255 - (255 * amount), (1 - amount) * 75, 200) )
self.ping:SetText( self.player:Ping() )
self.ping:SizeToContents()
if ( self.player:Name() != self.name:GetText() ) then
self.name:SetText( self.player:Name() )
self.name:SizeToContents()
end
end
end
function PANEL:Paint(w, h)
//draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 225) ) --Individual Player Tags
if self.player:IsUserGroup("owner") then
draw.RoundedBox( 4, 0, 0, w, h, Color(0, 0, 0, 200) )
elseif self.player:IsUserGroup("superadmin") then
draw.RoundedBox( 4, 0, 0, w, h, Color(240, 45, 45, 200) )
elseif self.player:IsUserGroup("admin") then
draw.RoundedBox( 4, 0, 0, w, h, Color(45, 123, 240, 200) )
elseif self.player:IsUserGroup("moderator") then
draw.RoundedBox( 4, 0, 0, w, h, Color(45, 240, 84, 200) )
elseif self.player:IsUserGroup("vip")then
draw.RoundedBox( 4, 0, 0, w, h, Color(240, 201, 45, 200) )
elseif self.player:IsUserGroup("user") then
draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 200) )
end
end[/CODE]
[IMG]http://gyazo.com/09a0918d2cfbe68ebc214308726088c7.png[/IMG]
Either thats the wrong file or not the entirety of the code.
[QUOTE=KarmaLord;41137775]Either thats the wrong file or not the entirety of the code.[/QUOTE]
You don't need the entire code the rest is just scoreboard properties. I just need to know why its saying 'player' responding nil value
[QUOTE=Richtofen;41137780]You don't need the entire code the rest is just scoreboard properties. I just need to know why its saying 'player' responding nil value[/QUOTE]
I actually do so that the line numbers are proper. Otherwise:
[IMG]http://puu.sh/3ltX7.png[/IMG]
[QUOTE=KarmaLord;41137786]I actually do so that the line numbers are proper. Otherwise:
[IMG]http://puu.sh/3ltX7.png[/IMG][/QUOTE]
[CODE]
local PANEL = {}
surface.CreateFont("ScoreboardBig", {
size = ScreenScale(25),
weight = 800,
antialias = true,
font = "Harabara",
outline = true
} )
surface.CreateFont("ScoreboardMedium", {
size = ScreenScale(12),
weight = 600,
antialias = true,
font = "Harabara",
outline = true
} )
surface.CreateFont("ScoreboardSmall", {
size = ScreenScale(10),
weight = 600,
antialias = false,
font = "Harabara",
outline = true
} )
surface.CreateFont("ScoreboardTiny", {
size = ScreenScale(8),
weight = 200,
antialias = true,
font = "Harabara",
} )
function PANEL:Init()
self:SetSize(ScrW() * 0.44, ScrH() * 0.78)
self:Center()
self.body = self:Add("DPanel")
self.body:Dock(FILL)
self.body:DockMargin(5, 5, 5, 5)
self.body.Paint = function(body, w, h)
draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 20) )
end
self.header = self.body:Add("DPanel")
self.header:Dock(TOP)
self.header:SetTall(self:GetTall() * 0.15)
self.header:DockMargin(4, 4, 4, 4)
self.footer = self.body:Add("DPanel")
self.footer:Dock(BOTTOM)
self.footer:SetTall(38)
self.footer:DockMargin(4, 4, 4, 4)
self.header.Paint = function(header, w, h)
draw.RoundedBox( 4, 0, 0, w, h, Color(37, 85, 132, 200) )
end
self.header.title = self.header:Add("DLabel")
self.header.title:SetText("SubZero Deathrun")
self.header.title:SetFont("ScoreboardBig")
self.header.title:SetContentAlignment(5)
self.header.title:Dock(FILL)
self.header.hostName = self.header:Add("DLabel")
self.header.hostName:SetText( "A Small Gmod Community" )
self.header.hostName:SetFont("ScoreboardSmall")
self.header.hostName:SetContentAlignment(5)
self.header.hostName:DockMargin(3, 3, 3, 5)
self.header.hostName:Dock(BOTTOM)
self.footer.Paint = function(footer, w, h)
draw.RoundedBox( 4, 0, 0,w ,h, Color(37, 85, 132, 200) )
end
self.footer.spectators = self.footer:Add("DLabel")
self.footer.spectators:SetText( "SPECTATORS :" )
self.footer.spectators:SetFont("ScoreboardSmall")
self.footer.spectators:DockMargin(5, 5, 5, 5)
self.footer.spectators:Dock(FILL)
self.run = self.body:Add("ScoreboardTeam")
self.run:SetWide( (self:GetWide() * 0.5) - 15 )
self.run:DockMargin(5, 5, 5, 5)
self.run:Dock(LEFT)
self.run:SetTeam(TEAM_RUNNER)
self.death = self.body:Add("ScoreboardTeam")
self.death:SetWide( (self:GetWide() * 0.5) - 15 )
self.death:DockMargin(5, 5, 5, 5)
self.death:Dock(RIGHT)
self.death:SetTeam(TEAM_DEATH)
end
function PANEL:Paint(w, h)
draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 100) ) --BackPanel For Scoreboard (Behind Everything)
end
vgui.Register("Scoreboard", PANEL, "DPanel")
local PANEL = {}
function PANEL:Init()
self.title = self:Add("DLabel")
self.title:Dock(TOP)
self.title:DockMargin(5, 5, 5, 5)
self.title:SetFont("ScoreboardMedium")
self.title:SetText("N/A")
self.title:SizeToContents()
self.scroll = self:Add("DScrollPanel")
self.scroll:Dock(FILL)
self.scroll:DockMargin(5, 5, 5, 5)
self.scroll.Paint = function(scroll, w, h)
draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 200) ) ---Behind Individual Player Tags
end
end
function PANEL:SetTeam(index)
self.team = index
self.title:SetTextColor( team.GetColor(index) )
end
function PANEL:Think()
if (self.team) then
local players = team.NumPlayers(self.team)
local name = team.GetName(self.team)
if (players == 1) then
suffix = " Player"
end
self.title:SetText(name)
if self.team == TEAM_RUNNER then
self.title:SetText("RUNNERS")
self.title:SetTextColor( Color(255, 255, 255, 255) )
self.title:SetContentAlignment(5)
elseif self.team == TEAM_DEATH then
self.title:SetText("DEATH")
self.title:SetTextColor( Color(255, 255, 255, 255) )
self.title:SetContentAlignment(5)
end
for k, v in SortedPairs( player.GetAll() ) do
if (!IsValid(v.ts_Row) and v:Team() == self.team) then
local row = self.scroll:Add("ScoreboardPlayer")
row:Dock(TOP)
row:DockMargin(3, 3, 3, 0)
row:SetPlayer(v)
v.ts_Row = row
self.scroll:AddItem(row)
end
end
end
end
function PANEL:Paint(w, h)
draw.RoundedBox( 2, 0, 0, w, h, Color(37, 85, 132, 200) )
end
vgui.Register("ScoreboardTeam", PANEL, "DPanel")
local PANEL = {}
function PANEL:Init()
self:SetTall(36)
/*if self.player:IsUserGroup("owner") then
self.rank = self:Add("DLabel")
self.rank:SetFont("ScoreboardTiny")
self.rank:Dock(FILL)
self.rank:DockMargin(5,5,5,5)
self.rank:SizeToContents()
self.rank:SetTextColor( Color(255, 255, 255, 255))
end
*/
self.avatar = self:Add("AvatarImage")
self.avatar:Dock(LEFT)
self.avatar:DockMargin(3, 3, 3, 3)
self.avatar:SetSize(32, 32)
self.avatar.click = self.avatar:Add("DButton")
self.avatar.click:Dock(FILL)
self.avatar.click:SetText("")
self.avatar.click.Paint = function() end
self.avatar.click.DoClick = function(avatarButton)
local menu = DermaMenu()
menu:AddOption("View Profile", function()
if ( IsValid(self.player) ) then
self.player:ShowProfile()
end
end)
local text = "Mute"
if (self.player.ts_Muted) then
text = "Unmute"
end
menu:AddOption(text, function()
if ( IsValid(self.player) ) then
self.player.ts_Muted = !self.player.ts_Muted
self.player:SetMuted(self.player.ts_Muted)
end
end)
menu:Open()
end
self.name = self:Add("DLabel")
self.name:SetFont("ScoreboardSmall")
self.name:SetText("N/A")
self.name:Dock(LEFT)
self.name:DockMargin(5, 5, 5, 5)
self.name:SizeToContents()
self.name:SetTextColor( Color(255, 255, 255, 255) )
self.ping = self:Add("DLabel")
self.ping:SetFont("ScoreboardMedium")
self.ping:SetText("")
self.ping:DockMargin(5, 5, 5, 5)
self.ping:Dock(RIGHT)
self.ping:SizeToContents()
end
function PANEL:SetPlayer(client)
if ( IsValid(client) ) then
self.player = client
self.team = client:Team()
self.avatar:SetPlayer(client)
self.initialized = true
end
end
function PANEL:Think()
if ( self.initialized and !IsValid(self.player) ) then
self:Remove()
elseif (self.initialized) then
if ( self.team != self.player:Team() ) then
self:Remove()
end
local amount = math.Clamp(self.player:Ping() / 200, 0, 1)
self.ping:SetTextColor( Color( (255 * amount), 220 - (255 * amount), (1 - amount) * 75, 200) )
self.ping:SetText( self.player:Ping() )
self.ping:SizeToContents()
if ( self.player:Name() != self.name:GetText() ) then
self.name:SetText( self.player:Name() )
self.name:SizeToContents()
end
end
end
function PANEL:Paint(w, h)
//draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 225) ) --Individual Player Tags
if self.player:IsUserGroup("owner") then
draw.RoundedBox( 4, 0, 0, w, h, Color(0, 0, 0, 200) )
elseif self.player:IsUserGroup("superadmin") then
draw.RoundedBox( 4, 0, 0, w, h, Color(240, 45, 45, 200) )
elseif self.player:IsUserGroup("admin") then
draw.RoundedBox( 4, 0, 0, w, h, Color(45, 123, 240, 200) )
elseif self.player:IsUserGroup("moderator") then
draw.RoundedBox( 4, 0, 0, w, h, Color(45, 240, 84, 200) )
elseif self.player:IsUserGroup("vip")then
draw.RoundedBox( 4, 0, 0, w, h, Color(240, 201, 45, 200) )
elseif self.player:IsUserGroup("user") then
draw.RoundedBox( 4, 0, 0, w, h, Color(255, 255, 255, 200) )
end
end
vgui.Register("ScoreboardPlayer", PANEL, "DPanel")
local SCOREBOARD
function GM:ScoreboardShow()
gui.EnableScreenClicker(true)
SCOREBOARD = vgui.Create("Scoreboard")
end
function GM:ScoreboardHide()
gui.EnableScreenClicker(false)
if not SCOREBOARD then return end
SCOREBOARD:Remove()
end
[/CODE]
Is it me or is that code littered with stuff that looks like it shouldnt be there?
Ex:
[code]self.title:SetFont(="keyword operator">="string">"ScoreboardMedium")[/code]
="keyword operator">="string">
[QUOTE=KarmaLord;41137827]Is it me or is that code littered with stuff that looks like it shouldnt be there?
Ex:
[code]self.title:SetFont(="keyword operator">="string">"ScoreboardMedium")[/code]
="keyword operator">="string">[/QUOTE]
I think facepunch is changing something, because I don't have that in my file... either that or it copied weird.
Here is a[URL="http://pastebin.com/cVnsNv7h"] pastebin[/URL]
Sorry, you need to Log In to post a reply to this thread.