I posted my hud on the workshop [Only I can see it] I enable it and go into DarkRP single player and I am left with the default Sandbox HUD
The code if you need it :)
[code]
surface.CreateFont( "playerinfo", {
font = "Arial",
size = 26,
weight = 1000,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
surface.CreateFont( "hpfont", {
font = "Arial",
size = 16,
weight = 1000,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
surface.CreateFont( "arfont", {
font = "Arial",
size = 14,
weight = 2000,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
local function Base()
local DisplayJob = LocalPlayer():getDarkRPVar( "job" ) or "Citizen"
local DisplayName = LocalPlayer():Nick() or LocalPlayer():Nick()
local ourMat = Material( "vgui/saber.png")
local blue = Material( "vgui/blue.png")
local red = Material( "vgui/red.png")
local health = LocalPlayer():Health() or 0
local armor = LocalPlayer():Armor() or 0
if health > 100 then health = 100 end
if health < 0 then health = 0 end
if health != 0 then
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( red )
surface.DrawTexturedRect( ScrW() / 10.5, ScrH () / 1.269, health * 3.005, 47)
end
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( ourMat )
surface.DrawTexturedRect( ScrW() / 100, ScrH () / 1.246, 140, 30)
draw.RoundedBox(8, ScrW() / 38.8, ScrH () / 1.24, 60, 30, Color(0, 0, 0, 255))
if armor > 100 then armor = 100 end
if armor < 0 then armor = 0 end
if armor != 0 then
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( blue )
surface.DrawTexturedRect( ScrW() / 10.5, ScrH () / 1.133, armor * 3, 29)
end
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( ourMat )
surface.DrawTexturedRect( ScrW() / 100, ScrH () / 1.128, 140, 30)
draw.RoundedBox(8, ScrW() / 38.8, ScrH () / 1.124, 60, 30, Color(0, 0, 0, 255)) -- Thanks Dancore for telling me how to make the HUD the same size for all monitors <3
draw.RoundedBox(8, ScrW() / 70, ScrH () / 95, 300, 60, Color(54, 54, 54, 170))
draw.SimpleText(health.." HP","hpfont",ScrW() / 32,ScrH() / 1.226,Color(255,255,255,255))
draw.SimpleText(armor.." %","hpfont",ScrW() / 28,ScrH() / 1.11,Color(255,255,255,255))
draw.SimpleText( "Name: "..DisplayName, "playerinfo", ScrW() / 60, ScrH() / 95, Color(255,255,255,150))
draw.SimpleText("Role: "..DisplayJob, "playerinfo", ScrW() / 60, ScrH() / 16, Color(255,255,255,150))
end
/*---------------------------------------------------------------------------
HUD ConVars
---------------------------------------------------------------------------*/
local ConVars = {}
local HUDWidth
local HUDHeight
local Color = Color
local cvars = cvars
local DarkRP = DarkRP
local CurTime = CurTime
local draw = draw
local GetConVar = GetConVar
local IsValid = IsValid
local Lerp = Lerp
local localplayer
local math = math
local pairs = pairs
local ScrW, ScrH = ScrW, ScrH
local SortedPairs = SortedPairs
local string = string
local surface = surface
local table = table
local timer = timer
local tostring = tostring
CreateClientConVar("weaponhud", 0, true, false)
local colors = {}
colors.black = Color(0, 0, 0, 255)
colors.blue = Color(0, 0, 255, 255)
colors.brightred = Color(200, 30, 30, 255)
colors.darkred = Color(0, 0, 70, 100)
colors.darkblack = Color(0, 0, 0, 200)
colors.gray1 = Color(0, 0, 0, 155)
colors.gray2 = Color(51, 58, 51,100)
colors.red = Color(255, 0, 0, 255)
colors.white = Color(255, 255, 255, 255)
colors.white1 = Color(255, 255, 255, 200)
local function ReloadConVars()
ConVars = {
background = {0,0,0,100},
Healthbackground = {0,0,0,200},
Healthforeground = {140,0,0,180},
HealthText = {255,255,255,200},
Job1 = {0,0,150,200},
Job2 = {0,0,0,255},
salary1 = {0,150,0,200},
salary2 = {0,0,0,255}
}
for name, Colour in pairs(ConVars) do
ConVars[name] = {}
for num, rgb in SortedPairs(Colour) do
local CVar = GetConVar(name..num) or CreateClientConVar(name..num, rgb, true, false)
table.insert(ConVars[name], CVar:GetInt())
if not cvars.GetConVarCallbacks(name..num, false) then
cvars.AddChangeCallback(name..num, function() timer.Simple(0,ReloadConVars) end)
end
end
ConVars[name] = Color(unpack(ConVars[name]))
end
HUDWidth = (GetConVar("HudW") or CreateClientConVar("HudW", 240, true, false)):GetInt()
HUDHeight = (GetConVar("HudH") or CreateClientConVar("HudH", 115, true, false)):GetInt()
if not cvars.GetConVarCallbacks("HudW", false) and not cvars.GetConVarCallbacks("HudH", false) then
cvars.AddChangeCallback("HudW", function() timer.Simple(0,ReloadConVars) end)
cvars.AddChangeCallback("HudH", function() timer.Simple(0,ReloadConVars) end)
end
end
ReloadConVars()
local Scrw, Scrh, RelativeX, RelativeY
/*---------------------------------------------------------------------------
HUD Seperate Elements
---------------------------------------------------------------------------*/
local Page = Material("icon16/page_white_text.png")
local function GunLicense()
if localplayer:getDarkRPVar("HasGunlicense") then
surface.SetMaterial(Page)
surface.SetDrawColor(255, 255, 255, 255)
surface.DrawTexturedRect(RelativeX + HUDWidth, ScrH() - 34, 32, 32)
end
end
local function Agenda()
local ply = LocalPlayer()
local agenda = ply:getAgendaTable()
if not agenda then return end
draw.RoundedBox(10, 10, 10, 460, 110, colors.gray1)
draw.RoundedBox(10, 12, 12, 456, 106, colors.gray2)
draw.RoundedBox(10, 12, 12, 456, 20, colors.darkred)
draw.DrawNonParsedText(agenda.Title, "DarkRPHUD1", 30, 12, colors.red, 0)
local text = ply:getDarkRPVar("agenda") or ""
text = text:gsub("//", "\n"):gsub("\\n", "\n")
text = DarkRP.textWrap(text, "DarkRPHUD1", 440)
draw.DrawNonParsedText(text, "DarkRPHUD1", 30, 35, colors.white, 0)
end
local VoiceChatTexture = surface.GetTextureID("voice/icntlk_pl")
local function DrawVoiceChat()
if localplayer.DRPIsTalking then
local chbxX, chboxY = chat.GetChatBoxPos()
local Rotating = math.sin(CurTime()*3)
local backwards = 0
if Rotating < 0 then
Rotating = 1-(1+Rotating)
backwards = 180
end
surface.SetTexture(VoiceChatTexture)
surface.SetDrawColor(ConVars.Healthforeground)
surface.DrawTexturedRectRotated(ScrW() - 100, chboxY, Rotating*96, 96, backwards)
end
end
CreateConVar("DarkRP_LockDown", 0, {FCVAR_REPLICATED, FCVAR_SERVER_CAN_EXECUTE})
local function LockDown()
local chbxX, chboxY = chat.GetChatBoxPos()
if util.tobool(GetConVarNumber("DarkRP_LockDown")) then
local cin = (ma
The GAMEMODE variable is the same as the GM variable but they are valid at only certain times (such as when the server is starting up)
Do something like:
[CODE]local gm_table = GAMEMODE or GM[/CODE]
And then replace any code where you used GAMEMODE or GM with gm_table variable instead
Thanks I am doing it right now I will tell you how it does :)
[editline]6th February 2016[/editline]
Did you mean like this?
[code]
function gm_table:DrawDeathNotice(x, y)
if not GAMEMODE.Config.showdeaths then return end
self.BaseClass:DrawDeathNotice(x, y)
end
[/code]
I did add the variable in but it doesn't work :/
[QUOTE=Sir. Pumpin';49684934]Thanks I am doing it right now I will tell you how it does :)
[editline]6th February 2016[/editline]
Did you mean like this?
[code]
function gm_table:DrawDeathNotice(x, y)
if not GAMEMODE.Config.showdeaths then return end
self.BaseClass:DrawDeathNotice(x, y)
end
[/code]
I did add the variable in but it doesn't work :/[/QUOTE]
[QUOTE=BillyOnWiiU;49684728]And then replace any code where you used GAMEMODE or GM with gm_table variable instead[/QUOTE]
R.E.P.L.A.C.E, everything that is either GAMEMODE or GM should be gm_table.
I said just if you needed it, and I then posted the part of the coding that was making errors -,-
[QUOTE=Sir. Pumpin';49685132]I said just if you needed it, and I then posted the part of the coding that was making errors -,-[/QUOTE]
It's obvious we'd need the code, else how do you expect us to know what is causing the trouble? Magic?
[QUOTE]Do not post huge scripts and expect people to fix them. If you wrote the script then you should know why it doesn't work. If you're editing someone's script and can't get it to work then don't! Learn how to code![/QUOTE]
Now back on topic:
You still didn't replace all GAMEMODE/GM occurrences in your code, so of course it'd generate errors.
The problem is that you're still using
[lua]if not GAMEMODE.Config.showdeaths then return end[/lua]
instead of
[lua]if not gm_table.Config.showdeaths then return end[/lua]
and the same kind of error will show up everywhere you didn't replace GAMEMODE/GM for gm_table.
That didn't do the tick still getting the lua error:
[code]
[BF2Hud v3.1] lua/autorun/cl_battlefronthud.lua:370: attempt to index local 'gm_table' (a nil value)
1. unknown - lua/autorun/cl_battlefronthud.lua:370
[/code]
Here is line 370:
[code]
local gm_table = GAMEMODE or GM
function gm_table:DrawDeathNotice(x, y)
if not gm_table.Config.showdeaths then return end
self.BaseClass:DrawDeathNotice(x, y)
end
[/code]
Oh yeah, you can't replace gamemode default functions, you have to use hooks for that.
[lua]
local gm_table = GAMEMODE or GM
hook.Add( "DrawDeathNotice", "StarwarsHUD_DeathNotice", function()
if not gm_table.Config.showdeaths then return end
self.BaseClass:DrawDeathNotice(x, y)
end )
[/lua]
[editline]asdad[/editline]
[del]anyways, as long as you don't edit DarkRP core files you shouldn't need to do this as it does by itself (Iirc)[/del]
no it does not, the default hud does it and if you disable it then no death notices....
Use the hook then and see if it works.
[editline]6th February 2016[/editline]
Also, when is this HUD being loaded (before, after or during Initialization)?
Every time I install my addon I restart gmod make sure its enabled and start a new game.
[editline]6th February 2016[/editline]
[code]
[BF2Hud v4] lua/autorun/cl_battlefronthud.lua:378: attempt to index upvalue 'gm_table' (a nil value)
1. v - lua/autorun/cl_battlefronthud.lua:378
2. Run - lua/includes/modules/hook.lua:84
3. HUDPaint - gamemodes/base/gamemode/cl_init.lua:77
4. unknown - gamemodes/sandbox/gamemode/cl_init.lua:75
[/code]
line 378:
[code]
local gm_table = GAMEMODE or GM
hook.Add( "DrawDeathNotice", "StarwarsHUD_DeathNotice", function()
if not gm_table.Config.showdeaths then return end
self.BaseClass:DrawDeathNotice(x, y)
end )
[/code]
[editline]6th February 2016[/editline]
Instead of rating it funny maybe you could help Luke xD
Try changing
[lua]local gm_table = GAMEMODE or GM[/lua]
to
[lua]local gm_table = gmod.GetGamemode()[/lua]
EDIT: Coffee, since you've rated me dumb, ofc you know how to solve this problem right? And of course you already posted the solution, right? Wait, no you didn't. So instead of going around rating, try to be at least 0.1% useful.
That didn't work as well (same lua error:
[code]
[BF2Hud v6] lua/autorun/cl_battlefronthud.lua:378: attempt to index upvalue 'gm_table' (a nil value)
1. v - lua/autorun/cl_battlefronthud.lua:378
2. Run - lua/includes/modules/hook.lua:84
3. HUDPaint - gamemodes/base/gamemode/cl_init.lua:77
4. unknown - gamemodes/sandbox/gamemode/cl_init.lua:75
[/code]
:/
and Luke
Be more useful -,-
Why don't you use the HUDReplacement Module by DarkRP?
Stupid to override everything without any knownledge.
Alright, I was making this for a server does that mean I just give them the folder with materials/vgui/ and the lua/autorun/
Sorry, you need to Log In to post a reply to this thread.