Advertisement
nucular

RAND, SRAN, LRAN, GRAN elements

Jan 8th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.19 KB | None | 0 0
  1. -- RAND, SRAN, GRAN, LRAN elements
  2. -- by nucular, Public Domain
  3.  
  4. -- quite laggy at the moment :(
  5.  
  6. local all = {}
  7. local gasses = {}
  8. local liquids = {}
  9. local solids = {}
  10. for k,v in pairs(tpt.el) do
  11.     table.insert(all, v)
  12.  
  13.     if v.state == 1 then
  14.         table.insert(solids, v)
  15.     elseif v.state == 2 then
  16.         table.insert(liquids, v)
  17.     elseif v.state == 3 then
  18.         table.insert(gasses, v)
  19.     end
  20. end
  21.  
  22. local function choice(t)
  23.     return t[math.random(1, #t)]
  24. end
  25.  
  26. local function randProp(id)
  27.     tpt.parts[id].ctype = choice(all).id
  28.     tpt.parts[id].life = math.random(0, 655)
  29.     tpt.parts[id].tmp = math.random(0, 655)
  30.     tpt.parts[id].tmp2 = math.random(0, 655)
  31.     tpt.parts[id].vx = math.random(-10, 10)
  32.     tpt.parts[id].vy = math.random(-10, 10)
  33.     tpt.parts[id].temp = math.random(0, 655)
  34. end
  35.  
  36. local RAND = elem.allocate("RANDOM", "RAND")
  37. elem.element(RAND, elem.element(elem.DEFAULT_PT_DMND))
  38. elem.property(RAND, "Name", "RAND")
  39. elem.property(RAND, "Colour", 0xFFFFFFFF)
  40. elem.property(RAND, "Description", "Explodes into a random element")
  41. elem.property(RAND, "MenuSection", elem.SC_SPECIAL)
  42. elem.property(RAND, "HighTemperature", 10000)
  43. elem.property(RAND, "LowTemperature", -1)
  44. tpt.element_func(
  45.     function(i,x,y)
  46.         for k,j in ipairs(sim.partNeighbours(x, y, 1, 1)) do
  47.             if j then
  48.                 local t = tpt.parts[j].type
  49.                 if t == elem.DEFAULT_PT_FIRE or t == elem.DEFAULT_PT_PLSM or
  50.                         (t == RAND and tpt.parts[j].life > 10 and tpt.parts[i].life == 0) then
  51.                     tpt.parts[i].life = 50 + math.random(0, 60)
  52.                 end
  53.             end
  54.         end
  55.        
  56.         if tpt.parts[i].life == 1 then
  57.             sim.partChangeType(i, choice(all).id)
  58.             randProp(i)
  59.         elseif tpt.parts[i].life > 1 then
  60.             tpt.parts[i].life = tpt.parts[i].life - 1
  61.         end
  62.     end, RAND
  63. )
  64.  
  65. local SRAN = elem.allocate("RANDOM", "SRAN")
  66. elem.element(SRAN, elem.element(elem.DEFAULT_PT_DUST))
  67. elem.property(SRAN, "Name", "SRAN")
  68. elem.property(SRAN, "Colour", 0xFFFFFFFF)
  69. elem.property(SRAN, "Description", "Explodes into a random solid or powder")
  70. elem.property(SRAN, "MenuSection", elem.SC_SPECIAL)
  71. elem.property(SRAN, "HighTemperature", 10000)
  72. elem.property(SRAN, "LowTemperature", -1)
  73. tpt.element_func(
  74.     function(i,x,y)
  75.         for k,j in ipairs(sim.partNeighbours(x, y, 1, 1)) do
  76.             if j then
  77.                 local t = tpt.parts[j].type
  78.                 if t == elem.DEFAULT_PT_FIRE or t == elem.DEFAULT_PT_PLSM or
  79.                         (t == SRAN and tpt.parts[j].life > 10 and tpt.parts[i].life == 0) then
  80.                     tpt.parts[i].life = 50 + math.random(0, 60)
  81.                 end
  82.             end
  83.         end
  84.        
  85.         if tpt.parts[i].life == 1 then
  86.             sim.partChangeType(i, choice(solids).id)
  87.             randProp(i)
  88.         elseif tpt.parts[i].life > 1 then
  89.             tpt.parts[i].life = tpt.parts[i].life - 1
  90.         end
  91.     end, SRAN
  92. )
  93.  
  94. local GRAN = elem.allocate("RANDOM", "GRAN")
  95. elem.element(GRAN, elem.element(elem.DEFAULT_PT_FOG))
  96. elem.property(GRAN, "Name", "GRAN")
  97. elem.property(GRAN, "Colour", 0xFFFFFFFF)
  98. elem.property(GRAN, "Description", "Explodes into a random gas")
  99. elem.property(GRAN, "MenuSection", elem.SC_SPECIAL)
  100. elem.property(GRAN, "HighTemperature", 10000)
  101. elem.property(GRAN, "LowTemperature", -1)
  102. tpt.element_func(
  103.     function(i,x,y)
  104.         for k,j in ipairs(sim.partNeighbours(x, y, 1, 1)) do
  105.             if j then
  106.                 local t = tpt.parts[j].type
  107.                 if t == elem.DEFAULT_PT_FIRE or t == elem.DEFAULT_PT_PLSM or
  108.                         (t == GRAN and tpt.parts[j].life > 10 and tpt.parts[i].life == 0) then
  109.                     tpt.parts[i].life = 50 + math.random(0, 60)
  110.                 end
  111.             end
  112.         end
  113.        
  114.         if tpt.parts[i].life == 1 then
  115.             sim.partChangeType(i, choice(gasses).id)
  116.             randProp(i)
  117.         elseif tpt.parts[i].life > 1 then
  118.             tpt.parts[i].life = tpt.parts[i].life - 1
  119.         end
  120.     end, GRAN
  121. )
  122.  
  123. local LRAN = elem.allocate("RANDOM", "LRAN")
  124. elem.element(LRAN, elem.element(elem.DEFAULT_PT_WATR))
  125. elem.property(LRAN, "Name", "LRAN")
  126. elem.property(LRAN, "Colour", 0xFFFFFFFF)
  127. elem.property(LRAN, "Description", "Explodes into a random liquid")
  128. elem.property(LRAN, "MenuSection", elem.SC_SPECIAL)
  129. elem.property(LRAN, "HighTemperature", 10000)
  130. elem.property(LRAN, "LowTemperature", -1)
  131. tpt.element_func(
  132.     function(i,x,y)
  133.         for k,j in ipairs(sim.partNeighbours(x, y, 1, 1)) do
  134.             if j then
  135.                 local t = tpt.parts[j].type
  136.                 if t == elem.DEFAULT_PT_FIRE or t == elem.DEFAULT_PT_PLSM or
  137.                         (t == LRAN and tpt.parts[j].life > 10 and tpt.parts[i].life == 0) then
  138.                     tpt.parts[i].life = 50 + math.random(0, 60)
  139.                 end
  140.             end
  141.         end
  142.        
  143.         if tpt.parts[i].life == 1 then
  144.             sim.partChangeType(i, choice(liquids).id)
  145.             randProp(i)
  146.         elseif tpt.parts[i].life > 1 then
  147.             tpt.parts[i].life = tpt.parts[i].life - 1
  148.         end
  149.     end, LRAN
  150. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement