Advertisement
TPT_PL

Explodables Mod

Mar 20th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.95 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. local grenade = elem.allocate("MOD", "GRND")
  5. local shrapnel = elem.allocate("MOD", "SHRP")
  6.  
  7. elem.element(dynamite, elem.element(tpt.element("c-4")))
  8. elem.property(dynamite, "Name", "DNMT")
  9. elem.property(dynamite, "Description", "Dynamite, very strong crushing explosive.")
  10. elem.property(dynamite, "Flammable", 0)
  11. elem.property(dynamite, "Explosive", 0)
  12. elem.property(dynamite, "Color", 0xFF6666)
  13.  
  14. local function dnmtUpdate(i, x, y, s, nt)
  15.     if s ~= 8 and nt ~= 0 then
  16.         for r in sim.neighbors(x, y, 1, 1) do
  17.             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
  18.                 sim.partKill(i)
  19.                 sim.partCreate(-1, x, y, elem.DEFAULT_PT_FIRE)
  20.                 sim.pressure(x/4, y/4, sim.pressure(x/4, y/4)+1.2)
  21.                 return 1
  22.             end
  23.         end
  24.     end
  25.     if sim.partProperty(i, "temp") > 673.15 then
  26.         sim.partKill(i)
  27.         sim.partCreate(-1, x, y, elem.DEFAULT_PT_FIRE)
  28.         sim.pressure(x/4, y/4, sim.pressure(x/4, y/4)+1.2)
  29.         return 1
  30.     end
  31. end
  32.  
  33. elem.property(dynamite, "Update", dnmtUpdate)
  34.  
  35. elem.element(blackpd, elem.element(tpt.element("gun")))
  36. elem.property(blackpd, "Name", "BPDR")
  37. elem.property(blackpd, "Description", "Black powder, explosive. Used in production of dynamite.")
  38. elem.property(blackpd, "Flammable", 0)
  39. elem.property(blackpd, "Explosive", 0)
  40. elem.property(blackpd, "Color", 0x555555)
  41.  
  42. local function bpdrUpdate(i, x, y, s, nt)
  43.     if s ~= 8 and nt ~= 0 then
  44.         for r in sim.neighbors(x, y, 1, 1) do
  45.             local rtype = sim.partProperty(r, "type")
  46.             if sim.partProperty(r, "temp") > 673.15 or (rtype == elem.DEFAULT_PT_FIRE or rtype == elem.DEFAULT_PT_PLSM) then
  47.                 sim.partKill(i)
  48.                 if math.random(1, 15) ~= 1 then
  49.                     sim.partCreate(-1, x, y, elem.DEFAULT_PT_FIRE)
  50.                 else
  51.                     sim.partCreate(-1, x, y, elem.DEFAULT_PT_EMBR)
  52.                 end
  53.                 sim.pressure(x/4, y/4, sim.pressure(x/4, y/4)+0.5)
  54.                 return 1
  55.             elseif rtype == elem.DEFAULT_PT_CLST then
  56.                 if math.random(0, 1) == 0 then
  57.                     sim.partChangeType(r, dynamite)
  58.                 else
  59.                     sim.partChangeType(i, dynamite)
  60.                     return 1
  61.                 end
  62.             end
  63.         end
  64.     end
  65.     if sim.partProperty(i, "temp") > 673.15 then
  66.         sim.partKill(i)
  67.         if math.random(1, 15) ~= 1 then
  68.             sim.partCreate(-1, x, y, elem.DEFAULT_PT_FIRE)
  69.         else
  70.             sim.partCreate(-1, x, y, elem.DEFAULT_PT_EMBR)
  71.         end
  72.         sim.pressure(x/4, y/4, sim.pressure(x/4, y/4)+0.5)
  73.         return 1
  74.     end
  75. end
  76.  
  77. elem.property(blackpd, "Update", bpdrUpdate)
  78.  
  79. elem.element(phosphor, elem.element(elem.DEFAULT_PT_BCOL))
  80. elem.property(phosphor, "Name", "PHOS")
  81. elem.property(phosphor, "Description", "Phosphorus, glows for a short while when ignited.")
  82. elem.property(phosphor, "Color", 0x880000)
  83. elem.property(phosphor, "MenuSection", elem.SC_EXPLOSIVE)
  84. elem.property(phosphor, "Properties", elem.PROP_DEADLY+elem.PROP_LIFE_DEC)
  85.  
  86. local function phosUpdate(i, x, y, s, nt)
  87.     if sim.partProperty(i, "tmp") == 1 and sim.partProperty(i, "life") <= 0 then
  88.         sim.partKill(i)
  89.         sim.partCreate(-1, x, y, elem.DEFAULT_PT_SMKE)
  90.         return 1
  91.     end
  92.     local r = sim.partID(math.random(x-1, x+1), math.random(y-1, y+1))
  93.     if r ~= nil then
  94.         local rtype = sim.partProperty(r, "type")
  95.         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
  96.             sim.partProperty(i, "tmp", 1)
  97.             sim.partProperty(i, "life", 100)
  98.         end
  99.     end
  100.     if sim.partProperty(i, "temp") >= 673.15 and sim.partProperty(i, "tmp") ~= 1 then
  101.         sim.partProperty(i, "tmp", 1)
  102.         sim.partProperty(i, "life", 100)
  103.     end
  104. end
  105.  
  106. local function phosGraphics(i, colr, colg, colb)
  107.     if sim.partProperty(i, "tmp") == 1 then
  108.         return 0, ren.PMODE_FLAT+ren.PMODE_FLARE+ren.FIRE_ADD, 125, 255, 125, 125, 125, 127, 63, 63
  109.     end
  110. end
  111.  
  112. elem.property(phosphor, "Update", phosUpdate)
  113. elem.property(phosphor, "Graphics", phosGraphics)
  114.  
  115. elem.element(grenade, elem.element(elem.DEFAULT_PT_DMND))
  116. elem.property(grenade, "Name", "GRND")
  117. elem.property(grenade, "Description", "Grenade, activated by electricity. Explodes into a bunch of smaller explosive pieces.")
  118. elem.property(grenade, "Color", 0x324200)
  119. elem.property(grenade, "MenuSection", elem.SC_EXPLOSIVE)
  120. elem.property(grenade, "Properties", elem.PROP_LIFE_DEC)
  121.  
  122. local function grndUpdate(i, x, y, s, nt)
  123.     local r = sim.partID(math.random(x-1, x+1), math.random(y-1, y+1))
  124.     if r ~= nil then
  125.         local rtype = sim.partProperty(r, "type")
  126.         if ((rtype == elem.DEFAULT_PT_SPRK and sim.partProperty(r, "ctype") ~= elem.DEFAULT_PT_INWR) or (rtype == grenade and sim.partProperty(r, "tmp") == 1)) and sim.partProperty(i, "tmp") ~= 1 then
  127.             sim.partProperty(i, "tmp", 1)
  128.             sim.partProperty(i, "life", 75)
  129.         end
  130.     end
  131.     if sim.partProperty(i, "tmp") == 1 and sim.partProperty(i, "life") <= 0 then
  132.         sim.partKill(i)
  133.         sim.pressure(x/4, y/4, sim.pressure(x/4, y/4)+0.75)
  134.         if math.random(0, 2) == 2 then
  135.             local sh = sim.partCreate(-1, x, y, shrapnel)
  136.             sim.partProperty(sh, "life", 100)
  137.         else
  138.             if math.random(1, 15) ~= 1 then
  139.                 sim.partCreate(-1, x, y, elem.DEFAULT_PT_FIRE)
  140.             else
  141.                 sim.partCreate(-1, x, y, elem.DEFAULT_PT_EMBR)
  142.             end
  143.         end
  144.         return 1
  145.     end
  146. end
  147.  
  148. local function grndGraphics(i, colr, colg, colb)
  149.     if sim.partProperty(i, "tmp") == 1 then
  150.         return 0, ren.PMODE_FLAT+ren.PMODE_FLARE, 0, 50, 66, 0, 0, 0, 0, 0
  151.     end
  152. end
  153.  
  154. elem.property(grenade, "Update", grndUpdate)
  155. elem.property(grenade, "Graphics", grndGraphics)
  156.  
  157. elem.element(shrapnel, elem.element(elem.DEFAULT_PT_BCOL))
  158. elem.property(shrapnel, "Name", "SHRP")
  159. elem.property(shrapnel, "Description", "Shrapnel, left by grenade.")
  160. elem.property(shrapnel, "Color", 0xC2C2A3)
  161. elem.property(shrapnel, "Properties", elem.TYPE_PART+elem.PROP_LIFE_DEC)
  162. elem.property(shrapnel, "MenuVisible", 0)
  163.  
  164. local function shrpUpdate(i, x, y, s, nt)
  165.     if sim.partProperty(i, "life") == 0 then
  166.         sim.partKill(i)
  167.         if math.random(1, 15) ~= 1 then
  168.             sim.partCreate(-1, x, y, elem.DEFAULT_PT_FIRE)
  169.         else
  170.             sim.partCreate(-1, x, y, elem.DEFAULT_PT_EMBR)
  171.         end
  172.         sim.pressure(x/4, y/4, sim.pressure(x/4, y/4)+1)
  173.         return 1
  174.     end
  175. end
  176.  
  177. elem.property(shrapnel, "Update", shrpUpdate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement