So, i've been working on a little exploding melon mine for my TTT server. I came across an issue with tracers, as it seems to not see the world in its trace sometimes. Did garry change how traces work?
here's my code:
[lua]
---Ran in ent:Think()
for k, v in pairs(player.GetAll()) do
if not self.GoingOff and not v:IsTraitor() and v:Alive() then
local pl = v:GetPos()
local en = self:GetPos()
local prox = math.Distance( pl.x, pl.y, en.x, en.y )
local tracedata = {}
tracedata.start = pl
tracedata.endpos = self.Entity:GetPos()
tracedata.filter = v:GetPos()
local trace = util.TraceLine(tracedata)
if !trace.HitWorld and trace.HitNonWorld then
if self.Proximity >= prox and !v:IsTraitor() and v:Alive() then
self:SetExplodeTime(CurTime() + self.ExplosionDelay)
self.GoingOff = true
end
else
return
end
end
end
[/lua]
Can anyone enlighten me on what i'm doing wrong, or a way to do this a bit better?
edit: i'm terrible at explaining things. The specific issue i've found is that the mine will return that there is no world hit between the ent and player, even when there's a wall there.
tracedata.filter = self
[QUOTE=Archemyde;40716948]if not self.GoingOff and not v:IsTraitor() and v:Alive() then[/lua][/QUOTE]
ply:Alive() returns true for people in the Spectator team, that might cause issues later
It's better to use ply:IsTerror() and ply:IsSpec()
As brandon said, the filter should be an entity or table of entities, and not a vector
You might also want to look into setting tracedata.mask [url]http://wiki.garrysmod.com/page/Enums/MASK[/url] but I don't think that's your issue
[lua]
for k, v in pairs(player.GetAll()) do
if not self.GoingOff and not v:IsTraitor() and not v:IsSpec() then
local pl = v:GetPos()
local en = self:GetPos()
local prox = math.Distance( pl.x, pl.y, en.x, en.y )
local tracedata = {}
tracedata.start = pl
tracedata.endpos = self.Entity:GetPos()
tracedata.filter = self
local trace = util.TraceLine(tracedata)
if !trace.HitWorld then
self.Owner:ChatPrint("No wall collision!")
if self.Proximity >= prox and !v:IsTraitor() and !v:IsSpec() then
self:SetExplodeTime(CurTime() + self.ExplosionDelay)
self.GoingOff = true
self.Owner:ChatPrint("Explode!")
end
else
self.Owner:ChatPrint("Hit wall!")
return
end
end
end
[/lua]
Outputs seemingly random things.
Sometimes it hits the world, sometimes it doesnt - even if its in a sealed room surrounded by walls.
For tracedata you shold use tracedata.mask ( 32 bit integer with flags ) to tell the trace what to hit ...
[code]
tracedata.mask = MASK_SOLID // For example ...
[/code]
it's .mask but yeah.
If you don't specify the mask it assumes all though, which is usually enough.
[QUOTE=JetBoom;43556661]it's .mask but yeah.[/QUOTE]
I am not so sure about that ....
[url]http://wiki.garrysmod.com/page/Structures/Trace[/url]
[QUOTE=dvd_video;43569518]I am not so sure about that ....
[url]http://wiki.garrysmod.com/page/Structures/Trace[/url][/QUOTE]
The first column is type, not member name.
[QUOTE=Robotboy655;43569541]The first column is type, not member name.[/QUOTE]
Saw it :) My bad ( fixed it, my eyes are like cakes whth that much programming at work ... ) , but still masks are awseome !
Here is a link for that kinda old but decent
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index5636.html[/url]
Sorry, you need to Log In to post a reply to this thread.