Revision Difference
Basic_scoreboard_creation#513974
<cat>Dev.UI</cat>⤶
# About ⤶
This tutorial will explain the basics of creating a custom scoreboard in Garry's Mod.⤶
⤶
I will only show how to start it. Customize it to your liking based off of what you learn here. You will require some knowledge of GMod LUA and Client/Server side differences.⤶
⤶
Creating a scoreboard is simpler than one would think.⤶
⤶
# Getting started ⤶
To start, create a client lua file to overwrite the default scoreboard. Then you will want to create the hooks to do so.⤶
⤶
## Required hooks ⤶
You should only need 2 hooks for the scoreboard:⤶
* <page>GM:ScoreboardShow</page>⤶
* <page>GM:ScoreboardHide</page>⤶
ScoreboardShow and ScoreboardHide will Show and Hide the scoreboard, respectively.⤶
⤶
## Basic template ⤶
We'll use an template, that Niandra and others use, to show the information on the scoreboard, you are expected to know how to set up the information on this page.⤶
⤶
```⤶
scoreboard = scoreboard or {}⤶
function scoreboard:show()⤶
--Create the scoreboard here, with an base like DPanel, you can use an DListView for the rows.⤶
⤶
function scoreboard:hide()⤶
-- This is where you hide the scoreboard, such as with Base:Remove()⤶
end⤶
end⤶
⤶
function GM:ScoreboardShow()⤶
scoreboard:show()⤶
end⤶
⤶
function GM:ScoreboardHide()⤶
scoreboard:hide()⤶
end⤶
```⤶
⤶
The code is self explanatory, it sets up the basic functions, and it calls the Hide & Show functions, the comments also show how to make a scoreboard, like using the <page>DListView</page> for creating the rows etc, and a <page>DPanel</page> for the base.⤶
⤶
# Misc ⤶
If you use the DListView, and want to paint it, there are multiple ways. For example, I used this for the headers & rows:⤶
⤶
```⤶
--<page> Line painting </page>--⤶
for _, v in pairs (player.GetAll()) do⤶
local line = playerlist:AddLine(v:Name(), v:Frags(), v:Deaths(), v:Ping())⤶
function line:Paint(w, h)⤶
--Paint the LINEs here⤶
end⤶
end⤶
⤶
--<page> Column header painting </page>--⤶
for _, v in pairs(playerlist.Columns) do⤶
function v.Header:Paint(w, h)⤶
-- Paint the HEADERs here⤶
end⤶
v.Header:SetTextColor(Color(255, 255, 255, 0)) -- Set its text alpha with this in case you paint the text manually⤶
end⤶
```⤶
⤶
⤶
⤶
⤶