greetings,
here is my first Lua element NEON (neon gas). it glows in contact with electricity and is sparkable. through tmp value (1-7) you are able to change its colour. tmp 8 shuffles them.
example:
note that deco layer have to be enabled!
I'm still not so good at Lua scripting and i know that this element is not very realistic :P but i'm getting better. here is the code (last update April 2013) http://pastebin.com/Arib3qM1
local NEON = elements.allocate("MOD", "NEON")
elements.element(elements.MOD_PT_NEON, elements.element(elements.DEFAULT_PT_NBLE))
elements.property(elements.MOD_PT_NEON, "Name", "NEON")
elements.property(elements.MOD_PT_NEON, "Description", "Neon gas - glows in contact with electricity")
elements.property(elements.MOD_PT_NEON, "Colour", 0x00242424)
elements.property(elements.MOD_PT_NEON, "MenuSection", 6)
elements.property(elements.MOD_PT_NEON, "Loss", 0.1)
elements.property(elements.MOD_PT_NEON, "AirLoss", 1)
elements.property(elements.MOD_PT_NEON, "Advection", 0.4)
elements.property(elements.MOD_PT_NEON, "Diffusion", 0.5)
elements.property(elements.MOD_PT_NEON, "Temperature", 295)
elements.property(elements.MOD_PT_NEON, "Gravity", 0)
elements.property(elements.MOD_PT_NEON, "Flammable", 0)
elements.property(elements.MOD_PT_NEON, "Weight", 0)
elements.property(elements.MOD_PT_NEON, "Properties", 0x4828)
local colour={0xFFAA0000,0xFFFF6600,0xFFFFFF00,0xFF00FF00,0xFF00FFFF,0xFF0000FF,0xFF9900CC}
local none=0x00242424
local function neon(i,x,y,s,n)
if tpt.get_property("tmp",i)== 0 then
tpt.set_property("tmp",1,i)
end
if tpt.get_property("tmp2",i)== 1 then
tpt.set_property("life",180+math.random(0,20),i)
tpt.set_property("tmp2",0,i)
end
if tpt.parts[i].life<=0 then
tpt.set_property("dcolour",none,i)
end
end
local function neonsprk(i,x,y,s,n)
local ntmp=tpt.get_property("tmp",i)
local neontype=tpt.get_property("ctype",i)
if tpt.get_property("ctype",i)==elements.MOD_PT_NEON then
if tpt.get_property("tmp",i)==ntmp then
tpt.set_property("dcolour",colour[ntmp],i)
tpt.set_property("tmp2",1,i)
end
if tpt.get_property("tmp",i)==8 then
tpt.set_property("dcolour",colour[math.random(1,7)],i)
tpt.set_property("tmp2",1,i)
end
end
end
tpt.element_func(neon,elements.MOD_PT_NEON)
tpt.element_func(neonsprk,elements.DEFAULT_PT_SPRK)
--By MrSalit0s
here is an optional graphics funktion for NEON. it has an EMBR like effect. add this piece of code if you want.
local function neongraphics(i, colr, colg, colb)
return 1,0x00022110,30,30,30,30,30,30,30,30
end
tpt.graphics_func(neongraphics,elements.MOD_PT_NEON)
Pretty good for a beginner. :3
''
function neon(i,x,y,s,n)
if tpt.get_property("tmp2",i)== 1 then
tpt.set_property("life",200,i)
tpt.set_property("tmp2",0,i)
end
if tpt.parts[i].life<=0 then
tpt.set_property("dcolour",0X00242424,i)
end
end
''
He's not beginner at scripting anymore.
True. A lot of people wants lamps, and now those people will be happy.
Hmm.. I'll try to get how does that code work.
Just 2 things: what's airloss, and which are the submenu numbers?
Epic. No other words needed.
Alright. I checked the script. I wrote what I understood and what not. Here:
-------------------------------------------------------------------------------------------
tpt.el.bran.menu=1
tpt.el.bran.enabled=1
tpt.el.bran.menusection=5----------------------------------------------------------------
Puts bran in the menu, in a certain menusection, and enables it.
----------------------------------------------------------------tpt.el.bran.name="NEON"
tpt.el.bran.description="Neon gas - glows in contact with electricity"
tpt.el.bran.color=0X00242424
tpt.el.bran.gravity=0
tpt.el.bran.diffusion=1
------------------
Nothing new to me.
------------------
tpt.el.bran.advection=2
tpt.el.bran.properties=0x48280
tpt.el.bran.flammable=0
tpt.el.bran.heat=295
tpt.el.bran.weight=0
tpt.el.bran.airloss=1------------------------------------
Advection, dunno,
properties, adds various properties,
flammable, false,
heat, default initial heat,
weight, obvious,
airloss, dunno again.
------------------------------------function neon(i,x,y,s,n)
if tpt.get_property("tmp2",i)== 1 then
tpt.set_property("life",200,i)
tpt.set_property("tmp2",0,i)
end
if tpt.parts[i].life<=0 then
tpt.set_property("dcolour",0X00242424,i)
end
end-------------------------------------------------------------------------
*If tmp2 is changed to 1, life changes to 200 and tmp2 changes to 0 again.
(used to make glowing neon non-sparkable)
I don't understand the second one.Edit: nevermind. The second If thing is to make the color back to normal when life goes to 0
(At that time it is sparkable again)
-------------------------------------------------------------------------
function neonsprk(i,x,y,s,n)
type=tpt.get_property("ctype",x+math.random(-1,1),y+math.random(-1,1))
if tpt.get_property("ctype",i)==tpt.el.bran.id then
if tpt.get_property("tmp",i)==0 then
tpt.set_property("dcolour",0xFFFF0000,i) --red
tpt.set_property("tmp2",1,i)
end
if tpt.get_property("tmp",i)==1 then
tpt.set_property("dcolour",0xFF00FF00,i) --green
tpt.set_property("tmp2",1,i)
end
if tpt.get_property("tmp",i)==2 then
tpt.set_property("dcolour",0xFF0000FF,i) --blue
tpt.set_property("tmp2",1,i)
end
end
end----------------------------------------------------------------------------------
Don't understand the type thing.
All I understood is this:If sprk has bran as ctype then the following happens:
If tmp is 0, then it would become red and tmp2 would become 1, making * happen.
If tmp is 1, then it would become green and tmp2 would become 1, making * happen.
If tmp is 2, then it would become blue and tmp2 would.. you get it.
----------------------------------------------------------------------------------tpt.element_func(neonsprk,tpt.el.sprk.id)
tpt.element_func(neon,tpt.el.bran.id)-------------------------------------------------------------------------------------------
Makes ''function neon'' and ''function neonsprk'' work,
as if they were ''function bran'' and ''function sprk'', respectively.
Other way those wouldn't work.
Basically, both commands simply attach 'neon' and 'neonsprk', to the 'bran' and 'sprk' ids.
-------------------------------------------------------------------------------------------
Can someone read and clarify me plz?
Advection, does the element rise if it has more heat. Its another name for convection although advection IS a different thing.
Airloss I don't know either as elements are incapable of blocking air apart from ttan
The function you dont understand converts surrounding pixels at a random interval, I guess to stop it being a solid line? Im not sure.
Well done to the creator