Hello, I am making a HUD for DarkRP right now (my first), and I don't know how to correctly make a playermodel on my HUD (A playermodel that reflects the job you have in DarkRP) I've tried to use the DModelPanel, but it caused loads of FPS lag and I couldn't use the F4 menu, spawning menu, or context menu. I also tried using the SpawnIcon, but I couldn't use the F4, spawning, or context menu either. So, how do I add the playermodel on my HUD?
Where are you putting this code that didn't work?
[QUOTE=Thane;50706003]Where are you putting this code that didn't work?[/QUOTE]
At the end, after all my text and boxes.
I meant which file, but could you post your code? And make sure you put it in [code.]Your code here[/code.]
but without the periods.
darkrpmodification-master\lua\darkrp_modules\hudreplacement\cl_hudreplacement.lua
[code]surface.CreateFont( "Font", {
font = "Impact", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
extended = false,
size = 30,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = true,
} )
hook.Add("HUDPaint" , "DrawMyHealth" , function()
local health = LocalPlayer():Health()
draw.RoundedBox(0,20,ScrH() - 90,300 + 4 , 30 + 4,Color(40, 40, 40))
draw.RoundedBox(0,22,ScrH() - 88,health * 3,30,Color(255,0,0))
draw.SimpleText(health.. "%" , "Font",10 + 150, ScrH() - 72,Color(255,255,255),1, 1)
hook.Add("HUDPaint" , "DrawMyArmor" , function()
local armor = LocalPlayer():Armor()
draw.RoundedBox(0,20,ScrH() - 50,300 + 4 , 30 + 4,Color(40, 40, 40))
draw.RoundedBox(0,22,ScrH() - 48,armor * 3,30,Color(0,0,255))
draw.SimpleText(armor.. "%" , "Font",10 + 150, ScrH() - 32,Color(255,255,255),1, 1)
hook.Add("HUDPaint" , "DrawMyMoney" , function()
local Money = ply:getDarkRPVar("money") or 0
draw.SimpleText("$".. Money ,"Font",10 + 280, ScrH() - 130,Color(0,255,0),1, 1)
hook.Add("HUDPaint" , "DrawMySalary" , function()
local Salary = ply:getDarkRPVar("salary") or 0
draw.SimpleText("$".. Salary ,"Font",10 + 280, ScrH() - 105,Color(255,255,0),1, 1)
hook.Add("HUDPaint" , "DrawMyJob" , function()
local Job = ply:getDarkRPVar("job")
draw.SimpleText(Job , "Font", 10 + 115, ScrH() - 105,Color(255,255,255),1, 1)
hook.Add("HUDPaint" , "DrawMyName" , function()
draw.SimpleText(ply:Nick() , "Font", 10 + 115, ScrH() - 130,Color(255,255,255),1, 1)
local model = vgui.Create("SpawnIcon")
model:SetPos(10 + 10, ScrH() - 154)
model:SetModel(LocalPlayer():GetModel())
end)
end)
end)
end)
end)
end)
[/code]
Please don't create HUDPaint hooks IN a HUDPaint hook, it'll lag tons
[editline]14th July 2016[/editline]
Also, the reason the DModelPanel was creating lag for you was probably because you were creating it in one of those HUDPaint hooks. I'll have a go at fixing your code, hang on
[editline]14th July 2016[/editline]
Try this:
[CODE]
surface.CreateFont( "Font", {
font = "Impact", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
extended = false,
size = 30,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = true,
} )
local model = vgui.Create("SpawnIcon") -- NEVER create vgui panels in a HUDPaint hook
model:SetPos(10 + 10, ScrH() - 154)
hook.Add("HUDPaint" , "DrawMyHealth" , function()
local health = LocalPlayer():Health()
draw.RoundedBox(0,20,ScrH() - 90,300 + 4 , 30 + 4,Color(40, 40, 40))
draw.RoundedBox(0,22,ScrH() - 88,health * 3,30,Color(255,0,0))
draw.SimpleText(health.. "%" , "Font",10 + 150, ScrH() - 72,Color(255,255,255),1, 1)
local armor = LocalPlayer():Armor()
draw.RoundedBox(0,20,ScrH() - 50,300 + 4 , 30 + 4,Color(40, 40, 40))
draw.RoundedBox(0,22,ScrH() - 48,armor * 3,30,Color(0,0,255))
draw.SimpleText(armor.. "%" , "Font",10 + 150, ScrH() - 32,Color(255,255,255),1, 1)
local Money = LocalPlayer():getDarkRPVar("money") or 0
draw.SimpleText("$".. Money ,"Font",10 + 280, ScrH() - 130,Color(0,255,0),1, 1)
local Salary = LocalPlayer():getDarkRPVar("salary") or 0
draw.SimpleText("$".. Salary ,"Font",10 + 280, ScrH() - 105,Color(255,255,0),1, 1)
local Job = LocalPlayer():getDarkRPVar("job")
draw.SimpleText(Job , "Font", 10 + 115, ScrH() - 105,Color(255,255,255),1, 1)
draw.SimpleText(LocalPlayer():Nick() , "Font", 10 + 115, ScrH() - 130,Color(255,255,255),1, 1)
model:SetModel(LocalPlayer():GetModel()) -- update the model
end)
[/CODE]
I didn't change much, but it should be less laggy now
[editline]14th July 2016[/editline]
Also, the reason you shouldn't create any vgui stuff in a HUDPaint hook is because it doesn't get removed by the next frame. HUDPaint hooks get called EVERY FRAME, and if you create a vgui element in it without removing it BY THE NEXT FRAME, then it'll get created again and again and again EVERY SINGLE FRAME, which obviously causes lag
[QUOTE=MPan1;50706077]Please don't create HUDPaint hooks IN a HUDPaint hook, it'll lag tons
[editline]14th July 2016[/editline]
Also, the reason the DModelPanel was creating lag for you was probably because you were creating it in one of those HUDPaint hooks. I'll have a go at fixing your code, hang on
[editline]14th July 2016[/editline]
Try this:
[CODE]
surface.CreateFont( "Font", {
font = "Impact", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
extended = false,
size = 30,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = true,
} )
local model = vgui.Create("SpawnIcon") -- NEVER create vgui panels in a HUDPaint hook
model:SetPos(10 + 10, ScrH() - 154)
model:SetModel(LocalPlayer():GetModel())
hook.Add("HUDPaint" , "DrawMyHealth" , function()
local health = LocalPlayer():Health()
draw.RoundedBox(0,20,ScrH() - 90,300 + 4 , 30 + 4,Color(40, 40, 40))
draw.RoundedBox(0,22,ScrH() - 88,health * 3,30,Color(255,0,0))
draw.SimpleText(health.. "%" , "Font",10 + 150, ScrH() - 72,Color(255,255,255),1, 1)
local armor = LocalPlayer():Armor()
draw.RoundedBox(0,20,ScrH() - 50,300 + 4 , 30 + 4,Color(40, 40, 40))
draw.RoundedBox(0,22,ScrH() - 48,armor * 3,30,Color(0,0,255))
draw.SimpleText(armor.. "%" , "Font",10 + 150, ScrH() - 32,Color(255,255,255),1, 1)
local Money = LocalPlayer():getDarkRPVar("money") or 0
draw.SimpleText("$".. Money ,"Font",10 + 280, ScrH() - 130,Color(0,255,0),1, 1)
local Salary = LocalPlayer():getDarkRPVar("salary") or 0
draw.SimpleText("$".. Salary ,"Font",10 + 280, ScrH() - 105,Color(255,255,0),1, 1)
local Job = LocalPlayer():getDarkRPVar("job")
draw.SimpleText(Job , "Font", 10 + 115, ScrH() - 105,Color(255,255,255),1, 1)
draw.SimpleText(LocalPlayer():Nick() , "Font", 10 + 115, ScrH() - 130,Color(255,255,255),1, 1)
end)
[/CODE]
I didn't change much, but it should be less laggy now
[editline]14th July 2016[/editline]
Also, the reason you shouldn't create any vgui stuff in a HUDPaint hook is because it doesn't get removed by the next frame. HUDPaint hooks get called EVERY FRAME, and if you create a vgui element in it without removing it BY THE NEXT FRAME, then it'll get created again and again and again EVERY SINGLE FRAME, which obviously causes lag[/QUOTE]
Ok, kinda weird, but I just realized that on the game startup it does this:
[url]http://images.akamai.steamusercontent.com/ugc/271723349502644537/DC0D7AC772300E28B4B93DA85985C6F68D0E627D/?interpolation=lanczos-none&output-format=jpeg&output-quality=95&fit=inside|1024:576&composite-to=*,*|1024:576&background-color=black[/url]
But when I save it again, it fixes it, but with the box that usually indicates an image error being behind the hud...
Edit: it also comes up with this error message:
[DarkRP] addons/darkrpmodification-master/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:72: Tried to use a NULL entity!
1. GetModel - [C]:-1
2. unknown - addons/darkrpmodification-master/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:72
3. doInclude - [C]:-1
4. loadModules - gamemodes/darkrp/gamemode/libraries/modificationloader.lua:102
5. Call - gamemodes/darkrp/gamemode/libraries/modificationloader.lua:147
6. unknown - gamemodes/darkrp/gamemode/cl_init.lua:53
[QUOTE=deal with it;50706147]Ok, kinda weird, but I just realized that on the game startup it does this:
[url]http://images.akamai.steamusercontent.com/ugc/271723349502644537/DC0D7AC772300E28B4B93DA85985C6F68D0E627D/?interpolation=lanczos-none&output-format=jpeg&output-quality=95&fit=inside|1024:576&composite-to=*,*|1024:576&background-color=black[/url]
But when I save it again, it fixes it, but with the box that usually indicates an image error being behind the hud...
Edit: it also comes up with this error message:
[DarkRP] addons/darkrpmodification-master/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:72: Tried to use a NULL entity!
1. GetModel - [C]:-1
2. unknown - addons/darkrpmodification-master/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:72
3. doInclude - [C]:-1
4. loadModules - gamemodes/darkrp/gamemode/libraries/modificationloader.lua:102
5. Call - gamemodes/darkrp/gamemode/libraries/modificationloader.lua:147
6. unknown - gamemodes/darkrp/gamemode/cl_init.lua:53[/QUOTE]
Kill yourself and see if the player model appears
Sorry, I forgot that LocalPlayer() isn't set at the start of the game. I updated the code I posted before, try it now.
[QUOTE=Thane;50706343]Kill yourself and see if the player model appears[/QUOTE]
Nope
Figured it'd be the same problem I had with getting the players avatar, I guess it kind of is since the LocalPlayer() doesn't exist at the beginning of the game, like MPan1 said. Although it's basically the same thing I did to fix my problem. What MPan1 said should work.
[QUOTE=MPan1;50706359]Sorry, I forgot that LocalPlayer() isn't set at the start of the game. I updated the code I posted before, try it now.[/QUOTE]
It works now! Thank you :D
Sorry, you need to Log In to post a reply to this thread.