Find Entity not working?

i realy don’t know what is wrong with this code:
[LUA]
hook.Add( “HUDPaint”, “Printer”, function()
if PrinterSwitch:GetInt() == 1 then
local en = ents.FindByModel(“models/props_borealis/bluebarrel001.mdl”)
for k, v in pairs(en) do
local pos = v:GetPos():ToScreen()
draw.RoundedBox( 4, pos.x-5, pos.y-5, 10, 10, Color( 255, 0, 0, 150 ) )
end
end
end)
[/lua]

pleas help

Thanks,

I’m not ingame to test this, but you could try adding a print to the code to see if it’s finding the entities. If so, it’s an issue with your draw code.

if i do a print like :
[LUA]
print (“Function Active”)
[/LUA]
i see that is works.

i try to switch
[LUA]
ents.FindByModel(“models/props_borealis/bluebarrel001.mdl”)
[/LUA]
to
[LUA]
ents.FindByClass(“prop_physics”)
[/LUA]

and than it works fine…

Yeah because props are spawned with prop_physics, you alter the model with ent:SetModel(modelhurrrr)

you have a code?

mine don’t work the way you say.

[editline]15th May 2011[/editline]

[LUA]
hook.Add( “HUDPaint”, “Printer”, function()
if PrinterSwitch:GetInt() == 1 then
local ent = ents.FindByModel(“models/props_borealis/bluebarrel001.mdl”)
//ents.FindByClass(“prop_physics”)
for k, v in pairs(ent) do
local pos = v:GetPos():ToScreen()
print("->")
draw.RoundedBox( 4, pos.x-5, pos.y-5, 10, 10, Color( 255, 0, 0, 150 ) )
end
end
end)
[/LUA]

on this way it works only 3 seconds when the prop is spawned.

It appears that FindByModel doesn’t work, as I just tried it too. You could do this…

[lua]hook.Add(“HUDPaint”, “showBarrels”, function()
for k,v in pairs(ents.FindByClass(“prop_physics”)) do
if (v:IsValid() and v:GetModel() == “models/props_borealis/bluebarrel001.mdl”) then
local pos = v:GetPos():ToScreen()
draw.RoundedBox( 4, pos.x-5, pos.y-5, 10, 10, Color( 255, 0, 0, 150 ) )
end
end
end)[/lua]

Yea he’s code is working as you see on the picture but you could also use ents.GetAll() instead of ents.FindByClass()

That works GREAT!
thanks for helping Fleamonji!

But then you have to filter through extra entities, which could probably make it a bit slower.

Oh yea you are right unless he wants to find more of them later.

Why it isn’t working if i try

[LUA]
hook.Add( “HUDPaint”, “Printer”, function()
hook.Add(“HUDPaint”, “showBarrels”, function()
for k,v in pairs(ents.FindByClass(“prop_physics”)) do
if (v:IsValid() and v:GetModel() == “models/Combine_Helicopter/helicopter_bomb01.mdl”) then
local pos = v:GetPos():ToScreen()
draw.RoundedBox( 4, pos.x-5, pos.y-5, 10, 10, Color( 255, 0, 0, 150 ) )
end
end
end)
end)
[/LUA]

Why are you hooking it twice?

Its not working cause you doubled up your Hook at the very top.

What’s the point of this reply I clearly answered it an hour before this post

It now works with more porps but not a prop like:

[LUA]
models/Gibs/HGIBS.mdl
[/lua]

can someone tell me why?

The model anme must be all lowercase

Sorry, i left it on this thread when i went out so i got back and just replied to what i saw.

:ninja:'ed

can it be that my prop has al ready a box on it, like in RP that it don’t work sometimes?