Advertisement
TPT_PL

The Power Toy

May 27th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.88 KB | None | 0 0
  1. local dynamite = elem.allocate("MOD", "DNMT")
  2. local blackpd = elem.allocate("MOD", "BPDR")
  3. local phosphor = elem.allocate("MOD", "PHOS")
  4.  
  5. elem.element(dynamite, elem.element(tpt.element("c-4")))
  6. elem.property(dynamite, "Name", "DNMT")
  7. elem.property(dynamite, "Description", "Dynamite, very strong crushing explosive.")
  8. elem.property(dynamite, "Flammable", 0)
  9. elem.property(dynamite, "Explosive", 0)
  10. elem.property(dynamite, "Color", 0xFF6666)
  11.  
  12. local function dnmtUpdate(i, x, y, s, nt)
  13.     if s ~= 8 and nt ~= 0 then
  14.         for r in sim.neighbors(x, y, 1, 1) do
  15.             if sim.partProperty(r, "temp") > 673.15 or (sim.partProperty(r, "type") == elem.DEFAULT_PT_FIRE or sim.partProperty(r, "type") == elem.DEFAULT_PT_PLSM) then
  16.                 sim.partKill(i)
  17.                 sim.partCreate(-1, x, y, elem.DEFAULT_PT_FIRE)
  18.                 sim.pressure(x/4, y/4, sim.pressure(x/4, y/4)+1.2)
  19.                 return 1
  20.             end
  21.         end
  22.     end
  23.     if sim.partProperty(i, "temp") > 673.15 then
  24.         sim.partKill(i)
  25.         sim.partCreate(-1, x, y, elem.DEFAULT_PT_FIRE)
  26.         sim.pressure(x/4, y/4, sim.pressure(x/4, y/4)+1.2)
  27.         return 1
  28.     end
  29. end
  30.  
  31. elem.property(dynamite, "Update", dnmtUpdate)
  32.  
  33. elem.element(blackpd, elem.element(tpt.element("gun")))
  34. elem.property(blackpd, "Name", "BPDR")
  35. elem.property(blackpd, "Description", "Black powder, explosive. Much stronger than gunpowder.")
  36. elem.property(blackpd, "Flammable", 0)
  37. elem.property(blackpd, "Explosive", 0)
  38. elem.property(blackpd, "Color", 0x555555)
  39.  
  40. local function bpdrUpdate(i, x, y, s, nt)
  41.     if s ~= 8 and nt ~= 0 then
  42.         for r in sim.neighbors(x, y, 1, 1) do
  43.             local rtype = sim.partProperty(r, "type")
  44.             if sim.partProperty(r, "temp") > 673.15 or (rtype == elem.DEFAULT_PT_FIRE or rtype == elem.DEFAULT_PT_PLSM) then
  45.                 sim.partKill(i)
  46.                 if math.random(1, 15) ~= 1 then
  47.                     sim.partCreate(-1, x, y, elem.DEFAULT_PT_FIRE)
  48.                 else
  49.                     sim.partCreate(-1, x, y, elem.DEFAULT_PT_EMBR)
  50.                 end
  51.                 sim.pressure(x/4, y/4, sim.pressure(x/4, y/4)+0.5)
  52.                 return 1
  53.             elseif rtype == elem.DEFAULT_PT_CLST then
  54.                 if math.random(0, 1) == 0 then
  55.                     sim.partChangeType(r, dynamite)
  56.                 else
  57.                     sim.partChangeType(i, dynamite)
  58.                     return 1
  59.                 end
  60.             end
  61.         end
  62.     end
  63.     if sim.partProperty(i, "temp") > 673.15 then
  64.         sim.partKill(i)
  65.         if math.random(1, 15) ~= 1 then
  66.             sim.partCreate(-1, x, y, elem.DEFAULT_PT_FIRE)
  67.         else
  68.             sim.partCreate(-1, x, y, elem.DEFAULT_PT_EMBR)
  69.         end
  70.         sim.pressure(x/4, y/4, sim.pressure(x/4, y/4)+0.5)
  71.         return 1
  72.     end
  73. end
  74.  
  75. elem.property(blackpd, "Update", bpdrUpdate)
  76.  
  77. elem.element(phosphor, elem.element(elem.DEFAULT_PT_BCOL))
  78. elem.property(phosphor, "Name", "PHOS")
  79. elem.property(phosphor, "Description", "Phosphorus, glows for a short while when ignited.")
  80. elem.property(phosphor, "Color", 0x880000)
  81. elem.property(phosphor, "MenuSection", elem.SC_EXPLOSIVE)
  82. elem.property(phosphor, "Properties", elem.PROP_DEADLY+elem.PROP_LIFE_DEC)
  83.  
  84. local function phosUpdate(i, x, y, s, nt)
  85.     if sim.partProperty(i, "tmp") == 1 and sim.partProperty(i, "life") <= 0 then
  86.         sim.partKill(i)
  87.         sim.partCreate(-1, x, y, elem.DEFAULT_PT_FIRE)
  88.         return 1
  89.     end
  90.     local r = sim.partID(math.random(x-1, x+1), math.random(y-1, y+1))
  91.     if r ~= nil then
  92.         local rtype = sim.partProperty(r, "type")
  93.         if (rtype == elem.DEFAULT_PT_FIRE or rtype == elem.DEFAULT_PT_PLSM or (rtype == phosphor and sim.partProperty(r, "tmp") == 1)) and sim.partProperty(i, "tmp") ~= 1 then
  94.             sim.partProperty(i, "tmp", 1)
  95.             sim.partProperty(i, "life", 100)
  96.         end
  97.     end
  98.     if sim.partProperty(i, "temp") >= 673.15 and sim.partProperty(i, "tmp") ~= 1 then
  99.         sim.partProperty(i, "tmp", 1)
  100.         sim.partProperty(i, "life", 100)
  101.     end
  102. end
  103.  
  104. local function phosGraphics(i, colr, colg, colb)
  105.     if sim.partProperty(i, "tmp") == 1 then
  106.         return 0, ren.PMODE_FLAT+ren.PMODE_FLARE+ren.FIRE_ADD, 125, 255, 125, 125, 125, 127, 63, 63
  107.     end
  108. end
  109.  
  110. elem.property(phosphor, "Update", phosUpdate)
  111. elem.property(phosphor, "Graphics", phosGraphics)
  112.  
  113. local organic = elem.allocate("MOD", "ORGM")
  114. local biogas = elem.allocate("MOD", "BIOG")
  115. local biofuel = elem.allocate("MOD", "BFUL")
  116.  
  117. elem.element(organic, elem.element(elem.DEFAULT_PT_DUST))
  118. elem.property(organic, "Name", "ORGM")
  119. elem.property(organic, "Description", "Organic matter, decomposes into biogas at high temperatures.")
  120. elem.property(organic, "Color", 0x333300)
  121. elem.property(organic, "Flammable", 20)
  122. elem.property(organic, "Weight", 80)
  123. elem.property(organic, "MenuSection", elem.SC_POWDER)
  124.  
  125. elem.element(biogas, elem.element(elem.DEFAULT_PT_BOYL))
  126. elem.property(biogas, "Name", "BIOG")
  127. elem.property(biogas, "Description", "Biogas, made from organic matter.")
  128. elem.property(biogas, "Temperature", 573.15)
  129. elem.property(biogas, "Color", 0x669900)
  130. elem.property(biogas, "Diffusion", 0.5)
  131. elem.property(biogas, "Flammable", 80)
  132. elem.property(biogas, "LowTemperature", 473.15)
  133. elem.property(biogas, "LowTemperatureTransition", biofuel)
  134.  
  135. elem.element(biofuel, elem.element(elem.DEFAULT_PT_DESL))
  136. elem.property(biofuel, "Name", "BFUL")
  137. elem.property(biofuel, "Description", "Biofuel, liquefied and more flammable version of biogas.")
  138. elem.property(biofuel, "Color", 0x264D00)
  139. elem.property(biofuel, "Flammable", 20)
  140. elem.property(biofuel, "Explosive", 1)
  141. elem.property(biofuel, "HighTemperature", 473.15)
  142. elem.property(biofuel, "HighTemperatureTransition", biogas)
  143.  
  144. local function orgmUpdate(i, x, y, s, nt)
  145.     if sim.partProperty(i, "temp") >= 1000 then
  146.         if sim.pressure(x/4, y/4) >= 1 then
  147.             if math.random(1, 200) == 1 then
  148.                 sim.partChangeType(i, biogas)
  149.             end
  150.         else
  151.             if math.random(1, 1000) == 1 then
  152.                 sim.partChangeType(i, biogas)
  153.             end
  154.         end
  155.     end
  156. end
  157.  
  158. elem.property(organic, "Update", orgmUpdate)
  159.  
  160. local bramble = elem.allocate("MOD", "BCRS")
  161.  
  162. elem.element(bramble, elem.element(elem.DEFAULT_PT_WOOD))
  163. elem.property(bramble, "Name", "BCRS")
  164. elem.property(bramble, "MenuSection", elem.SC_SPECIAL)
  165. elem.property(bramble, "Description", "Bramblecrush, grows into solid things.")
  166. elem.property(bramble, "Color", 0x145214)
  167. elem.property(bramble, "HighTemperature", 395.15)
  168. elem.property(bramble, "HighTemperatureTransition", organic)
  169.  
  170. local function bcrsUpdate(i, x, y, s, nt)
  171.     local r = sim.partID(math.random(x-1, x+1), math.random(y-1, y+1))
  172.     if r ~= nil then
  173.         local rtype = sim.partProperty(r, "type")
  174.         local rx = sim.partProperty(r, "x")
  175.         local ry = sim.partProperty(r, "y")
  176.         if (bit.band(elem.property(rtype, "Properties"), elem.PROP_DEADLY) ~= 0 or bit.band(elem.property(rtype, "Properties"), elem.PROP_RADIOACTIVE) ~= 0) and math.random(1, 5) == 1 then
  177.             sim.partChangeType(i, organic)
  178.         elseif rtype == elem.DEFAULT_PT_GLAS or rtype == elem.DEFAULT_PT_QRTZ then
  179.             if math.random(1, 5) == 1 then
  180.                 sim.partKill(r)
  181.                 if math.random(1, 5) > 2 then
  182.                     local new = sim.partCreate(-1, rx, ry, bramble)
  183.                end
  184.             end
  185.         elseif bit.band(elem.property(rtype, "Properties"), elem.TYPE_SOLID) ~= 0 and elem.property(rtype, "Hardness") ~= 0 and rtype ~= bramble then
  186.             if math.random(1, 5) == 1 then
  187.                 sim.partKill(r)
  188.                 if math.random(1, 5) > 2 then
  189.                     local new = sim.partCreate(-1, rx, ry, bramble)
  190.                end
  191.             end
  192.         end
  193.     end
  194. end
  195.  
  196. elem.property(bramble, "Update", bcrsUpdate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement