Guest User

tpt ruler

a guest
Aug 8th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. ruler = {}
  2.  
  3.  
  4. ruler.active = false
  5. ruler.aHeld = false
  6. ruler.rx = 0
  7. ruler.ry = 0
  8.  
  9. function ruler.draw()
  10.     if ruler.active then
  11.         local mx, my =  tpt.mousex, tpt.mousey
  12.         tpt.drawline(ruler.rx - 2, ruler.ry, ruler.rx + 2, ruler.ry, 255, 255, 255, 127)
  13.         tpt.drawline(ruler.rx, ruler.ry - 2, ruler.rx, ruler.ry + 2, 255, 255, 255, 127)
  14.         if ruler.aHeld then
  15.             tpt.drawline(ruler.rx, ruler.ry, mx, my, 49, 193, 226, 95)
  16.         end
  17.         tpt.drawtext(mx + 11, my + 11, tostring(math.floor(((ruler.rx - mx) ^ 2 + (ruler.ry - my) ^ 2) ^ 0.5 * 100) / 100), 49, 193, 226, 159)
  18.     end
  19. end
  20.  
  21. function ruler.key(char, _, _,event)
  22.     if char == "a" then
  23.         ruler.aHeld = event == 1
  24.     end
  25. end
  26.  
  27. function ruler.mouse(mx, my, _, e)
  28.     if e == 1 then
  29.         if not ruler.active then
  30.             if ruler.aHeld then
  31.                 ruler.active = true
  32.                 ruler.rx = mx
  33.                 ruler.ry = my
  34.                 return false
  35.             end
  36.         else
  37.             ruler.active = false
  38.             return false
  39.         end
  40.     end
  41. end
  42.  
  43.  
  44. tpt.register_mouseclick(ruler.mouse)
  45. tpt.register_keypress(ruler.key)
  46. tpt.register_step(ruler.draw)
  47.  
  48. tpt.log("ruler loaded")
Advertisement
Add Comment
Please, Sign In to add comment