• Replacement for DrawEntityOutline?
    13 replies, posted
[CODE]function ENT:Draw() if (self:GetNetworkedBool("smoking", false)) then local effect = EffectData(); effect:SetOrigin(self:GetPos()); util.Effect("meth_smoke", effect); end if ( LocalPlayer():GetEyeTrace().Entity == self.Entity && EyePos():Distance( self.Entity:GetPos() ) < 512 ) then self:DrawEntityOutline( 1.1 ) end self:DrawModel() end local matOutlineWhite = Material( "white_outline" ) local ScaleNormal = 0 local ScaleOutline1 = 1 local ScaleOutline2 = 1.1 local matOutlineBlack = Material( "black_outline" ) function ENT:DrawEntityOutline( size ) size = size or 1.0 render.SuppressEngineLighting( true ) render.SetAmbientLight( 1, 1, 1 ) render.SetColorModulation( 1, 1, 1 ) // First Outline self:SetModelScale( ScaleOutline2 * size ) render.MaterialOverride( matOutlineBlack ) self:DrawModel() // Second Outline self:SetModelScale( ScaleOutline1 * size ) render.MaterialOverride( matOutlineWhite ) self:DrawModel() // Revert everything back to how it should be render.MaterialOverride( nil ) self:SetModelScale( ScaleNormal, 0 ) render.SuppressEngineLighting( false ) local col = self:GetColor() render.SetColorModulation( col.r/255, col.g/255, col.b/255 ) end[/CODE] This is from my item script where if you look at the prop then it will have the white glow around it and when you look away it was supposed to remove the glow from that prop. It wasnt supposed to have a white glow around any of the npcs or entities on the map just specific items in the gamemode. Ive tried doing some research and looked around for a solution to my problem but all i could really find were things about Halo.Add and stuff and i even did some research into that played around with it a little bit and eventually got it to put a halo around the one prop but it would never go away even if you looked away from it, it would still be glowing if i spawned two different items i could look at one and it would glow then i could look at the other one and that one would glow and the other one wouldnt. Does anyone have any ideas on how to fix this? I thought it had something to do about this [CODE]if ( LocalPlayer():GetEyeTrace().Entity == self.Entity && EyePos():Distance( self.Entity:GetPos() ) < 512 ) then self:DrawEntityOutline( 1.1 ) end self:DrawModel() end[/CODE] Since DrawEntityOutline doesnt exist anymore i was thinking that could be the problem but i cant find the solution. If someone could help me it would be greatly appreciated.
I think it would be easier for you just to get the halos working. Here's a snippet of code I've made that accomplishes something similar to what you're trying to achieve: [lua] function GM:PreDrawHalos() local tr = util.GetPlayerTrace(LocalPlayer()) local trRes = util.TraceLine(tr) for _,ent in pairs(ents.FindInSphere(LocalPlayer():GetPos(), 16)) do if trRes.Entity == ent then effects.halo.Add({ent}, Color(0, 255, 0), 5, 5, 2) break end end end [/lua]
[QUOTE=Sparky-Z;39104095]I think it would be easier for you just to get the halos working. Here's a snippet of code I've made that accomplishes something similar to what you're trying to achieve: [lua] function GM:PreDrawHalos() local tr = util.GetPlayerTrace(LocalPlayer()) local trRes = util.TraceLine(tr) for _,ent in pairs(ents.FindInSphere(LocalPlayer():GetPos(), 16)) do if trRes.Entity == ent then effects.halo.Add({ent}, Color(0, 255, 0), 5, 5, 2) end end end [/lua][/QUOTE] You'd be better off doing this [lua] local rents = {} for _,ent in pairs(ents.FindInSphere(LocalPlayer():GetPos(), 16)) do if trRes.Entity == ent then table.insert(rents,ent) end end if #rents >= 1 then effects.halo.Add(rents, Color(0, 255, 0), 5, 5, 2) end [/lua] Won't be as laggy.
so would i want to get rid of the entire entityoutline function and where it says self:DrawEntityOutline just replace it? [editline]5th January 2013[/editline] [CODE]local rents = {} for _,ent in pairs(ents.FindInSphere(LocalPlayer():GetPos(), 16)) do if trRes.Entity == ent then table.insert(rents,ent) end end if #rents >= 1 then effects.halo.Add(rents, Color(0, 255, 0), 5, 5, 2) end[/CODE] also, I attempted what you said above that i would be better off using this and i did a little test and tried it out and it came back as attempt to index global 'trRes' (a nil value) [editline]5th January 2013[/editline] I'm trying to get when i look at the prop it add the halo but when i dont look at the prop it removes the halo how would i go about doing that?
I think he meant to have it replace part of my code in my post above it. [lua] function GM:PreDrawHalos() local tr = util.GetPlayerTrace(LocalPlayer()) local trRes = util.TraceLine(tr) local rents = {} for _,ent in pairs(ents.FindInSphere(LocalPlayer():GetPos(), 16)) do if trRes.Entity == ent then table.insert(rents,ent) end end if #rents >= 1 then effects.halo.Add(rents, Color(0, 255, 0), 5, 5, 2) end end [/lua] Although, isnipeu, why is this less laggy than what I had? Won't there only be one trRes.Entity at a time and thus make the table redundant?
I don't think his will be any faster to be honest, since he is making a table only for it be unpacked one by one on the other end anyway.
Where am i going to put that i mean because i attempted yours too. No errors except for attempt to index global GM. This is in a entity folder so im assuming i need to put ur function in the gamemode for it to work?
[QUOTE=Regicide;39104426]Where am i going to put that i mean because i attempted yours too. No errors except for attempt to index global GM. This is in a entity folder so im assuming i need to put ur function in the gamemode for it to work?[/QUOTE] Yea, it was meant for a gamemode clientside file, if you use this though it should work anywhere clientside. [lua] hook.Add("PreDrawHalos", "DrawHalo", function() local tr = util.GetPlayerTrace(LocalPlayer()) local trRes = util.TraceLine(tr) for _,ent in pairs(ents.FindInSphere(LocalPlayer():GetPos(), 16)) do if trRes.Entity == ent then effects.halo.Add({ent}, Color(0, 255, 0), 5, 5, 2) break end end end) [/lua]
Putting in the gamemode aswell doesnt make any difference it doesnt add a halo around the entities.
Hmm, that's odd. Maybe you're not getting close enough? Try changing the radius in ents.FindInSphere to 50.
that seemed to work, but is it possible to do the same like where instead of doing GetPos to like GetAimVector or something and have it have the same effect? where it would light up if i looked at it it would glow and if i looked away it would remove the glow? [editline]5th January 2013[/editline] also, it does it for every entity on the map. Im only looking for gamemode entities. [editline]5th January 2013[/editline] [CODE]if ( LocalPlayer():GetEyeTrace().Entity == self.Entity && EyePos():Distance( self.Entity:GetPos() ) < 512 ) then hook.Add( "PreDrawHalos", "AddHalos", function() effects.halo.Add({self.Entity}, Color( 255, 0, 0 )) end ) end[/CODE] Origanlly i did that to attempt to fix it which it did add the glow around only gamemode entities like i wanted it to but, the glow would stay around it even if you looked away. Which im trying to achieve that if you look at it, it glows and if you look away it removes the glow around it.
Yea it is possible and probably actually better. Look up how to make traces on the wiki and then get rid of the for loop and just use the if statement. To make it certain items only, just add something in the if statement about whether or not the traced entity's class is in a table of entity classes to draw halos on.
[CODE]if ( LocalPlayer():GetEyeTrace().Entity == self.Entity && EyePos():Distance( self.Entity:GetPos() ) < 512 ) then[/CODE] this orignally was used for the DrawEntityOutline, which then i posted above how i added the hook for Halo's. But the when i did so it just added the halo no EyeTrace or GetPos was involved it just automatically set the halo around it and i read up on the wiki on Tracing and EyeTrace and AimVectors which kinda got me a idea but didn't get me very far.
Put everything in the hook. [lua] hook.Add( "PreDrawHalos", "AddHalos", function() if ( LocalPlayer():GetEyeTrace().Entity == self.Entity && EyePos():Distance( self.Entity:GetPos() ) < 512 ) then effects.halo.Add({self.Entity}, Color( 255, 0, 0 )) end end) [/lua]
Sorry, you need to Log In to post a reply to this thread.