Item prop red glow / outline ?

So, I’m trying to make it so that specific entities (in this case, an M16 rifle entity) has a red glow around the world model when you come within a certain range of it.

I’ve got some basic code that gives ALL entities within a range a glow, but the problem is that this also highlights NPC’s in red, which I do not want, I only want certain entities to have the glow.

Any suggestions?

Also, here is the current code I have:



hook.Add("PreDrawHalos", "DrawHalo", function()
    local tr = util.GetPlayerTrace(LocalPlayer())
    local trRes = util.TraceLine(tr)
    for _,ent in pairs(ents.FindInSphere(LocalPlayer():GetPos(), 100)) do
        if trRes.Entity == ent then
            effects.halo.Add({ent}, Color(255, 0, 0), 5, 5, 2)
            break
        end
    end
end)


Compare the class of the trace result entity and the entities that are being looped.

I did not test the code so you and I both hope it works.

[lua]
// I added some variables so you can change shit quick
local drawRadius = 100
local haloColor = Color(255,0,0)

// example being “weapon_crowbar”
// table of valid class names
local valid_classes = {
“<insert class>”,
“<insert class>”,
“<…etc>”
}

local function getValidEnts()
local ent_table = ents.FindInSphere(LocalPlayer():GetPos(), drawRadius)
local return_ents = {}
// loop compares all ents found in the circle to the table of valid classes
// another and probably more effiecient way to to do this would be to find
//all of the valid entities first then find there distance to you and compare the distance
for _,v in pairs(ent_table) do
for k, j in pairs(valid_classes) do
if v:GetClass() == j then table.insert(return_ents, v) break end
end
end
// return the ents to get halos
return return_ents
end

local function drawHalos()
local inRange = getValidEnts()
effects.halo.Add(inRange, haloColor , 5, 5, 2)
end
hook.Add(“PreDrawHalos”, “DrawHalo”, drawHalos)
[/lua]