I am in the process of creating a HUD for a server I am building with a couple friends. Unfortunately I am having a problem.
After working on the HUD in either Singleplayer or on my Test Server, After I Lua refresh a bunch of times, my Gmod crashes to desktop with no error logs. I suspect its because every time I LUA refresh it will draw another version of my HUD and eventually there are several variations of my HUD on the screen, but to me it only appears as if there is one drawn.
I believe I need a script that will prevent the HUD from drawing multiple times, it would be appreciated if you guys can help
Post some code so we know what is happening.
Common problems:
1) vgui.Create must NOT be in HUDPaint hook. Should only be called once or its going to create 60 new panels pr second.
2) surface.CreateFont must NOT be in a render hook. Should only be done once.
AddCSLuaFile("apollo_core.lua")
include("apollo_core.lua")
local hideHUDElements = {
-- if you DarkRP_HUD this to true, ALL of DarkRP's HUD will be disabled. That is the health bar and stuff,
-- but also the agenda, the voice chat icons, lockdown text, player arrested text and the names above players' heads
["DarkRP_HUD"] = true,
-- DarkRP_EntityDisplay is the text that is drawn above a player when you look at them.
-- This also draws the information on doors and vehicles
["DarkRP_EntityDisplay"] = true,
-- DarkRP_ZombieInfo draws information about zombies for admins who use /showzombie.
["DarkRP_ZombieInfo"] = false,
-- This is the one you're most likely to replace first
-- DarkRP_LocalPlayerHUD is the default HUD you see on the bottom left of the screen
-- It shows your health, job, salary and wallet, but NOT hunger (if you have hungermod enabled)
["DarkRP_LocalPlayerHUD"] = true,
-- If you have hungermod enabled, you will see a hunger bar in the DarkRP_LocalPlayerHUD
-- This does not get disabled with DarkRP_LocalPlayerHUD so you will need to disable DarkRP_Hungermod too
["DarkRP_Hungermod"] = true,
-- Drawing the DarkRP agenda
["DarkRP_Agenda"] = true,
-- Lockdown info on the HUD
["DarkRP_LockdownHUD"] = true,
-- Arrested HUD
["DarkRP_ArrestedHUD"] = true,
["CHudHealth"] = true,
["CHudAmmo"] = true,
["CHudSecondaryAmmo"] = true,
}
local function Base()
surface.CreateFont( "Apollo",
{
font = "Roboto-Light",
size = 16,
weight = 800,
})
surface.CreateFont( "ApolloSmall",
{
font = "Roboto-Light",
size = 14,
weight = 800,
})
surface.CreateFont( "ApolloLarge",
{
font = "Roboto-Light",
size = 17,
weight = 800,
})
-- Declaring Variables
local DrawHealth = LocalPlayer():Health() or 0
local TextHealth = LocalPlayer():Health() or 0
local DrawArmor = LocalPlayer():Armor() or 0
local TextArmor = LocalPlayer():Armor() or 0
local plywallet = LocalPlayer():getDarkRPVar("money") or "Error"
local plysalary = LocalPlayer():getDarkRPVar("salary") or "Error"
local plyjob = LocalPlayer():getDarkRPVar("job") or "Error"
-- If statements to fix the HP/Armor bars becoming too large.
if DrawHealth > 100 then DrawHealth = 100 end
if DrawHealth < 0 then DrawHealth = 0 end
if DrawArmor > 100 then DrawArmor = 100 end
if DrawArmor < 0 then DrawArmor = 0 end
-- Drawing HUD
surface.SetFont("Apollo")
surface.SetTextColor(255, 255, 255, 255)
surface.SetDrawColor(25, 25, 25, 255)
surface.DrawRect(0, 0, ScrW() - 0, ScrH() / 30)
surface.SetTextPos(5, 7)
surface.DrawText(plyjob)
surface.SetDrawColor(255, 255, 255, 255)
surface.DrawOutlinedRect(0, 0, ScrW() - 1, ScrH() / 30)
surface.SetTextPos(100, 7)
surface.DrawText(DrawHealth .. "%")
surface.DrawOutlinedRect(0, 50, ScrW() / 2, ScrH() / 150)
end
hook.Add("HUDPaint", "ApolloHUD", Base)
There you go There is more but its just the basic DarkRP HUD elements below the hook.
You're calling surface.CreateFont 60 times pr seconds. Gmod only supports 120 fonts or so.
You should only call this once.
Thanks! Ill let you know if it crashes, it tends to happen after about 5 minutes of messing around lol
Sorry, you need to Log In to post a reply to this thread.