Trouble with Lua Explosive

  • NDR149
    19th Sep 2016 Member 0 Permalink

    For some reason, this explosive is absolutely awful. I'd appreciate it if somebody could find the problem.

     

    elem.allocate("TONY", "TSAR")
    elem.element(elem.TONY_PT_TSAR, elem.element(elem.DEFAULT_PT_DMND))

    elem.property(elem.TONY_PT_TSAR, "Name", "TSAR")
    elem.property(elem.TONY_PT_TSAR, "Description", "Tsar Balla, explodes like VIBR into molten GOLD")
    elem.property(elem.TONY_PT_TSAR, "Colour", 0xff9900)
    elem.property(elem.TONY_PT_TSAR, "MenuVisible", 1)
    elem.property(elem.TONY_PT_TSAR, "MenuSection", 9)

    elem.property(elem.TONY_PT_TSAR, "Advection", 0)
    elem.property(elem.TONY_PT_TSAR, "AirDrag", 0)
    elem.property(elem.TONY_PT_TSAR, "AirLoss", 0.9)
    elem.property(elem.TONY_PT_TSAR, "Loss", 0)
    elem.property(elem.TONY_PT_TSAR, "Collision", 0)
    elem.property(elem.TONY_PT_TSAR, "Gravity", 0)
    elem.property(elem.TONY_PT_TSAR, "Diffusion", 0)
    elem.property(elem.TONY_PT_TSAR, "HotAir", 0)

    elem.property(elem.TONY_PT_TSAR, "Explosive", 0)
    elem.property(elem.TONY_PT_TSAR, "Flammable", 0)
    elem.property(elem.TONY_PT_TSAR, "Hardness", 40)
    elem.property(elem.TONY_PT_TSAR, "Meltable", 0)
    elem.property(elem.TONY_PT_TSAR, "Weight", 1)

    elem.property(elem.TONY_PT_TSAR, "HeatConduct", 255)
    elem.property(elem.TONY_PT_TSAR, "Temperature", 295.15)

    elem.property(elem.TONY_PT_TSAR, "Falldown", 0)
    elem.property(elem.TONY_PT_TSAR, "State", elem.ST_SOLID)
    elem.property(elem.TONY_PT_TSAR, "Properties", elem.TYPE_SOLID + elem.PROP_LIFE_DEC)

    elem.property(elem.TONY_PT_TSAR, "LowPressure", IPL)
    elem.property(elem.TONY_PT_TSAR, "LowPressureTransition", NT)
    elem.property(elem.TONY_PT_TSAR, "HighPressure", IPH)
    elem.property(elem.TONY_PT_TSAR, "HighPressureTransition", NT)
    elem.property(elem.TONY_PT_TSAR, "LowTemperature", ITL)
    elem.property(elem.TONY_PT_TSAR, "LowTemperatureTransition", NT)
    elem.property(elem.TONY_PT_TSAR, "HighTemperature", ITH)
    elem.property(elem.TONY_PT_TSAR, "HighTemperatureTransition", NT)

    function TSAR_Update(i, x, y, ss, nt)
    -- i: particle index
    -- x, y: particle x, y coords

    --Absorb and Release Temperature
    if sim.partProperty(i,"tmp2") ~= 1 then
    if sim.partProperty(i,"temp") > 299.15 then
    sim.partProperty(i,"tmp",sim.partProperty(i,"tmp")+1)
    sim.partProperty(i,"temp",295.15)
    elseif sim.partProperty(i,"temp") < 291.15 then
    sim.partProperty(i,"tmp",sim.partProperty(i,"tmp")-1)
    sim.partProperty(i,"temp",295.15)
    end
    end

    --Start Countdown
    if sim.partProperty(i,"tmp2") ~= 1 then
    if sim.partProperty(i,"tmp") == 1000 then
    sim.partProperty(i,"life",1000)
    sim.partProperty(i,"temp",9295.15)
    sim.partProperty(i,"tmp2",1)
    end
    end

    --Explode Into GOLD
    if sim.partProperty(i,"tmp2") == 1 then
    if sim.partProperty(i,"life") == 0 then
    sim.partChangeType(i, elem.DEFAULT_PT_LAVA)
    sim.partProperty(i,"ctype",elem.DEFAULT_PT_GOLD)
    sim.pressure(x/4,y/4,200)
    else
    sim.pressure(x/4,(y/4),-4)
    end
    end
    end
    elements.property(elem.TONY_PT_TSAR, "Update", TSAR_Update)

    function TSAR_Graphics(i, colr, colg, colb)
    -- i: particle index
    -- colr, colg, colb: color red, green, and blue channels

    -- return cache, pixel mode,
    -- alpha, red, green, blue,
    -- fire alpha, fire red, fire green, fire blue
    return 1, 0x0000001, 255, colr, colg, colb, 0, 0, 0, 0
    end
    elements.property(elem.TONY_PT_TSAR, "Graphics", TSAR_Graphics)

  • TPT_PL
    19th Sep 2016 Member 0 Permalink
    Lol, your name is Tony? XD
  • NDR149
    19th Sep 2016 Member 0 Permalink

    @TPT_PL (View Post)

     No, Tony is the guy who asked me to design this element

  • TPT_PL
    20th Sep 2016 Member 0 Permalink
    Tell me why this is awful, because of no pressure?
    Try preplacing the pressure value 200 with 200.00
    Maybe it will work.

    Oh, and shouldn't it be Tsar Bomba?
    Edited once by TPT_PL. Last: 20th Sep 2016
  • hax4life
    21st Sep 2016 Member 0 Permalink

    who uses sim.part nowadays,far more bugs to me,and yeah,i tried doing the pressure thing once too,tho seems to error alot,dunno extractly how it works,tho,id prefer doing it like:

    local checklife = tpt.get_property("life",x,y)
    local checktmp = tpt.get_property("tmp2",x,y)

    if checklife >1 and checktmp >3 then
    tpt.set_property('tmp2', (checktmp - 1), x, y)

    for example(thats to auto remove tmp2 to 3)

    eazier to understand,and has almost all functions(but pressure,so far i know of) than sim.part,its a lil more decompressed tho,try looking up again how the pressure thing extractly works,also might be the part where it makes the elements it spits out ctyped lava

     

    Edited once by hax4life. Last: 21st Sep 2016
  • jacob1
    21st Sep 2016 Developer 0 Permalink
    @hax4life (View Post)
    sim.partProperty is exactly the same as tpt.get_property, and doesn't have any more "bugs". If you do know about any bugs, what are they?

    I would recommend using the new APIs when possible.
  • NDR149
    21st Sep 2016 Member 0 Permalink

    @TPT_PL (View Post)

     The pressure works, but the explosion itself is touch-and-go. Sometimes it's flawless, sometimes I just get bits of solid gold everywhere. Tsar "Balla" because golden bomb, not nuclear.

  • TPT_PL
    22nd Sep 2016 Member 0 Permalink
    Try increasing the temp of GOLD.