Entity Glow Help.

Well I’m trying to make a few entities glow. The entity names are “wood”,“ironbar”,“spring”,“wrench”
They are materials for the crafting table addon from coderhire and I would like to know how to make them glow to distinct them better.

And for the second part, I’m trying to get the command on this to work so I can add positions to the position list table in game and easily.


local EntityList = {
	"ironbar",
	"ironbar",
	"ironbar",
	"spring",
	"spring",
	"wrench",
	"wrench",
	"food",
	"food",
	"food",
	"npc_zombie",
	"npc_fastzombie",
	"npc_poisonzombie",
	"fas2_ifak",
	"wood",
	"wood"
}

local PositionList = {
	Vector( -3596.3, 10862.77, 291.73 ),
	Vector( -3061.3, 11878.7, 241.7 ),
	Vector( 747.33, 9737.69, 217.29 ),
	Vector( 3191.95, 8210, 160.92 ),
	Vector( 3015.4, 4523.92, -100.95 ),
	Vector( 5077.32, 1670.46, 424 ),
	Vector( 2154.65, -5177.67, 132.85 ),
	Vector( 119, -5548.38, 171 ),
	Vector( -1455.5, -1176.9, 255.2 ),
	Vector( -5044.8, -3646.4, 184 ),
	Vector( -4171.25, 1539.9, 178.48 ),
	Vector( -6270, 6383, 553.24 ),
	Vector( -6601.2, 9189.27, 149 ),
	Vector( -5485, -2936.7, 190.7 ),
	Vector(  -5964.5, 124.76, 232.28 ),
	Vector(  -7878.7, 3079.2, 191.4 ),
	Vector(  -4359.75, 5983.86, 220.62 ),
	Vector(  -1182.29, 9108, 279 ),
	Vector(  3582.5, 9790.5, 217.43 ),
	Vector(  -5482, 5602, 208.62 ),
	Vector(  -2399.59, -710.14, 227.42 ),
	Vector(  1707.39, 2892.89, 187.7 ),
	Vector(  5675.7, 4391.2, 170 )
	//
}

local offset = Vector(0,0,-20)


hook.Add( "InitPostEntity", "initpostent123", function()
 timer.Create("entity_spawns",  math.random(120,300), 0, function()

for _, pos in pairs( PositionList ) do
	local ent = ents.Create( EntityList[math.random(#EntityList)])
	ent:SetPos( pos )
	ent:SetAngles( Angle( 0, 0, 0 ) )
	ent:DropToFloor()
	ent:Spawn()
	print("Spawning Entities")
	end
end)
end)


hook.Add( "PlayerSay", 0, function( ply, text, team )
	if (ply:IsUserGroup("owner") and (string.sub(text, 1, 12) == "/addentspawn")) then
		table.insert( PositionList, table.Count( PositionList ) + 1, Vector( ply:GetPos() ) )
		print( "Position: " .. ply:GetPos() .. " added" )
	end
end)

-bump-

I believe you don’t have to do the second parameter for table.insert , just use the two.

I tried the halo.add then my screen turns 100% black on my server when I try it.

Yeah, stencils will do that sometimes. Try DynamicLight() Maybe?

You did it wrong then.

Well it doesn’t give me a black screen anymore but here is my code
I put it in lua/autorun/client
I was only using the entity “wood” for this to test and it’s still not working


local haloitems = ents.FindByClass("wood")



hook.Add( "PreDrawHalos", "AddHalos", function()
	timer.Create("halo_add", 5, 0, function()
	halo.Add( haloitems, Color( 255, 0, 0 ), 5, 5, 2)
end )
end)



local haloitems = {}

hook.Add( "PreDrawHalos", "AddHalos", function()
         for k,ent in pairs(ents.FindByClass("wood")) do
table.insert( haloitems, ent )
end
halo.Add( haloitems, Color( 255, 0, 0 ), 5, 5, 2)
end)

Try that.

Well that did work, but when the entities spawn there is massive lag, I’m guessing it’s because they all render at once.
So would there be a way to make it so it only renders the closest one to the player?

Make it only render if its within like 1000 hammer units. That should only bring it up if your within a close range.

How would I go about doing that?

-bump-

No need to bump so soon; but just do a distance comparison. If this is done client-side, which it should be, then do a test with the entity like so inside the loop before it adds it to the table:

[lua]if ( LocalPlayer( ):GetPos( ):Distance( ent:GetPos( ) > 1000 ) then continue; end[/lua]

Well now it glows only when I spawn it directly on me, when the ones spawn in the map and I walk up to them, it doesn’t do it. Here is the code


local haloitems = {}

timer.Create("refresh_halo", 1, 0, function()
hook.Add( "PreDrawHalos", "AddHalos", function()

  for k,ent in pairs( ents.FindByClass("wood") ) do
table.insert( haloitems, ent )
  if ( LocalPlayer( ):GetPos( ):Distance( ent:GetPos( ) ) > 500 )then return end
end

  for k,ent in pairs( ents.FindByClass("spring") ) do
table.insert( haloitems, ent )
  if ( LocalPlayer( ):GetPos( ):Distance( ent:GetPos( ) ) > 500  ) then return end
end

  for k,ent in pairs( ents.FindByClass("wrench") ) do
table.insert( haloitems, ent )
  if ( LocalPlayer( ):GetPos( ):Distance( ent:GetPos( )  ) > 500  ) then return end
end

  for k,ent in pairs( ents.FindByClass("ironbar") )  do
table.insert( haloitems, ent )
  if ( LocalPlayer( ):GetPos( ):Distance( ent:GetPos( ) ) > 500  ) then return end
end


halo.Add(haloitems, Color(0, 220, 0), 4, 4, 2, true, false)
end)
end)

Do not use a timer to re-do the hook every second, it’s not needed.

You’re only looking at the first entity each time; use continue instead of return; continue skips the current item in the list and lets the look “continue” to the next element in the list. return ends the function. Additionally, you need to insert it into the table AFTER the distance check, otherwise it would always be inserted.

Something like this should work, untested:


local function addHaloEnts( _table, _entClass )
	for k, ent in pairs( ents.FindByClass( _entClass ) ) do
		// If it's over 500 units away then skip to the next element in the list
		if ( LocalPlayer( ):GetPos( ):Distance( ent:GetPos( ) ) > 500 )then continue; end

		// Only insert into the table if it's less than or equal to 500
		table.insert( _table, ent );
	end

	return _table;
end

hook.Add( "PreDrawHalos", "AddHalos", function()
	local haloitems = { };
	haloitems = addHaloEnts( haloitems, "wood" );
	haloitems = addHaloEnts( haloitems, "spring" );
	haloitems = addHaloEnts( haloitems, "wrench" );
	haloitems = addHaloEnts( haloitems, "ironbar" );

	halo.Add( haloitems, Color( 0, 220, 0 ), 4, 4, 2, true, false );
end );

Finally it works, THANK YOU SOO MUCH :smiley: