jacob614

TPT WIFI clone

May 30th, 2014
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. local awf = elements.allocate("OS", "AWF")
  2. elements.element(awf, elements.element(elem.DEFAULT_PT_WIFI))
  3. elements.property(awf, "Name", "AWF")
  4. elements.property(awf, "Description", "Atmospheric Wi-Fi. Designed for pressurized environments.")
  5. elements.property(awf, "Colour", 0x40A060)
  6. elements.property(awf, "HighPressure", 257)
  7. elements.property(awf, "HighPressureTransition", -1)
  8.  
  9. local wireless = {}
  10. local CHANNELS = 201 --changing this would probably break it slightly
  11. for i = 1,CHANNELS do
  12.     wireless[i] = {[0]=false, [1]=false}
  13. end
  14.  
  15. function WIFI_update()
  16.     for i = 1,CHANNELS do
  17.         if wireless[i][1] then
  18.             wireless[i] = {[0]=true, [1]=false}
  19.         else
  20.             wireless[i] = {[0]=false, [1]=false}
  21.         end
  22.     end
  23. end
  24. tpt.register_step(WIFI_update)
  25.  
  26. function AWF_update(i, x, y, s, n)
  27.     local tmp = math.floor((sim.partProperty(i, sim.FIELD_TEMP)+76.75)/50)
  28.     if tmp > CHANNELS then
  29.         tmp = CHANNELS
  30.     elseif tmp < 1 then
  31.         tmp = 1
  32.     end
  33.     sim.partProperty(i, sim.FIELD_TMP, tmp)
  34.    
  35.     for r in sim.neighbors(x, y, 1, 1) do
  36.         local type = sim.partProperty(r, sim.FIELD_TYPE)
  37.         if wireless[tmp][0] then
  38.             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
  39.                 sim.partProperty(r, sim.FIELD_CTYPE, type)
  40.                 sim.partChangeType(r, elem.DEFAULT_PT_SPRK)
  41.                 sim.partProperty(r, sim.FIELD_LIFE, 4)
  42.             end
  43.         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
  44.             wireless[tmp][1] = true
  45.         end
  46.     end
  47. end
  48. elements.property(awf, "Update", AWF_update)
  49.  
  50. local function AWF_graphics(i, colr, colg, colb)
  51.     local frequency = 0.031415
  52.     local tmp = math.floor((sim.partProperty(i, sim.FIELD_TEMP)+76.75)/50)
  53.     local colr = math.sin(frequency*tmp + 0) * 100 + 100
  54.     local colg = math.sin(frequency*tmp + 2) * 100 + 100
  55.     local colb = math.sin(frequency*tmp + 4) * 100 + 100
  56.     return 0, ren.PMODE_FLAT + ren.EFFECT_DBGLINES, 255, colr, colg, colb, 0, 0, 0, 0
  57. end
  58. elements.property(awf, "Graphics", AWF_graphics)
Advertisement
Add Comment
Please, Sign In to add comment