• Help with player model on HUD
    3 replies, posted
So this is what I've got: [CODE]local name = Material("icon16/user.png") local job2 = Material("icon16/vcard.png") local money2 = Material("icon16/money.png") local salar2 = Material("icon16/money_add.png") local function DrawHealth() LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {} local ply = LocalPlayer() local HP,AR = ply:Health(),ply:Armor() local slujba = LocalPlayer().DarkRPVars.job or "Unemployed" local salar = LocalPlayer().DarkRPVars.salary or "NONE" local bani = LocalPlayer().DarkRPVars.money or "NONE" draw.RoundedBox(10,10,ScrH() - 90,350,80,Color(71,71,71,210)) draw.RoundedBox(0,20,ScrH() - 80,64,64,Color(0,0,0,255)) -- HERE IS WHERE I NEED HELP! local Model = ply:GetModel() local icon = vgui.Create("SpawnIcon") local IconModel = Model icon:SetModel(IconModel) icon:SetSize(64, 64) icon:SetPos(20, ScrH() - 80) -- HERE IS WHERE I NEED HELP! draw.RoundedBox(0,100,ScrH() - 80,252,19,Color(0,0,0,255)) draw.RoundedBox(0,102,ScrH() - 78,math.Clamp(HP,0,100)*2.48,15,Color(50,170,70,255)) draw.SimpleText(HP.."%","TargetID",210,ScrH() - 78) if AR > 0 then draw.RoundedBox(0,135,ScrH() - 59,184,14,Color(0,0,0,255)) draw.RoundedBox(0,137,ScrH() - 57,math.Clamp(AR,0,100)*1.8,10,Color(8,116,225,255)) draw.SimpleText(AR.."%","TargetID",210,ScrH() - 60) end surface.SetMaterial(name) surface.SetDrawColor(255,255,255,255) surface.DrawTexturedRect(90,ScrH() - 45,16,16) draw.SimpleText(ply:Nick(),"TargetID",110,ScrH() - 45) surface.SetMaterial(money2) surface.SetDrawColor(255,255,255,255) surface.DrawTexturedRect(250,ScrH() - 45,16,16) draw.SimpleText("$"..bani,"TargetID",270,ScrH() - 45) surface.SetMaterial(salar2) surface.SetDrawColor(255,255,255,255) surface.DrawTexturedRect(250,ScrH() - 30,16,16) draw.SimpleText("$"..salar,"TargetID",270,ScrH() - 30) surface.SetMaterial(job2) surface.SetDrawColor(255,255,255,255) surface.DrawTexturedRect(90,ScrH() - 30,16,16) draw.SimpleText(slujba,"TargetID",110,ScrH() - 30) end[/CODE] It's a simple hud which draws the player's job's model but why does it lag? I'm not the best at Lua yet, I started about a week ago but I'm a quick learner. It lags REALLY bad I think the icon is re-rendering a bunch or something but along with low frames, if I try to use the F4 menu the cursor just flickers and is unusable. Please help
If you call this function in HudPaint the vgui will be create every frame. << this lags Create the vgui and use the function Panel:Paint() or function Panel:Think() to change some Panel settings
That's what I was thinking, I was so tired when I wrote the script, I will try that:) [editline]26th July 2013[/editline] That stopped a big portion of the lag but the mouse still flickers and was unusable. BUT I did write a small code to only allow it to update every 50 updates or so, which solved both problems, but it makes me look like the most foolish coder in the world. I'm off to write a code to only update if the player's job changes
You have to make a function, and hook it. I will update in a few, as I am away from my main pc.
Sorry, you need to Log In to post a reply to this thread.