Advertisement
captmicro

Walkbot v1.6

Oct 3rd, 2010
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.18 KB | None | 0 0
  1. local walkbot = {LEFT = -1, RIGHT = 1}
  2.  
  3. walkbot.WalkKey = KEY_B
  4. walkbot.MinWallDistance = 200
  5. walkbot.DefaultStepMult = walkbot.LEFT
  6. walkbot.StepDegrees = 15
  7. walkbot.ThreeWallMult = 15 --180 / walkbot.StepDegrees
  8. walkbot.Debug = false
  9.  
  10. walkbot.lp = LocalPlayer()
  11. walkbot.walking = false
  12. walkbot.ct = {mask = MASK_PLAYERSOLID}
  13. walkbot.tr = nil
  14. walkbot.td = nil
  15.  
  16. walkbot.DrawLine = function(tr)
  17.     if (tr.Hit) then surface.SetDrawColor(0,255,0,255)
  18.     else surface.SetDrawColor(255,0,0,255) end
  19.     local start2d = tr.StartPos:ToScreen()
  20.     local hit2d = tr.HitPos:ToScreen()
  21.     surface.DrawLine(start2d.x, start2d.y, hit2d.x, hit2d.y)
  22. end
  23.  
  24. walkbot.GetTurnDir = function()
  25.     local leftt = {mask = MASK_PLAYERSOLID}
  26.     leftt.start = walkbot.lp:GetPos()
  27.     local leftv = Angle(0,walkbot.lp:EyeAngles().y + 90,0):Forward()
  28.     leftt.endpos = leftt.start + (leftv * walkbot.MinWallDistance)
  29.     leftt.filter = walkbot.lp
  30.     local lefttr = util.TraceLine(leftt)
  31.     if (walkbot.Debug) then walkbot.DrawLine(lefttr) end
  32.    
  33.     local rightt = {mask = MASK_PLAYERSOLID}
  34.     rightt.start = walkbot.lp:GetPos()
  35.     local rightv = Angle(0,walkbot.lp:EyeAngles().y - 90,0):Forward()
  36.     rightt.endpos = rightt.start + (rightv * walkbot.MinWallDistance)
  37.     rightt.filter = walkbot.lp
  38.     local righttr = util.TraceLine(rightt)
  39.     if (walkbot.Debug) then walkbot.DrawLine(righttr) end
  40.    
  41.     if (lefttr.Hit and righttr.Hit) then
  42.         return walkbot.ThreeWallMult
  43.     elseif (lefttr.Hit) then
  44.         RunConsoleCommand("+moveright")
  45.         timer.Simple(walkbot.MinWallDistance/1000,
  46.             RunConsoleCommand, "-moveright")
  47.         return walkbot.RIGHT
  48.     elseif (righttr.Hit) then
  49.         RunConsoleCommand("+moveleft")
  50.         timer.Simple(walkbot.MinWallDistance/1000,
  51.             RunConsoleCommand, "-moveleft")
  52.         return walkbot.LEFT
  53.     end
  54.    
  55.     return walkbot.DefaultStepMult
  56. end
  57.  
  58. walkbot.main = function()
  59.     if (input.IsKeyDown(walkbot.WalkKey)) then
  60.         walkbot.GetTurnDir() //FIX WALL DISTANCE
  61.         walkbot.ct.start = walkbot.lp:EyePos()
  62.         walkbot.ct.endpos = walkbot.ct.start + (walkbot.lp:EyeAngles():Forward() * 16384)
  63.         walkbot.ct.filter = walkbot.lp
  64.         walkbot.tr = util.TraceLine(walkbot.ct)
  65.         if (walkbot.Debug) then walkbot.DrawLine(walkbot.tr) end
  66.         if (walkbot.tr.Hit) then
  67.             walkbot.td = walkbot.tr.StartPos:Distance(walkbot.tr.HitPos)
  68.             if (walkbot.td <= walkbot.MinWallDistance) then
  69.                 if (walkbot.walking) then RunConsoleCommand("-forward") end
  70.                 walkbot.lp:SetEyeAngles(walkbot.lp:EyeAngles() -
  71.                     Angle(0,walkbot.StepDegrees*walkbot.GetTurnDir(),0))
  72.             else
  73.                 RunConsoleCommand("+forward")
  74.                 walkbot.walking = true
  75.             end
  76.         end
  77.         if (input.IsKeyDown(KEY_DELETE)) then
  78.             hook.Remove("HUDPaint", "walkbot.main")
  79.             RunConsoleCommand("-forward")
  80.             walkbot = nil
  81.         end
  82.     elseif (walkbot.walking) then
  83.         RunConsoleCommand("-forward")
  84.         walkbot.walking = false
  85.     end
  86. end
  87. hook.Add("HUDPaint", "walkbot.main", walkbot.main)
  88.  
  89. print([[    __  ____                _    ___   ______________
  90.    /  |/  (_)______________| |  / / | / / ____/_  __/
  91.   / /|_/ / // ___/ ___/ __ \ | / /  |/ / __/   / /  
  92.  / /  / / // /__/ /  / /_/ / |/ / /|  / /___  / /    
  93. /_/  /_/_/ \___/_/   \____/|___/_/ |_/_____/ /_/     ]])
  94. print("====================WalkBot v1.6=====================")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement