Problem with traces?

I’m trying to make it so my grenade doesn’t ignite things through walls.

I’ve tried a million different methods for this. Every method either ignites everything or nothing.

Here’s my code, thank you very much.

[lua]
local model = “models/wfirenade.mdl”
local classname = “grenade_fire”
local ShouldSetOwner = true
local tick = Sound(“weapons/grenade/tick1.wav”)
local glowcolor = Color(215,55,0)


AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include( “shared.lua” )

local function DetonateGrenade(ent) – Is there a better way to do this?
ent:EmitSound(tick)
local start = ent:GetPos() + Vector(0,0,3)
timer.Simple(1, function()
local effect = EffectData()
effect:SetStart(ent:GetPos())
effect:SetScale(1)
util.Effect(“firenade_explode”, effect)
ent:EmitSound(Sound(“weapons/hegrenade/explode4.wav”))

	for k, v in pairs(ents.FindInSphere(start, 250)) do
		if v != ent then 
		
			local trace = {}
			trace.startpos = start
			trace.endpos = v:GetPos() + Vector(0,0,3)
			trace.filter = {ent, v}
			local tr = util.TraceLine(trace)
			
			if v:GetClass() == "prop_physics" or v:IsNPC() or v:IsPlayer() then
				if tr.HitNonWorld then
					if v:GetClass() == "prop_physics" or v:IsNPC() then
						v:Ignite(10)
					elseif v:IsPlayer() then
						-- Special player ignite
					end
				end
			end
		end
	end
	
	ent:Remove()
end)

end

function ENT:Initialize()
util.SpriteTrail(self.Entity, 0, glowcolor, false, 4, 0, 4, 0.1, “trails/laser.vmt”)
self.Entity:SetModel( model )
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )
local phys = self.Entity:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end

self.Entity:EmitSound(tick)

timer.Simple(5, function()
	DetonateGrenade(self.Entity)
end)

end

function ENT:OnTakeDamage( dmginfo )
self.Entity:TakePhysicsDamage( dmginfo )
end

function ENT:Think()

end

local bounce_tick = CurTime()
function ENT:PhysicsCollide( data, physobj )
if data.Speed < 200 then return end
if bounce_tick < CurTime() then
bounce_tick = CurTime() + 0.5
self.Entity:EmitSound(Sound(“weapons/hegrenade/he_bounce-1.wav”))
end
end
[/lua]

For the trace, try:

[lua]mask=MASK_SHOT_HULL[/lua]

(mask being cAsE sEnSiTiVe) :smiley:

That still makes it so they are ignited through walls.
Thanks though

[editline]12th June 2012[/editline]

Holy shit, I found out the error.

I was defining “Start” one second before the trace.

I can’t believe I was so stupid lol

[editline]12th June 2012[/editline]

Aww fuck. That doesn’t seem to fix it like I thought it did. Still need help.
Updated code:
[lua]
local model = “models/wfirenade.mdl”
local classname = “grenade_fire”
local ShouldSetOwner = true
local tick = Sound(“weapons/grenade/tick1.wav”)
local glowcolor = Color(215,55,0)


AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include( “shared.lua” )

local function DetonateGrenade(ent) – Is there a better way to do this?
ent:EmitSound(tick)

timer.Simple(1, function()
	local start = ent:GetPos() + Vector(0,0,3)
	local effect = EffectData()
	effect:SetStart(ent:GetPos())
	effect:SetScale(1)
	util.Effect("firenade_explode", effect)
	ent:EmitSound(Sound("weapons/hegrenade/explode4.wav"))
	
	for k, v in pairs(ents.FindInSphere(start, 250)) do
		if v != ent then 
			if v:GetClass() == "prop_physics" or v:IsNPC() or v:IsPlayer() then
				local trace = {}
				trace.startpos = start
				trace.endpos = v:GetPos() + Vector(0,0,3)
				trace.filter = {ent, v}
				local tr = util.TraceLine(trace)
				if tr.HitNonWorld or not tr.Hit then
					if v:GetClass() == "prop_physics" or v:IsNPC() then
						v:Ignite(10)
					elseif v:IsPlayer() then
						-- Special player ignite
					end
				end
			end
		end
	end
	
	ent:Remove()
end)

end

function ENT:Initialize()
util.SpriteTrail(self.Entity, 0, glowcolor, false, 4, 0, 4, 0.1, “trails/laser.vmt”)
self.Entity:SetModel( model )
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )
local phys = self.Entity:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end

self.Entity:EmitSound(tick)

timer.Simple(5, function()
	DetonateGrenade(self.Entity)
end)

end

function ENT:OnTakeDamage( dmginfo )
self.Entity:TakePhysicsDamage( dmginfo )
end

function ENT:Think()

end

local bounce_tick = CurTime()
function ENT:PhysicsCollide( data, physobj )
if data.Speed < 200 then return end
if bounce_tick < CurTime() then
bounce_tick = CurTime() + 0.5
self.Entity:EmitSound(Sound(“weapons/hegrenade/he_bounce-1.wav”))
end
end
[/lua]