ENT:Touch with certain Distance?

Hello guys,

I’m trying to make, if a player touch an entity, then remove it. and it’s working just fine!

But i wonder if it possible to make if the player distance is >= 100 from the Entity then run the: ENT:Touch

[lua]
function ENT:Touch( entity )

   if entity:IsPlayer() then
   entity:SetNWBool("Ball_Touched",true)
   end

	
print("Touched!")
self:EmitSound( "ambient/explosions/explode_" .. math.random( 1, 9 ) .. ".wav" )
self:Remove()

end
[/lua]

[lua]hook.Add(“KeyPress”,“barfing in my skin”,function(ply, key)
if key == IN_USE then
local tr = ply:GetEyeTrace()
local ent = tr.Entity
if IsValid(ent) && ent:GetClass() == “MyEntityClassHere” && ply:EyePos():Distance(tr.HitPos) >= 100 then
ent:Use()
end
end
end)[/lua]

[editline]22nd July 2015[/editline]

may have issues with code attempting to run twice on Use given these strange circumstances

consider running the code you want outside of the entity’s regular touch function since you don’t want to be able to ‘use’ it up close?

Thanks for your fast answer!

I want that the Player can touch the entity from a far distance without using the: USE key!