• Scoreboard
    8 replies, posted
Hey, i need help with coding a simple scoreboard for my server. I want to make scoreboard with nicks and Avatars for any player. So, i can write Hud scoreboard with names, score etc, but how to Add Avatar? Avatar in VGUI -_- so i don't know how to make VGUI in HUD. Thanks. [editline]05:07PM[/editline] You can help just with adding an avatar in HUD scoreboard... and it will be nice...
With usage of [b][url=http://wiki.garrysmod.com/?title=Player.GetAll]Player.GetAll [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] and a bit of help from [URL="http://wiki.garrysmod.com/?title=Guide_to_Derma"]this[/URL] you're able to make a scoreboard.
I know this all, i don't know how to add Avatar in my Scoreboard, i need part of code with description or example... Read attentively pls =/
Hm.. i will look it.. thx
[lua] self.MyAvatar = vgui.Create( "AvatarImage", self ) // First part before the equal sign is defining what we will call the vgui. [/lua] [lua] self.MyAvatar:SetPlayer( ply ) // We have to set "myAvatar" to the player in that row. [/lua] Let us know if you need more help.
Thanks! [editline]06:49PM[/editline] So, this i understood... but i have new little problem.. How i can make this avatarimage in HUD? Example: if i press TAB button then my table starts to draw if i release TAB button so my table close... How it can be make? (as HUD drawing... draw.SimpleText, draw.RoundedBox etc... and any scoreboard row must have avatar) I'm noob with working with Panels... like this: PANEL = {}, PANEL:Init() etc.... Need simple example of code wich draw simple scoreboard with avatars when i press TAB.... and description if you can =)
Here's an example from my player_row.lua All you have to do is create avatar vgui, define the players avatar, and set the size and position. [lua] surface.CreateFont( "coolvetica", 19, 500, true, false, "ScoreboardPlayerName" ) surface.CreateFont( "coolvetica", 15, 500, true, false, "ScoreboardPlayerName2" ) surface.CreateFont( "coolvetica", 22, 500, true, false, "ScoreboardPlayerNameBig" ) local PANEL = {} function PANEL:Init() self.Size = 36 self.lblName = vgui.Create( "Label", self ) self.lblTeam = vgui.Create( "Label", self ) self.lblFrags = vgui.Create( "Label", self ) self.lblDeaths = vgui.Create( "Label", self ) self.lblPing = vgui.Create( "Label", self ) self.lblSID = vgui.Create( "Label", self ) self.lblName:SetMouseInputEnabled( false ) self.lblTeam:SetMouseInputEnabled( false ) self.lblSID:SetMouseInputEnabled( false ) self.lblFrags:SetMouseInputEnabled( false ) self.lblDeaths:SetMouseInputEnabled( false ) self.lblPing:SetMouseInputEnabled( false ) self.imgAvatar = vgui.Create( "AvatarImage", self ) self:SetCursor( "hand" ) end function PANEL:Paint() if ( !ValidEntity( self.Player ) ) then return end draw.RoundedBox(4, 0, 0, self:GetWide(), 36, team.GetColor(self.Player:Team())) surface.SetTexture( texGradient ) surface.SetDrawColor(255, 255, 255, 255) surface.SetTexture(self.texRating) surface.DrawTexturedRect( self:GetWide() - 16 - 8, 36 / 2 - 8, 16, 16 ) return true end function PANEL:SetPlayer( ply ) self.Player = ply self.imgAvatar:SetPlayer( ply ) self:UpdatePlayerData() end local Clark = { "STEAM_0:0:14700480" } function PANEL:UpdatePlayerData() if ( !self.Player ) then return end if ( !self.Player:IsValid() ) then return end if table.HasValue( Clark, self.Player:SteamID() ) then self.texRating = surface.GetTextureID("gui/silkicons/wrench") elseif self.Player:GetLevel() == 0 then self.texRating = surface.GetTextureID("gui/silkicons/heart") elseif self.Player:GetLevel() == 4 then self.texRating = surface.GetTextureID("gui/silkicons/star") elseif self.Player:IsAdmin() or self.Player:IsSuperAdmin() then self.texRating = surface.GetTextureID("gui/silkicons/shield") else self.texRating = surface.GetTextureID("gui/silkicons/user") end self.lblName:SetText( self.Player:Nick() ) if table.HasValue( Clark, self.Player:SteamID() ) then self.lblTeam:SetText( "Coder" ) else self.lblTeam:SetText( "" ) end self.lblFrags:SetText( self.Player:Frags() ) self.lblDeaths:SetText( self.Player:Deaths() ) self.lblPing:SetText( self.Player:Ping() ) self.lblSID:SetText( self.Player:SteamID() ) end function PANEL:ApplySchemeSettings() self.lblName:SetFont( "ScoreboardPlayerNameBig" ) self.lblTeam:SetFont( "ScoreboardPlayerName2" ) self.lblSID:SetFont( "ScoreboardPlayerNameBig" ) self.lblFrags:SetFont( "ScoreboardPlayerName" ) self.lblDeaths:SetFont( "ScoreboardPlayerName" ) self.lblPing:SetFont( "ScoreboardPlayerName" ) self.lblName:SetFGColor( color_white ) self.lblTeam:SetFGColor( color_white ) self.lblFrags:SetFGColor( color_white ) self.lblDeaths:SetFGColor( color_white ) self.lblPing:SetFGColor( color_white ) self.lblSID:SetFGColor( color_white ) end function PANEL:Think() if ( !self.PlayerUpdate || self.PlayerUpdate < CurTime() ) then self.PlayerUpdate = CurTime() + 0.5 self:UpdatePlayerData() end end function PANEL:PerformLayout() self.imgAvatar:SetPos( 2, 2 ) self.imgAvatar:SetSize( 32, 32 ) self:SetSize( self:GetWide(), self.Size ) self.lblName:SizeToContents() self.lblName:SetPos( 24, 2 ) self.lblName:MoveRightOf( self.imgAvatar, 8 ) local COLUMN_SIZE = 50 self.lblPing:SetPos( self:GetWide() - COLUMN_SIZE * 1, 0 ) self.lblDeaths:SetPos( self:GetWide() - COLUMN_SIZE * 2, 0 ) self.lblFrags:SetPos( self:GetWide() - COLUMN_SIZE * 3, 0 ) self.lblTeam:SetPos( self:GetWide() - COLUMN_SIZE * 9.50, 0 ) self.lblSID:SetPos( self:GetWide() - COLUMN_SIZE * 7.25, 0 ) self.lblSID:SizeToContents() self.lblTeam:SizeToContents() end function PANEL:HigherOrLower( row ) if ( !self.Player:IsValid() || self.Player:Team() == TEAM_SPECTATOR || self.Player:Team() == TEAM_CONNECTING ) then return false end if ( !row.Player:IsValid() || row.Player:Team() == TEAM_SPECTATOR || row.Player:Team() == TEAM_CONNECTING ) then return true end if ( self.Player:Frags() == row.Player:Frags() ) then return self.Player:Deaths() < row.Player:Deaths() end return self.Player:Frags() > row.Player:Frags() end vgui.Register( "ScorePlayerRow", PANEL, "Button" ) [/lua]
Thanks. I will try it...
Sorry, you need to Log In to post a reply to this thread.