Advertisement
captmicro

Untitled

Jan 3rd, 2013
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. local CheckPlysPitch = function(set, pitch)
  2.     local OKs = {}
  3.     if set == nil then
  4.         set = {}
  5.         for i=0,32-1 do
  6.             table.insert(set, i)
  7.         end
  8.     end
  9.     for _,i in pairs(set) do
  10.         local p,y,r = Player.m_angRotation(GetEntity(i))
  11.         WriteConsole("Index#"..tostring(i).." -> Pitch " .. tostring(p) .. "deg\n")
  12.         if pitch < 0 then
  13.             if p < pitch then table.insert(OKs, i) end
  14.         else
  15.             if p > pitch then table.insert(OKs, i) end
  16.         end
  17.     end
  18.     return OKs
  19. end
  20.  
  21. local FindPlayerRecursive = function(down, ang, OKs)
  22.     WriteConsole("\tPlease look "
  23.         .. (down and "DOWN under " or "UP over ")
  24.         .. tostring(ang) .. " degrees. Press SPACE to continue.\n")
  25.     while (not IsKeyDown(VK_SPACE)) do end
  26.     local passed = CheckPlysPitch(OKs, ang)
  27.     if (#passed ~= 0) then
  28.         if (#passed == 1) then
  29.             localidx = passed[1]
  30.             WriteConsole("\tFound local player! Index " .. tostring(localidx) .. "\n")
  31.             recursivestopchk = 0
  32.         else
  33.             recursivestopchk = recursivestopchk + 1
  34.             if (recursivestopchk > 10) then
  35.                 localidx = -1
  36.                 recursivestopchk = 0
  37.                 WriteConsole("\tFailed to find local player!")
  38.             else
  39.                 WriteConsole("\tFound multiple indices. Retrying with smaller player set...\n")
  40.                 FindPlayerRecursive(not down, -ang, passed)
  41.             end
  42.         end
  43.     end
  44. end
  45.  
  46. --how i use it in the main loop
  47. if (localidx == -1) then
  48.     WriteConsole("Finding local player index...\n")
  49.     WriteConsole("\tDO NOT PRESS ANY KEYS IN GAME UNLESS INSTRUCTED!\n")
  50.     FindPlayerRecursive(false, -35, nil)
  51. else
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement