• HUD playermodel
    5 replies, posted
hey guys i am working on a swep that draws a hud when u use it and i want it to only draw the player model when you are holding the SWEP i have found this in a script for a hud i used but i dont know how to use hooks or if this works in a SWEP/HUD[CODE]hook.Add("InitPostEntity", "DrawPlayerModel", function() iconmodel = vgui.Create("DModelPanel") iconmodel:SetModel( LocalPlayer():GetModel()) function iconmodel:LayoutEntity( Entity ) return end iconmodel:SetPos(169, ScrH() - 205) iconmodel:SetAnimated(false) iconmodel:SetSize(125,125) iconmodel:SetCamPos( Vector( 20, 0, 65)) iconmodel:SetLookAt( Vector( 0, 0, 66.5 ) ) timer.Create("RefreshAvatar", 0.1, 0, function() if LocalPlayer():GetModel() ~= iconmodel.Entity:GetModel() then iconmodel:Remove() iconmodel = vgui.Create("DModelPanel") iconmodel:SetPos(169, ScrH() - 205) iconmodel:SetModel( LocalPlayer():GetModel()) function iconmodel:LayoutEntity( Entity ) return end iconmodel:SetAnimated(false) iconmodel:SetSize(125,125) iconmodel:SetCamPos( Vector( 20, 0, 65)) iconmodel:SetLookAt( Vector( 0, 0, 66.5 ) ) end end) end)[/CODE]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/benchmarking_tips/benchmarking_hud_stuff.lua.html[/url] You need to use HUDPaint. [lua]hook.Add( "HUDPaint", "MyWeaponHUD", function( ) local _p = LocalPlayer( ); if ( !IsValid( _p ) ) then return; end local _w = _p:GetActiveWeapon( ); if ( !IsValid( _w ) ) then return; end // Now draw your hud, the player is holding a weapon... end );[/lua] Alternatively, use the HUD function in SWEP. It'll only draw the hud with the weapon equipped. Just add the hud code to the base...
how do i use the hook.add do i have to call it or just put it in. this is the SWEP so far [CODE]id_card = {} --EDIT THE COLORS HERE---------------------------------- local colors = { background = Color( 255, 255, 255, 255); }; local tabel = { back = { x = 400; y = 150; w = 300; h = 150;}; }; --function id_card:_Location( x, y, w, h, color) --draw.RoundedBox( 6, x, ScrH() - y, w, h, colors.background ) --end if CLIENT then --THIS IS WHERE THE HUD IS DRAWN WHEN YOU TAKE THE ID CARD OUT function SWEP:DrawHUD() --id_card:_Location( 400, 150, 300, 150, colors) draw.RoundedBox( 6, tabel.back.x, ScrH() - tabel.back.y, tabel.back.w, tabel.back.h, colors.background) hook.Add("InitPostEntity", "DrawPlayerModel", function() iconmodel = vgui.Create("DModelPanel") iconmodel:SetModel( LocalPlayer():GetModel()) function iconmodel:LayoutEntity( Entity ) return end iconmodel:SetPos(169, ScrH() - 205) iconmodel:SetAnimated(false) iconmodel:SetSize(125,125) iconmodel:SetCamPos( Vector( 20, 0, 65)) iconmodel:SetLookAt( Vector( 0, 0, 66.5 ) ) timer.Create("RefreshAvatar", 0.1, 0, function() if LocalPlayer():GetModel() ~= iconmodel.Entity:GetModel() then iconmodel:Remove() iconmodel = vgui.Create("DModelPanel") iconmodel:SetPos(169, ScrH() - 205) iconmodel:SetModel( LocalPlayer():GetModel()) function iconmodel:LayoutEntity( Entity ) return end iconmodel:SetAnimated(false) iconmodel:SetSize(125,125) iconmodel:SetCamPos( Vector( 20, 0, 65)) iconmodel:SetLookAt( Vector( 0, 0, 66.5 ) ) end end) end) end end function SWEP:DrawViewModel() end function SWEP:Initialize() self:SetWeaponHoldType( "normal" ) end function SWEP:PrimaryAttack() return end function SWEP:SecondaryAttack() return end function SWEP:Think() end[/CODE]
Ah, I see what you mean.. You want the player avatar to hold the weapon when they have a weapon.. I gave you wrong information. Ok, you need to save the variable state of weapon. There are several hooks you'll need to monitor; test to ensure that the new weapon IsValid; if not then target your DModelPanel and remove the weapon from the character ( you'll need to extend your DModelPanel to support multiple models ) Don't put vgui.Create in HUDPaint or SWEP HUD EVER!!! You'll crash your game. Instead of monitoring hooks, you can use a timer, or Think hook to monitor when you have a valid weapon and when it changes. When it changes, update the DModelPanel, when it is removed, update the DModelPanel. Never create... ( This method could be very reliable ) For monitoring hooks function GM:PlayerSwitchWeapon( Player, OldWeapon, NewWeapon )
nope :P i want the HUD to show the player model in the HUD [url]http://media.moddb.com/images/mods/1/20/19746/2012-02-29_00001.jpg[/url] when you hold the SWEP it draws a HUD and the player model in it i want somthing like in the link above but i onlt want it to show when i pull out the SWEP
So you want the swep to be a different element? Just use a DModelPanel and use the model of the current weapon. PlayerSwitchWeapon = change the image without having to re-create the vgui panel.
Sorry, you need to Log In to post a reply to this thread.