Add your own Addon! - Henotu/TTT2-Statistics GitHub Wiki
Adding your own addition
If you want to add your own statistics in the Addon, you can do this by using a structure like the following example.
Make sure to check out the other pages to find out more about the available hooks and functions.
--Make sure you localise your GUI elements
local MyExampleLabel
local MyExamplePicture
local MyExampleButton
local Counter = 0
hook.Add("StatisticsDrawGui", "unique_Identifier", function(panel)
--Add your own GUI elements here
MyExampleLabel = vgui.Create("DLabel", panel)
MyExampleLabel:SetPos(0,0)
MyExampleLabel:SetSize(0.5 * panel:GetWide(), 0.5 * panel:GetTall())
MyExamplePicture = vgui.Create("DImage", panel)
MyExamplePicture:SetPos(0.5 * panel:GetWide(), 0.5 * panel:GetTall())
MyExamplePicture:SetSize(0.5 * panel:GetWide(), 0.5 * panel:GetTall())
MyExampleButton = vgui.Create("DButton", panel)
MyExampleButton:SetPos(0.5 * panel:GetWide(), 0)
MyExampleButton:SetSize(0.5 * panel:GetWide(), 0.5 * panel:GetTall())
MyExampleButton:SetText("Click!")
MyExampleButton.DoClick = function()
Counter = Counter + 1
ExampleFunction(true)
end
end)
--[[
Place for your own code
]]
function ExampleFunction(visible)
--[[It is necessary that you set every GUI-elements visibilty as the argument given by the function,
otherwise it won't show/hide]]
MyExampleLabel:SetVisible(visible)
MyExamplePicture:SetVisible(visible)
MyExampleButton:SetVisible(visible)
--Do whatever you want from here on
MyExampleLabel:SetText("You clicked the following button ".. Counter .." times")
MyExampleLabel:SetFont("StatisticsHudHint") -- There are custom fonts provided by the addon (more about that in the Wiki)
MyExampleLabel:SetTextColor(Color(255,255,255))
MyExamplePicture:SetImage("MyPicture")
end
hook.Add("TTT2FinishedLoading", "unique_Identifier", function()
AddYourStatisticsAddon("Example", ExampleFunction)
end)
Output
Empty Code
--Make sure you localise your GUI elements
hook.Add("StatisticsDrawGui", "unique_Identifier", function(panel)
--Add your own GUI elements here
end)
--[[
Place for your own code
]]
function GlobalFunction(visible)
-- It is necessary that you set every GUI-element as the argument given by the function, otherwise it won't show/hide
end
hook.Add("TTT2FinishedLoading", "unique_Identifier", function()
AddYourStatisticsAddon("ButtonName", GlobalFunction, EntryTable)
end)