MTOR (Meteor)

  • Videogamer555
    1st Jan 2012 Member 11 Permalink
    Here's the Lua code for a new element called Meteor (it changes ELEC into MTOR). They heat nearby objects and explode on impact. This is realistic as I've heard that large asteroids (like the one that killed the dinosaurs) can set entire forrests on fire just by its radiant heat alone (just like the heat of a nuclear blast, well before actual impact)! However this isn't a large asteroid so it has to be fairly close (about 10 pixels away) to set much of anything on fire (such as PLNT which will ignite at only 400degC). And it has to be almost one frame before impact for metal to melt (though a shallower angle such as from a "near miss" will mean it exposes the metal to more heat for longer before impact and can melt metal in fact with no impact). As it is radiant heat (and IR intensity as with visible light intensity is proportional to the square of the distance from the source), the heating strength is proportional to the square of the distance (out to a distance of 40 pixels as I have it set to only affect things within this distance or else running 2 for loops for x and y coordinates at something like a 200pixel radius would completely consume CPU processing power, and it would be useless as at that distance the heating would be negligible anyway). So if it tries to add 1000degC per frame at a given distance (within 40 pixels of the head of the meteor), it will only attempt to add 250degC at twice that distance.

    It also makes a shockwave or "sonic boom" as it travels. This is visible in any one of the air pressure or velocity displays available as a region of high pressure just in front of head of the meteor (and radiating away in a cone shape) as well as a region of low pressure just behind the head of the meteor (again radiating away in a cone). The velocity shape is a bit more complicated but tends to follow the pressure and vacuum regions of the shock wave.

    Upon impact it explodes and throws out a shower of hot sparks (not the element SPRK, but rather realistic sparks from the BOMB element) which can cause burn or melt more things by direct contact.

    Warning, this thing absolutely MURDERS the frame rate of TPT when a significant number of meteors are on screen at the same time. When having a completely black play area on the screen I get about 52 FPS. Having just 20 meteors on the screen simultaneously I get only 10 FPS. So as the in-game description of the element says, USE SPARINGLY!

    You may have noticed above I mentioned the head of the meteor as the reference point for thermal and shockwave effects, that's because this meteor also has a tail. I accomplished this with BRAY.

    Here is the LUA code to turn ELEC into MTOR (I called it MTOR instead of METR to avoid confusion with METL metal). It appears in the explosives menu. I hope some day this element makes it into an official TPT release.


    tpt.el.elec.properties=0
    tpt.el.elec.heat=9999
    tpt.el.elec.airdrag=30
    tpt.el.elec.menusection=3
    tpt.el.elec.name="MTOR"
    tpt.el.elec.description="Meteor. Heats nearby objects (the closer the stronger the heating), makes a shockwave, and explodes on impact. Use sparingly."


    math.randomseed(os.time())
    function mtor_update(i, x, y, s, n)
    if tpt.get_property("tmp",i)==0 then
    tpt.parts[i].tmp=1
    randvel=math.random(-20,20)/10
    tpt.parts[i].vx=randvel
    tpt.parts[i].vy=math.sqrt(8-(randvel^2))
    end

    xvel=tpt.get_property("vx",i)/2
    yvel=tpt.get_property("vy",i)/2
    if yvel <= 0 or math.abs(xvel) > 1 then
    tpt.delete(i)


    end

    xpos=x-xvel
    ypos=y-yvel
    elemtype=tpt.get_property("type",xpos,ypos)

    if elemtype == 0 then
    tpt.create(xpos,ypos,"bray")
    tpt.set_property("temp",5000,xpos,ypos)
    end
    tpt.parts[i].temp=9999

    elemtype25=tpt.get_property("type",x+xvel*5,y+yvel*5)
    elemtype24=tpt.get_property("type",x+xvel*4,y+yvel*4)
    elemtype23=tpt.get_property("type",x+xvel*3,y+yvel*3)
    elemtype22=tpt.get_property("type",x+xvel*2,y+yvel*2)
    elemtype21=tpt.get_property("type",x+xvel,y+yvel)
    if elemtype25 ~= 0 and elemtype25 ~= tpt.el.elec.id and elemtype25 ~= tpt.el.bray.id and elemtype25 ~= tpt.el.dmnd.id and elemtype25 ~= tpt.el.void.id then
    tpt.set_property("type","bomb",i)
    tpt.set_property("life",0,i)
    tpt.set_property("tmp",0,i)


    elseif elemtype24 ~= 0 and elemtype24 ~= tpt.el.elec.id and elemtype24 ~= tpt.el.bray.id and elemtype24 ~= tpt.el.dmnd.id and elemtype24 ~= tpt.el.void.id then
    tpt.set_property("type","bomb",i)
    tpt.set_property("life",0,i)
    tpt.set_property("tmp",0,i)
    elseif elemtype23 ~= 0 and elemtype23 ~= tpt.el.elec.id and elemtype23 ~= tpt.el.bray.id and elemtype23 ~= tpt.el.dmnd.id and elemtype23 ~= tpt.el.void.id then
    tpt.set_property("type","bomb",i)
    tpt.set_property("life",0,i)
    tpt.set_property("tmp",0,i)
    elseif elemtype22 ~= 0 and elemtype22 ~= tpt.el.elec.id and elemtype22 ~= tpt.el.bray.id and elemtype22 ~= tpt.el.dmnd.id and elemtype22 ~= tpt.el.void.id then
    tpt.set_property("type","bomb",i)
    tpt.set_property("life",0,i)
    tpt.set_property("tmp",0,i)
    elseif elemtype21 ~= 0 and elemtype21 ~= tpt.el.elec.id and elemtype21 ~= tpt.el.bray.id and elemtype21 ~= tpt.el.dmnd.id and elemtype21 ~= tpt.el.void.id then
    tpt.set_property("type","bomb",i)
    tpt.set_property("life",0,i)
    tpt.set_property("tmp",0,i)
    end



    for scany = -40,40 do
    maxscanx=math.sqrt(1600-(scany^2))
    for scanx = -maxscanx,maxscanx do
    elemtype3 = tpt.get_property("type",x+scanx,y+scany)
    if elemtype3 ~= 0 and elemtype3 ~= tpt.el.elec.id and elemtype3 ~= tpt.el.bray.id and elemtype3 ~= tpt.el.insl.id then
    tpt.set_property("temp",tpt.get_property("temp",x+scanx,y+scany)+(19200/((scanx^2)+(scany^2))),x+scanx,y+scany)
    end
    end
    end
    end
    tpt.element_func(mtor_update, tpt.el.elec.id,1)

  • arlo
    1st Jan 2012 Member 0 Permalink
    I made somthing similar to that but its a fake really
  • therocketeer
    1st Jan 2012 Member 0 Permalink

    @Videogamer555 (View Post)
    how do I put it into the console?

  • Shriek
    1st Jan 2012 Banned 1 Permalink
    This post is hidden because the user is banned
  • ArtMaster
    1st Jan 2012 Banned 0 Permalink
    This post is hidden because the user is banned
  • therocketeer
    1st Jan 2012 Member 2 Permalink
    can someone tell me without taking the piss, how to put the code into the game.
  • disturbed666
    1st Jan 2012 Member 2 Permalink
    @therocketeer (View Post)
    If I'm correct you need to save this as a lua script file and then through console use the dofile('filename.lua')
    as command to run it. Hope it works
  • lillepallt
    1st Jan 2012 Member 2 Permalink
    @therocketeer (View Post)
    I'm a noob on that area :3 but I think you have to create a textfile named autorun.lua copy + paste the code to the file and put it in the same file as where tpt is placed
  • ArtMaster
    1st Jan 2012 Banned 2 Permalink
    This post is hidden because the user is banned
  • therocketeer
    1st Jan 2012 Member 1 Permalink
    @disturbed666 (View Post)
    @lillepallt (View Post)
    thanks for helping, that sounds rather complex, it'd be nice if you could just paste it into the console normaly.