Advertisement
TPT_PL

Explosives

Aug 23rd, 2017
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.38 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. Used in production of dynamite.")
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement