CapsAdmin

Untitled

Apr 18th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. function raymond(a, b, callback, dist, filter) 
  2.     if IsEntity(a) then
  3.         a = a:EyePos()
  4.     end
  5.  
  6.     if IsEntity(b) then
  7.         b = b:EyePos()
  8.     end
  9.  
  10.     local id = "audiencelaugh" -- tostring(a) .. tostring(b)
  11.     local i = 0
  12.     local mapped = {}
  13.    
  14.     local last
  15.  
  16.     local filter = table.Merge({a,b}, filter or {})
  17.     filter = table.Merge(filter, ents.FindByClass("func_door"))
  18.    
  19.     local function random_dir(dir)
  20.         local len = dir:Length()
  21.         dir = dir:Normalize()
  22.         return LerpVector(((i%100)/100), dir, VectorRand()) * len
  23.     end
  24.  
  25.     local function line(a, b)  
  26.         local dir = random_dir(b-a)
  27.         local data = util.QuickTrace(a, dir, filter)
  28.        
  29.         debugoverlay.Line(a, data.HitPos, 5, HSVToColor(i%360, 1, 1), true)
  30.        
  31.         local pos = data.HitPos
  32.            
  33.         return pos
  34.     end
  35.        
  36.     local function iterate(a, b, i)
  37.         local pos = line(a, b, i)
  38.        
  39.         if pos:Distance(b) > (dist or 100) then
  40.             return pos
  41.         else
  42.             return false
  43.         end
  44.     end
  45.        
  46.     hook.Add("Think", id, function()
  47.         if i%100 == 1 then
  48.             print("searching...")
  49.         end
  50.            
  51.         for i2 = 0, 200 do
  52.             local pos = iterate(a, b, i)
  53.             if pos then
  54.                 if last ~= pos then
  55.                     table.insert(mapped, pos)
  56.                 end
  57.                 a = pos
  58.                 last = pos
  59.             else
  60.                 hook.Remove("Think", id)
  61.                 if callback then
  62.                     callback(mapped)
  63.                 else
  64.                     print(#mapped .. " ray's bounced")
  65.                 end
  66.                 break
  67.             end
  68.             i = i + 1 + i2
  69.         end
  70.     end)
  71. end
Advertisement
Add Comment
Please, Sign In to add comment