Advertisement
nucular

Particle Monitor III.I

May 19th, 2013
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.95 KB | None | 0 0
  1. -- nucular's Particle Monitor III.I
  2. -- Changes III.I
  3. -- - Fixed rounding
  4. -- Changes III
  5. -- - Works on zoom mode!!
  6. -- - Shows temperature in °C and in K!
  7. -- - Draws inside a dark box.
  8. -- - You can set the precision of temp, vx and vy.
  9.  
  10. -- Settings
  11. -- Press this key to toggle the monitor.
  12. local key = 283       -- F2
  13. local modifier = 0    -- Nothing
  14.  
  15. -- And this key to switch between verbose and compact mode.
  16. local ev_key = 284    -- F3
  17. local ev_modifier = 0 -- Nothing
  18.  
  19. local precision = 2 -- Decimal places at temp, vx, vy ...
  20.  
  21. -------------------------------------
  22. local show = true
  23. local show_everything = true
  24. local rectHeight = 137
  25.  
  26. local function lk(nr)
  27.     -- try to find out the name of an element
  28.     local is_el, el = pcall(tpt.element, nr)
  29.     if is_el == true then
  30.         return el
  31.     else
  32.         return ""
  33.     end
  34. end
  35.  
  36. local function round(nr)
  37.     local c = math.pow(10, precision)
  38.     return tostring(math.floor(nr * c) / c)
  39. end
  40.  
  41. local function draw()
  42.     local x = tpt.mousex
  43.     local y = tpt.mousey
  44.     local x, y = sim.adjustCoords(x,y)
  45.     local id = tpt.get_property('id', x, y)
  46.     local str = x .. "," .. y
  47.    
  48.     if show_everything == true then
  49.         local typ = sim.partProperty(id, 'type')
  50.         local ctype = sim.partProperty(id, 'ctype')
  51.         local temp = round(sim.partProperty(id, 'temp'))
  52.         local life = sim.partProperty(id, 'life')
  53.         local tmp = sim.partProperty(id, 'tmp')
  54.         str = str .. "\n#" .. id
  55.                   .. "\ntype: " .. typ .. " " .. lk(typ)
  56.                   .. "\nctype: " .. ctype .. " " .. lk(ctype)
  57.                   .. "\ntemp: " .. temp-273.15 .. " C (" .. temp .. " K)"
  58.                   .. "\nlife: " .. life
  59.                   .. "\ntmp: " .. tmp .. " " .. lk(tmp)
  60.     end
  61.    
  62.     local tmp2 = sim.partProperty(id, 'tmp2')
  63.     local vx = round(sim.partProperty(id, 'vx'))
  64.     local vy = round(sim.partProperty(id, 'vy'))
  65.     local dcolour = sim.partProperty(id, 'dcolour')
  66.     str = str .. "\ntmp2: " .. tmp2 .. " " .. lk(tmp2)
  67.               .. "\nvx: " .. vx
  68.               .. "\nvy: " .. vy
  69.               .. "\ndcolour: #" .. string.format("%X", dcolour)
  70.    
  71.     gfx.fillRect(12,27,gfx.textSize(str)+8,rectHeight,0,0,0,127)
  72.     gfx.drawText(16,32,str, 200, 200, 200)
  73. end
  74.    
  75. local function safedraw()
  76.     if show then
  77.         pcall(draw)
  78.     end
  79. end
  80.  
  81. local function toggle()
  82.     if show == false then
  83.         show = true
  84.     else
  85.         show = false
  86.     end
  87. end
  88.  
  89. local function hotkey(keystr, keynum, mod, evt)
  90.     if keynum == key and mod == modifier and evt == 1 then
  91.         toggle()
  92.     end
  93.     if keynum == ev_key and mod == ev_modifier and evt == 1 then
  94.         if show_everything == true then
  95.             show_everything = false
  96.             rectHeight = 65
  97.         else
  98.             show_everything = true
  99.             rectHeight = 137
  100.         end
  101.     end
  102. end
  103.  
  104. tpt.register_keypress(hotkey)
  105. tpt.register_step(safedraw)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement