Hi All
Currently working on a HUD which displays the players current model using a DPanel. The issue I have is it does not update nor show it upon player connect. I need something that refreshes the DPanel upon player connect and also when they change jobs on my server.
panelcolor = Color( 0, 0, 0, 0)
local Panel = vgui.Create( "DPanel" )
Panel:SetPos( 8, ScrH() - 200 )
Panel:SetSize( 200, 200 )
Panel:SetBackgroundColor( panelcolor )
Panel:ParentToHUD()
local icon = vgui.Create( "DModelPanel", Panel )
icon:SetSize( 100, 100 )
icon:SetPos( 0, 50)
icon:SetAnimated(true)
icon:SetModel( LocalPlayer():GetModel() )
local eyeposst = icon.Entity:GetBonePosition(icon.Entity:LookupBone("ValveBiped.Bip01_Head1") or 0)
eyeposst:Add(Vector(12, 0, 0))
icon:SetLookAt(eyeposst)
icon:SetCamPos(eyeposst - Vector(-15, 0, 0))
icon.Entity:SetEyeTarget(eyeposst - Vector(-12, 0, 0))
function icon:LayoutEntity( Entity )
return
end
So far I have what is above. It will display the model in the bottom left upon running the script. It will also overlay multiple models if the script is run multiple times.
E.G. If I run the script it will display model1. If i change models in-game and run the script again it will display models 1 and 2.
I have read about DPanel:Think() but not sure how to use this function with my code in order for it to update on certain parameters.
Any help would be appreciated, thank you.
Try something like this perhaps
panelcolor = Color( 0, 0, 0, 0)
local Panel = vgui.Create( "DPanel" )
Panel:SetPos( 8, ScrH() - 200 )
Panel:SetSize( 200, 200 )
Panel:SetBackgroundColor( panelcolor )
Panel:ParentToHUD()
local icon = vgui.Create( "DModelPanel", Panel )
icon:SetSize( 100, 100 )
icon:SetPos( 0, 50)
icon:SetAnimated(true)
icon.currentModel = LocalPlayer():GetModel() -- Store the current model so we can see if it has changed
icon:SetModel( LocalPlayer():GetModel() )
local eyeposst = icon.Entity:GetBonePosition(icon.Entity:LookupBone("ValveBiped.Bip01_Head1") or 0)
eyeposst:Add(Vector(12, 0, 0))
icon:SetLookAt(eyeposst)
icon:SetCamPos(eyeposst - Vector(-15, 0, 0))
icon.Entity:SetEyeTarget(eyeposst - Vector(-12, 0, 0))
function icon:Think()
if LocalPlayer():GetModel() != self.currentModel then -- Only update if the model has actually changed to prevent lag
self:SetModel(LocalPlayer():GetModel())
self.currentModel = LocalPlayer():GetModel()
end
end
function icon:LayoutEntity( Entity )
return
end
Thank you @Donkie that worked.
Now I just need something that loads the script apon server entry. Like when a player spawns in to display the model
This post gives you exactly what you need: https://forum.facepunch.com/gmoddev/nnve/How-can-I-make-that-a-Derma-Menu-opens-once-the-player-spawn/1/#posteqdjd
Just change PlayerSpawn with PlayerInitialSpawn
@Donkie When I follow that as a guidance i get this
if (SERVER) then
util.AddNetworkstring("playermodel")
hook.Add("PlayerInitialSpawn", "OpenDerma", function(ply)
net.Start("playermodel")
net.Send(ply)
end)
end
if (CLIENT) then
net.Receive("playermodel", function()
panelcolor = Color( 0, 0, 0, 0)
local Panel = vgui.Create( "DPanel" )
Panel:SetPos( 8, ScrH() - 200 )
Panel:SetSize( 200, 200 )
Panel:SetBackgroundColor( panelcolor )
Panel:ParentToHUD()
local icon = vgui.Create( "DModelPanel", Panel )
icon:SetSize( 100, 100 )
icon:SetPos( 0, 50)
icon:SetAnimated(true)
icon.currentModel = LocalPlayer():GetModel()
icon:SetModel( LocalPlayer():GetModel() )
local eyeposst = icon.Entity:GetBonePosition(icon.Entity:LookupBone("ValveBiped.Bip01_Head1") or 0)
eyeposst:Add(Vector(12, 0, 0))
icon:SetLookAt(eyeposst)
icon:SetCamPos(eyeposst - Vector(-15, 0, 0))
icon.Entity:SetEyeTarget(eyeposst - Vector(-12, 0, 0))
function icon:Think()if LocalPlayer():GetModel() != self.currentModel then-- Only update if the model has actually changed to prevent lag
self:SetModel(LocalPlayer():GetModel())
self.currentModel = LocalPlayer():GetModel()
end
end
function icon:LayoutEntity( Entity )
return
end
end)
end
On player initial spawn it doesn't make the model appear. I cannot get it to appear by running the script either. I changed it to PlayerSpawn to check if when the player spawns it would appear, but nothing.
Is this code put in a shared file?
Snippet of code from TCB Hud v2.
timer.Create( "UpdatePlayerModel", 0.5, 0, function()
if LocalPlayer():GetModel() != PlayerModel.Entity:GetModel() then
PlayerModel:Remove()
PlayerModel = vgui.Create("DModelPanel")
function PlayerModel:LayoutEntity( Entity ) return end
PlayerModel:SetModel( LocalPlayer():GetModel())
PlayerModel:SetPos(HUD.PosX, HUD.PosY)
PlayerModel:SetSize(75, HUD.HHeight)
PlayerModel:SetCamPos(Vector( 16, 0, 65 ))
PlayerModel:SetLookAt(Vector( 0, 0, 65 ))
end
end)
Make a timer, check if the player's model is the same as the model in your panel, if it isn't recreate the panel.
Sorry, you need to Log In to post a reply to this thread.