• Hooks coliding, don't know what to do.
    8 replies, posted
---SOLVED BY ACECOOL--- I tried adding text when you look at an entity (name is sim_ent_thompson1944, and sim_ent_ppsh41) This is the cl_init of both of them: (Tommy Gun) [CODE]include("shared.lua") ENT.RenderGroup = RENDERGROUP_OPAQUE function ENT:Draw() self.Entity:DrawModel() hook.Add("HUDPaint", "tomDraw", function() local ply = LocalPlayer() if(ply:Alive()) then if(ply:GetEyeTrace()) then if(ply:GetEyeTrace().Entity) then local ent = ply:GetEyeTrace().Entity if(ent:GetPos():Distance(ply:GetPos()) < 140) then local xAxis = ply:GetEyeTrace().HitPos:ToScreen().x local yAxis = ply:GetEyeTrace().HitPos:ToScreen().y surface.SetFont("ChatFont") surface.SetTextColor(230, 126, 34) surface.SetTextPos(xAxis+3,yAxis) surface.DrawText("Tommy Gun") surface.SetFont("ChatFont") surface.SetTextColor(255,255,255) surface.SetTextPos(xAxis,yAxis-2) surface.DrawText("Press E To Pick Up") end end end end end) end[/CODE] (PPSH41) [CODE]include("shared.lua") ENT.RenderGroup = RENDERGROUP_OPAQUE function ENT:Draw() self.Entity:DrawModel() hook.Add("HUDPaint", "ppshDraw", function() local ply = LocalPlayer() if(ply:Alive()) then if(ply:GetEyeTrace()) then if(ply:GetEyeTrace().Entity) then local ent = ply:GetEyeTrace().Entity if(ent:GetPos():Distance(ply:GetPos()) < 140) then local xAxis = ply:GetEyeTrace().HitPos:ToScreen().x local yAxis = ply:GetEyeTrace().HitPos:ToScreen().y surface.SetFont("ChatFont") surface.SetTextColor(230, 126, 34) surface.SetTextPos(xAxis+3,yAxis) surface.DrawText("Thompson1944") surface.SetFont("ChatFont") surface.SetTextColor(255,255,255) surface.SetTextPos(xAxis,yAxis-2) surface.DrawText("Press E To Pick Up") end end end end end) end[/CODE] And it's showing like this when I spawn one entity: [IMG]http://i.imgur.com/ONe3Qri.png[/IMG] When I spawn the other one, they colide: [IMG]http://i.imgur.com/KxD1V2x.png[/IMG] It's like the second one runs the hook of the first one. Why? *ACTUALLY: It draws it over any entity. How do i fix this?!
I output it on HUDPaint; simpler it seems: [lua]// // Press E to pick up weapon / Hold E to swap - Josh 'Acecool' Moser // hook.Add("HUDPaint", "AcecoolWeaponBase:HoldEToPickUpHUD", function( ) local _d, _t = LocalPlayer( ):TraceDistance( ); if ( IsValid( _t.Entity ) && _t.Entity:IsWeapon( ) && _d < 120 ) then local _text = "Tap USE to pick up " .. _t.Entity:GetTable( ).PrintName .. "."; draw.SimpleText( _text , "default", ScrW( ) / 2 + 25, ( ScrH( ) / 2 ) - 6, COLOR_WHITE ) end [/lua] That should be enough - a lot removed for the bar and other logic...
[QUOTE=Acecool;44940036]I output it on HUDPaint; simpler it seems: [lua]// // Press E to pick up weapon / Hold E to swap - Josh 'Acecool' Moser // hook.Add("HUDPaint", "AcecoolWeaponBase:HoldEToPickUpHUD", function( ) local _d, _t = LocalPlayer( ):TraceDistance( ); if ( IsValid( _t.Entity ) && _t.Entity:IsWeapon( ) && _d < 120 ) then local _text = "Tap USE to pick up " .. _t.Entity:GetTable( ).PrintName .. "."; draw.SimpleText( _text , "default", ScrW( ) / 2 + 25, ( ScrH( ) / 2 ) - 6, COLOR_WHITE ) end [/lua] That should be enough - a lot removed for the bar and other logic...[/QUOTE] Thanks, but it says [CODE][ERROR] addons/all_wwii_dod_weapons_for_gmod/lua/entities/sim_ent_thompson1944/cl_init.lua:7: attempt to call method 'TraceDistance' (a nil value) 1. v - addons/all_wwii_dod_weapons_for_gmod/lua/entities/sim_ent_thompson1944/cl_init.lua:7 2. unknown - lua/includes/modules/hook.lua:84 [/CODE]
You'll need to use your own trace and distance function. I combined them for the many cases where traces and getting a distance is used at the same time: Very straight forward: [lua]// // Returns distance and trace - Josh 'Acecool' Moser // function META_PLAYER:TraceDistance( pos ) if ( !IsValid( self ) ) then return false; end local _tr = util.TraceLine( util.GetPlayerTrace( self ) ); local _dist = math.GetDistance( ( pos or _tr.HitPos ), self:GetShootPos( ) ); return _dist, _tr; end[/lua]
[QUOTE=Acecool;44940099]You'll need to use your own trace and distance function. I combined them for the many cases where traces and getting a distance is used at the same time: Very straight forward: [lua]// // Returns distance and trace - Josh 'Acecool' Moser // function META_PLAYER:TraceDistance( pos ) if ( !IsValid( self ) ) then return false; end local _tr = util.TraceLine( util.GetPlayerTrace( self ) ); local _dist = math.GetDistance( ( pos or _tr.HitPos ), self:GetShootPos( ) ); return _dist, _tr; end[/lua][/QUOTE] Can i add this to ENT:Draw()?
As said, I simply use it in my HUDPaint; it may work in ENT:Draw with modifications... The function shouldn't be in it though because it would redefine it each time it draws..
[QUOTE=Acecool;44940115]As said, I simply use it in my HUDPaint; it may work in ENT:Draw with modifications... The function shouldn't be in it though because it would redefine it each time it draws..[/QUOTE] I'm kinda confused... Can you help me over steam?
Here's the new code, for a CLIENT side file outside of any weapon files: [lua]// // Draw Weapon-Name hook - Josh 'Acecool' Moser // Rewritten from [url]http://facepunch.com/showthread.php?t=1397295[/url] to follow my pre-existing logic // hook.Add( "HUDPaint", "WeaponText", function( ) local _p = LocalPlayer( ); local _tr = _p:GetEyeTrace( ); local _ent = _tr.Entity; if( IsValid( _p ) && _p:Alive( ) && _tr && IsValid( _ent ) && _ent:IsWeapon( ) ) then if( _ent:GetPos( ):Distance( _p:GetPos( ) ) < 140 ) then local _name = "N/A"; if ( _ent.GetTable && _ent:GetTable( ).PrintName ) then _name = _ent:GetTable( ).PrintName; end draw.SimpleText( _name, "ChatFont", ScrW( ) / 2 + 15, ( ScrH( ) / 2 ), Color( 230, 126, 34 ) ) draw.SimpleText( "Press E To Pick Up", "ChatFont", ScrW( ) / 2 + 15, ( ScrH( ) / 2 ) - 16, Color( 255, 255, 255 ) ) end end end );[/lua] It would've been easier to notice the issue had the HUDPaint been tabbed like everything else. The issue was the HUDPaint inside of Draw was called once for each weapon. Since the HUDPaint was the same name, it drew once for the weapon you looked at, then once more when the next entity Draw was called. [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/weapon_name_e_to_pick_up_hudpaint.lua.html[/url]
Thanks! Acecool solved it!
Sorry, you need to Log In to post a reply to this thread.