Advertisement
Guest User

Laggiest TPT element in the WORLD!

a guest
Dec 14th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. -- LAG: Lag tester!
  2.  
  3. -- This is just an edited version of my energy converter.
  4.  
  5. -- Definition
  6. local lag = elements.allocate("lag", "lag")
  7. elements.element(lag, elements.element(elements.DEFAULT_PT_DMG))
  8. elements.property(lag, "Name", "LAG")
  9. elements.property(lag, "Colour", 0x808080) -- Boring gray
  10. elements.property(lag, "Description", "Unstoppable lag.")
  11. elements.property(lag, "MenuSection", elem.SC_SPECIAL)
  12. elements.property(lag, "Properties", elem.TYPE_SOLID)
  13.  
  14. local function lag_update(i,x,y,s,nt)
  15. local mytmp = math.huge --sim.partProperty(i, sim.FIELD_TMP)
  16. local target = sim.partProperty(i, sim.FIELD_LIFE)
  17. local flags = sim.partProperty(i, sim.FIELD_TMP2)
  18. local diff = 0
  19. local mult = 0
  20. -- Energy stealing
  21. for r in sim.parts() do -- Ugly line incoming!
  22. if (sim.partProperty(r, sim.FIELD_TYPE) ~= elem.DEFAULT_PT_VIBR) and (bit.bor(flags, 4) > 0) then
  23. mytmp = mytmp + sim.partProperty(r, sim.FIELD_TMP)
  24. sim.partProperty(r, sim.FIELD_LIFE, 0)
  25. sim.partProperty(r, sim.FIELD_TMP, 0)
  26. sim.partProperty(r, sim.FIELD_TMP2, 0)
  27. sim.partProperty(r, sim.FIELD_TMP2, 0)
  28. end
  29. end
  30. -- Energy absorption
  31. if bit.bor(flags, 1) > 0 then
  32. diff = sim.partProperty(i, sim.FIELD_TEMP) - target
  33. mytmp = mytmp + math.floor(diff / 3)
  34. sim.partProperty(i, sim.FIELD_TEMP, (diff % 3) + target)
  35. end
  36. if bit.bor(flags, 2) > 0 then
  37. diff = get_pressure(x, y) - target
  38. if diff < 0 then mult = 2 else mult = 7 end
  39. mytmp = mytmp + math.floor(diff) * mult
  40. set_pressure(x, y, (diff % 1) + target)
  41. end
  42. -- Energy emission
  43. if bit.bor(flags, 8) > 0 then
  44. diff = sim.partProperty(i, sim.FIELD_TEMP) + (mytmp * 3)
  45. sim.partProperty(i, sim.FIELD_TEMP, diff)
  46. end
  47. if bit.bor(flags, 16) > 0 then
  48. if mytmp < 0 then mult = 2 else mult = 7 end
  49. diff = get_pressure(x, y) + (mytmp / mult)
  50. set_pressure(x, y, diff)
  51. end
  52. if bit.bor(flags, 32) > 0 then
  53. diff = math.floor(mytmp / 20)
  54. mytmp = mytmp % 20
  55. for i=1,diff,1 do
  56. sim.partCreate(-3, x, y, i)
  57. end
  58. end
  59. end
  60.  
  61. -- Apply update function
  62. elements.property(lag, "Update", lag_update)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement