Nuclear Fusion Script

  • QuentinADay
    9th Feb 2014 Member 0 Permalink

    Its a bomb that makes fusion when it explodes (Warning: This will break any saves that uses thdr) 

     

    Use in enclosed spaces!

     

     

     

    local thunder = elements.allocate("NOBODY", "B")
    elements.element(elements.NOBODY_PT_B, elements.element(elements.DEFAULT_PT_BCOL))
    elements.property(elements.NOBODY_PT_B, "Name", "NFUS")
    elements.property(elements.NOBODY_PT_B, "Description", "Creates Nuclear Fusion.")
    elements.property(elements.NOBODY_PT_B, "Colour", 0xFFB9FEF7)
    elements.property(elements.NOBODY_PT_B, "MenuSection", 5)
    elements.property(elements.NOBODY_PT_B, "Gravity", 0)
    elements.property(elements.NOBODY_PT_B, "Flammable", 0)
    elements.property(elements.NOBODY_PT_B, "Explosive", 0)
    elements.property(elements.NOBODY_PT_B, "Loss", 0.15)
    elements.property(elements.NOBODY_PT_B, "AirLoss", 0.96)
    elements.property(elements.NOBODY_PT_B, "AirDrag", 0.03)
    elements.property(elements.NOBODY_PT_B, "Advection", 2)
    elements.property(elements.NOBODY_PT_B, "Weight", 32)
    elements.property(elements.NOBODY_PT_B, "Diffusion", 0)
    elements.property(elements.NOBODY_PT_B, "Falldown", 0)
    NFUSUpdate = function(i, x, y, s, n)
    local clife = tpt.get_property('life', x, y)
    if clife > 1 then
    for cx = -1, 1, 2 do
    for cy = -1, 1, 2 do
    tpt.create(x + cx, y + cy, 'thdr')
    end
    end
    tpt.set_property('life', clife - 1, x, y)
    elseif clife == 1 then
    tpt.set_property('type', 0, x, y)
    elseif s > 0 then
    for cx = -1, 1, 2 do
    for cy = -1, 1, 2 do
    if tpt.get_property('type', x + cx, y + cy) == 4 or tpt.get_property('type', x + cx, y + cy) == 49 then
    tpt.set_property('life', 300, x, y)
    return true
    end
    end
    end
    end
    end
    tpt.element_func(NFUSUpdate, tpt.element('nfus'))

     

    function growth(i,x,y,s,n)
    type=tpt.get_property("type",x+math.random(-1,1),y+math.random(-1,1))
    if type==tpt.el.thdr.id then
    tpt.parts[i].type=tpt.el.hygn.id
    end
    end

    tpt.element_func(growth,tpt.el.thdr.id)

    Edited once by QuentinADay. Last: 9th Feb 2014
  • FeynmanLogomaker
    9th Feb 2014 Member 0 Permalink

    You could allocate an element yourself rather than overwrite THDR, but other than that, it's pretty cool!

  • QuentinADay
    9th Feb 2014 Member 0 Permalink

    i thought of that but desided not too...

  • FeynmanLogomaker
    9th Feb 2014 Member 0 Permalink

    You could do something like this:

     

    local thdr_copy = elements.allocate("NOBODY", "THDR")
    elements.element(elements.NOBODY_PT_THDR, elements.element(elements.DEFAULT_PT_THDR))

     

    It makes your own little private copy of THDR.

  • QuentinADay
    9th Feb 2014 Member 0 Permalink

    thx that works!

  • FeynmanLogomaker
    9th Feb 2014 Member 0 Permalink

    It does? I haven't tested it, so I wasn't sure if it would need edits.

  • QuentinADay
    9th Feb 2014 Member 0 Permalink

    well it copies it but i have no clue on how to put it into the update function where thdr goes...

     

    tpt.create(x + cx, y + cy, 'thdr')

  • nucular
    9th Feb 2014 Member 0 Permalink
    @QuentinADay
    You can use element IDs wherever you use element names.