<code>
local OS = elements.allocate("OS", "AWF")
elements.element(elements.OS_PT_AWF, elements.element(tpt.element("AWF")))
elements.property(elements.OS_PT_AWF, "Name", "AWF")
elements.property(elements.OS_PT_AWF, "Description", "Atmospheric Wi-Fi. Designed for pressurized environments.")
elements.property(elements.OS_PT_AWF, "Colour", 0x40A060)
elements.property(elements.OS_PT_AWF, "MenuVisible", 1)
elements.property(elements.OS_PT_AWF, "MenuSection", SC_ELEC)
elements.property(elements.OS_PT_AWF, "Advection", 0)
elements.property(elements.OS_PT_AWF, "AirDrag", 0)
elements.property(elements.OS_PT_AWF, "AirLoss", 1.00)
elements.property(elements.OS_PT_AWF, "Loss", 0)
elements.property(elements.OS_PT_AWF, "Collision", 0)
elements.property(elements.OS_PT_AWF, "HeatConduct", 1)
elements.property(elements.OS_PT_AWF, "Gravity", 0)
elements.property(elements.OS_PT_AWF, "Diffusion", 0)
elements.property(elements.OS_PT_AWF, "HotAir", 0)
elements.property(elements.OS_PT_AWF, "Falldown", 0)
elements.property(elements.OS_PT_AWF, "Flammable", 0)
elements.property(elements.OS_PT_AWF, "Explosive", 0)
elements.property(elements.OS_PT_AWF, "Meltable", 0)
elements.property(elements.OS_PT_AWF, "Hardness", 2)
elements.property(elements.OS_PT_AWF, "Weight", 100)
elements.property(elements.OS_PT_AWF, "Temperature", 273.15)
elements.property(elements.OS_PT_AWF, "HeatConduct", 0)
elements.property(elements.OS_PT_AWF, "State", ST_GAS)
elements.property(elements.OS_PT_AWF, "Properties", TYPE_SOLID)
elements.property(elements.OS_PT_AWF, "LowPressure", IPL)
elements.property(elements.OS_PT_AWF, "LowPressureTransition", NT)
elements.property(elements.OS_PT_AWF, "HighPressure", IPH)
elements.property(elements.OS_PT_AWF, "HighPressureTransition", NT)
elements.property(elements.OS_PT_AWF, "LowTemperature", ITL)
elements.property(elements.OS_PT_AWF, "LowTemperatureTransition", NT)
elements.property(elements.OS_PT_AWF, "HighTemperature", ITH)
elements.property(elements.OS_PT_AWF, "HighTemperatureTransition", NT)
function AWF_update(i, x, y, s, n)
int r, rx, ry
tpt.parts[i].tmp = (int)((parts[i].tmp.temp-0.20)/47500+1);
if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1;
else if (parts[i].tmp<0) parts[i].tmp = 0;
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++;)
if (BOUNDS_CHECK and (rx || ry))
r = pmap[y+ry][x+rx];
if (!r)
continue;
if (sim->wireless[parts[i].tmp][0])
if (((r and 0xFF0==PT_NSCN||(r and 0xFF)==PT_PSCN||(r and 0xFF)==PT_INWR) and parts[r>>8].life==0 and sim->wireless[parts[i].tmp][0])
parts[r>>8].ctype = r and 0xFF
sim->part_change_type(r>>8,x+ry,y+ry,PT_SPRK)
parts[r>>8.life = 4
else if ((r and 0xFF)==PT_SPRK and parts[r>>8].ctype!=PT_NSCN and parts[r>>8].life==3)
sim->wireless[parts[i].tmp][1] = 1
sim->ISWIRE = 2
return 0
end
tpt.element_func(AWF_update, elements.OS_PT_AWF,1)
local function graphics1(i, colr, colg, colb)
float frequency = 0.0628
int q = (int)((cpart->temp-0.20)/100+1)
*colr = sin(frequency*q + 0) * 31 + 32
*colg = sin(frequency*q + 2) * 31 + 32
*colb = sin(frequency*q + 4) * 31 + 32
*pixel_mode |= EFFECT_DBGLINES
return 0
end
tpt.graphics_func(graphics1,AWF)
<code>
Thanks for the advice. I tried to look at example code from other Mod elements and this is the best I could do. I thought it'd work, but now I know.
How would I replicate WIFI using Lua? From other's examples, I most likely know how to replace an element using Lua, but how would I replicate and rename the new replicated wifi, as well as making it pressure-proof and set it where it has 200 channels instead of 100?
local awf = elements.allocate("OS", "AWF")
elements.element(awf, elements.element(elem.DEFAULT_PT_WIFI))
elements.property(awf, "Name", "AWF")
elements.property(awf, "Description", "Atmospheric Wi-Fi. Designed for pressurized environments.")
elements.property(awf, "Colour", 0x40A060)
elements.property(awf, "HighPressure", 257)
elements.property(awf, "HighPressureTransition", -1)
local wireless = {}
local CHANNELS = 201 --changing this would probably break it slightly
for i = 1,CHANNELS do
wireless[i] = {[0]=false, [1]=false}
end
function WIFI_update()
for i = 1,CHANNELS do
if wireless[i][1] then
wireless[i] = {[0]=true, [1]=false}
else
wireless[i] = {[0]=false, [1]=false}
end
end
end
tpt.register_step(WIFI_update)
function AWF_update(i, x, y, s, n)
local tmp = math.floor((sim.partProperty(i, sim.FIELD_TEMP)+76.75)/50)
if tmp > CHANNELS then
tmp = CHANNELS
elseif tmp < 1 then
tmp = 1
end
sim.partProperty(i, sim.FIELD_TMP, tmp)
for r in sim.neighbors(x, y, 1, 1) do
local type = sim.partProperty(r, sim.FIELD_TYPE)
if wireless[tmp][0] then
if type == elem.DEFAULT_PT_NSCN or type == elem.DEFAULT_PT_PSCN or type == elem.DEFAULT_PT_INWR and sim.partProperty(r, sim.FIELD_LIFE) == 0 then
sim.partProperty(r, sim.FIELD_CTYPE, type)
sim.partChangeType(r, elem.DEFAULT_PT_SPRK)
sim.partProperty(r, sim.FIELD_LIFE, 4)
end
elseif type == elem.DEFAULT_PT_SPRK and sim.partProperty(r, sim.FIELD_CTYPE) ~= elem.DEFAULT_PT_NSCN and sim.partProperty(r, sim.FIELD_LIFE) == 3 then
wireless[tmp][1] = true
end
end
end
elements.property(awf, "Update", AWF_update)
local function AWF_graphics(i, colr, colg, colb)
local frequency = 0.031415
local tmp = math.floor((sim.partProperty(i, sim.FIELD_TEMP)+76.75)/50)
local colr = math.sin(frequency*tmp + 0) * 100 + 100
local colg = math.sin(frequency*tmp + 2) * 100 + 100
local colb = math.sin(frequency*tmp + 4) * 100 + 100
return 0, ren.PMODE_FLAT + ren.EFFECT_DBGLINES, 255, colr, colg, colb, 0, 0, 0, 0
end
elements.property(awf, "Graphics", AWF_graphics)
Thanks dude! I really appreciate it!
jacob1:
This should be an almost exact replica of WIFI (with a particle order issue fixed :P). I noticed a glitch where it would constantly spark but I couldn't reproduce it. I also tried to use the new Lua APIs fully :)local awf = elements.allocate("OS", "AWF")
elements.element(awf, elements.element(elem.DEFAULT_PT_WIFI))
elements.property(awf, "Name", "AWF")
elements.property(awf, "Description", "Atmospheric Wi-Fi. Designed for pressurized environments.")
elements.property(awf, "Colour", 0x40A060)
elements.property(awf, "HighPressure", 257)
elements.property(awf, "HighPressureTransition", -1)
local wireless = {}
local CHANNELS = 201 --changing this would probably break it slightly
for i = 1,CHANNELS do
wireless[i] = {[0]=false, [1]=false}
end
function WIFI_update()
for i = 1,CHANNELS do
if wireless[i][1] then
wireless[i] = {[0]=true, [1]=false}
else
wireless[i] = {[0]=false, [1]=false}
end
end
end
tpt.register_step(WIFI_update)
function AWF_update(i, x, y, s, n)
local tmp = math.floor((sim.partProperty(i, sim.FIELD_TEMP)+76.75)/50)
if tmp > CHANNELS then
tmp = CHANNELS
elseif tmp < 1 then
tmp = 1
end
sim.partProperty(i, sim.FIELD_TMP, tmp)
for r in sim.neighbors(x, y, 1, 1) do
local type = sim.partProperty(r, sim.FIELD_TYPE)
if wireless[tmp][0] then
if type == elem.DEFAULT_PT_NSCN or type == elem.DEFAULT_PT_PSCN or type == elem.DEFAULT_PT_INWR and sim.partProperty(r, sim.FIELD_LIFE) == 0 then
sim.partProperty(r, sim.FIELD_CTYPE, type)
sim.partChangeType(r, elem.DEFAULT_PT_SPRK)
sim.partProperty(r, sim.FIELD_LIFE, 4)
end
elseif type == elem.DEFAULT_PT_SPRK and sim.partProperty(r, sim.FIELD_CTYPE) ~= elem.DEFAULT_PT_NSCN and sim.partProperty(r, sim.FIELD_LIFE) == 3 then
wireless[tmp][1] = true
end
end
end
elements.property(awf, "Update", AWF_update)
local function AWF_graphics(i, colr, colg, colb)
local frequency = 0.031415
local tmp = math.floor((sim.partProperty(i, sim.FIELD_TEMP)+76.75)/50)
local colr = math.sin(frequency*tmp + 0) * 100 + 100
local colg = math.sin(frequency*tmp + 2) * 100 + 100
local colb = math.sin(frequency*tmp + 4) * 100 + 100
return 0, ren.PMODE_FLAT + ren.EFFECT_DBGLINES, 255, colr, colg, colb, 0, 0, 0, 0
end
elements.property(awf, "Graphics", AWF_graphics)
Hopefully it's useful, I can explain any part of it, but it's really just a copy of the c++ source.
I tried the script and the AWF didn't work correctly. Any help?
It shows up. I set 2 AWFs to 50, and 2 to 100, and when I spark 1 end on both, no sparks transfered at all. I then set the channels in intervals of 100 like normal, starting at 22, then 122, and so forth and still nothing.
I'll try deleting then making the Lua script again.
PS: I haven't tried using TPTAPI. I don't even know what it is.
My silly self! No wonder it didn't work - I used METL and tried to transfer the spark to another METL instead of NSCN. Thanks for the help dude!