TPT Ruler

  • KOTOM
    17th Sep 2013 Member 0 Permalink
    My friend Alex Bond rewrote babay's tpt ruler script for me to make it more functionallu and less buggy. F4 turns ruler on or off. There are bug with Ctrl+Shift(Alt), But with only Ctrl or Shift it works greatly.
    You can delete all tpt.log strings if you need.


    ruler = {}
     
    ruler.active = false
    ruler.mouse_down = false
    ruler.rx = 0
    ruler.ry = 0
     
    local function draw()
      local mx, my =  tpt.mousex, tpt.mousey
      local x, y = sim.adjustCoords(ruler.rx,ruler.ry)
      local x1, y1 = sim.adjustCoords(mx, my)
      local str = tostring(1+math.floor(((x - x1) ^ 2 + (y - y1) ^ 2) ^ 0.5 * 100) / 100) .. "\nX=" ..
        tostring(1+math.floor(((x - x1) ^ 2) ^ 0.5 * 100) / 100) .. "\nY=" ..
        tostring(1+math.floor(((y - y1) ^ 2) ^ 0.5 * 100) / 100)
      gfx.fillRect(mx + 1,my + 1,gfx.textSize(str)+8,40,200,0,0,127) -- color 200 0 0
      gfx.drawText(mx + 5, my + 5, str, 200, 200, 200)
    end
     
    function ruler.draw()
     if ruler.active and ruler.mouse_down then
      pcall(draw)
     end
    end
     
    function ruler.key(_, key, _,event)
    -- F4 - 285
       if key == 285 and event == 1 then
            if ruler.active  == true then
                ruler.active  = false
       tpt.log("ruler off")
            else
                ruler.active = true
       tpt.log("ruler on")
            end
        end
    end
     
    function ruler.mouse(mx, my, _, event)
     if ruler.active then
      ruler.mouse_down = false
      if event == 1 then
       ruler.rx = mx
       ruler.ry = my
      end
      if event == 3 then
        ruler.mouse_down = true
      end
     end
    end
     
    tpt.register_mouseclick(ruler.mouse)
    tpt.register_keypress(ruler.key)
    tpt.register_step(ruler.draw)
     
    tpt.log("ruler loaded")


    Edit-jacob1: this formatting was very broken, fixed it
    Edited 20 times by KOTOM, Lockheedmartin, jacob1. Last: 17th Sep 2013
  • Sylvi
    17th Sep 2013 Moderator 0 Permalink

    Try adding the code into <code> tags.

  • KOTOM
    17th Sep 2013 Member 0 Permalink

    Like this? I'm noob in HTML.

  • Sylvi
    17th Sep 2013 Moderator 0 Permalink

    Like This

  • KOTOM
    17th Sep 2013 Member 0 Permalink

    I dont understand how to insert into <code></code> more than one string.