Guest User

A very superficial reaction, indeed

a guest
May 19th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. local function neighbours(x,y,r,type)
  2.     local array = {}
  3.     for dx=-r,r do
  4.         for dy=-r,r do
  5.             if tpt.get_property("type", x+dx, y+dy) == type then array[#array+1] = sim.partID(x+dx, y+dy) end
  6.         end
  7.     end
  8.     return array
  9. end
  10.  
  11. local ntrm = elements.allocate("ELEMENT", "NTRM")
  12.  
  13. elements.element(ntrm, elements.element(elements.DEFAULT_PT_PLUT))
  14. elements.property(ntrm, "Name", "NTRM")
  15. elements.property(ntrm, "Description", "Neutronium. Begins a chain reaction upon collision with neutrons.")
  16. elements.property(ntrm, "Colour", 0x00AAAA)
  17. elements.property(ntrm, "HighTemperature", 10001)
  18. elements.property(ntrm, "HighPressure", 257)
  19.  
  20. local function ntrmUpdate(i,x,y,s,nt)
  21.  
  22.     local clife = tpt.get_property("life", i)
  23.     local percent = 10
  24.     local parts = neighbours(x, y, 1, elements.DEFAULT_PT_NEUT)
  25.  
  26.     if clife <= 0 then
  27.         tpt.set_property("life", 3, i)
  28.     end
  29.     if clife > 0 and #parts > 0 and math.random(1, 1/(1-((1-percent/100)^(#parts)))) == 1 then
  30.         local dx = math.random(-1,1)
  31.         local dy = math.random(-1,1)
  32.         if clife == 1 then
  33.             sim.partCreate(-3, x+dx, y+dy, elements.DEFAULT_PT_NEUT)
  34.             sim.partKill(i)
  35.         else
  36.             sim.partCreate(-3, x+dx, y+dy, elements.DEFAULT_PT_NEUT)
  37.             tpt.set_property("life", clife-1, i)
  38.         end
  39.     end
  40.  
  41. end
  42.  
  43. elements.property(ntrm, "Update", ntrmUpdate)
Advertisement
Add Comment
Please, Sign In to add comment