Advertisement
Guest User

Laggiest element v2

a guest
Dec 14th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 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. function set_pressure(x, y, pres)
  15. sim.pressure(math.floor(x/4), math.floor(y/4), pres)
  16. end
  17. function get_pressure(x, y)
  18. return sim.pressure(math.floor(x/4), math.floor(y/4))
  19. end
  20.  
  21. local function lag_update(i,x,y,s,nt)
  22. local mytmp = math.huge --sim.partProperty(i, sim.FIELD_TMP)
  23. local target = sim.partProperty(i, sim.FIELD_LIFE)
  24. local flags = sim.partProperty(i, sim.FIELD_TMP2)
  25. local diff = 0
  26. local mult = 0
  27. -- Energy stealing
  28. for r in sim.parts() do -- Ugly line incoming!
  29. if (sim.partProperty(r, sim.FIELD_TYPE) ~= elem.DEFAULT_PT_VIBR) and (bit.bor(flags, 4) > 0) then
  30. mytmp = mytmp + sim.partProperty(r, sim.FIELD_TMP)
  31. sim.partProperty(r, sim.FIELD_LIFE, 0)
  32. sim.partProperty(r, sim.FIELD_TMP, 0)
  33. sim.partProperty(r, sim.FIELD_TMP2, 0)
  34. sim.partProperty(r, sim.FIELD_TMP2, 0)
  35. end
  36. end
  37. -- Energy absorption
  38. if bit.bor(flags, 1) > 0 then
  39. diff = sim.partProperty(i, sim.FIELD_TEMP) - target
  40. mytmp = mytmp + math.floor(diff / 3)
  41. sim.partProperty(i, sim.FIELD_TEMP, (diff % 3) + target)
  42. end
  43. if bit.bor(flags, 2) > 0 then
  44. diff = get_pressure(x, y) - target
  45. if diff < 0 then mult = 2 else mult = 7 end
  46. mytmp = mytmp + math.floor(diff) * mult
  47. set_pressure(x, y, (diff % 1) + target)
  48. end
  49. -- Energy emission
  50. if bit.bor(flags, 8) > 0 then
  51. diff = sim.partProperty(i, sim.FIELD_TEMP) + (mytmp * 3)
  52. sim.partProperty(i, sim.FIELD_TEMP, diff)
  53. end
  54. if bit.bor(flags, 16) > 0 then
  55. if mytmp < 0 then mult = 2 else mult = 7 end
  56. diff = get_pressure(x, y) + (mytmp / mult)
  57. set_pressure(x, y, diff)
  58. end
  59. if bit.bor(flags, 32) > 0 then
  60. diff = math.floor(mytmp / 20)
  61. mytmp = mytmp % 20
  62. for i=1,diff,1 do
  63. sim.partCreate(-3, x, y, i % 256)
  64. end
  65. end
  66. end
  67.  
  68. -- Apply update function
  69. elements.property(lag, "Update", lag_update)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement