Advertisement
Guest User

Drill

a guest
Oct 3rd, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 KB | None | 0 0
  1. --drill for digging
  2. --don't use more than one particle at a time
  3. local drill = elem.allocate("BAUER", "DRLL")
  4.  
  5. elem.element(elem.BAUER_PT_DRLL, elem.element(elem.DEFAULT_PT_PHOT))
  6. elem.property(elem.BAUER_PT_DRLL, "Name", "DRLL")
  7. elem.property(elem.BAUER_PT_DRLL, "MenuVisible", 1)
  8. elem.property(elem.BAUER_PT_DRLL, "Colour", 0x524734)
  9. elem.property(elem.BAUER_PT_DRLL, "MenuSection", elem.SC_SPECIAL)
  10. elem.property(elem.BAUER_PT_DRLL, "Description", "Drills through things, only use one at a time")
  11. elem.property(elem.BAUER_PT_DRLL, "Temperature", 273.15)
  12.  
  13. local drillup = false
  14. local drilldown = false
  15. local drillright = false
  16. local drillleft = false
  17.  
  18. local active = true
  19. local vnum = 1
  20. local pdir = ""
  21. local hud = 1
  22.  
  23. function control(key,dkey,_,event)
  24.     if dkey == 273 then --up arrow
  25.         drillup = true
  26.         drilldown = false
  27.         drillright = false
  28.         drillleft = false
  29.         active = true
  30.     end
  31.     if dkey == 274 then --down arrow
  32.         drillup = false
  33.         drilldown = true
  34.         drillright = false
  35.         drillleft = false
  36.         active = true
  37.     end
  38.     if dkey == 276 then --right arrow
  39.         drillup = false
  40.         drilldown = false
  41.         drillright = true
  42.         drillleft = false
  43.         active = true
  44.     end
  45.     if dkey == 275 then --left arrow
  46.         drillup = false
  47.         drilldown = false
  48.         drillright = false
  49.         drillleft = true
  50.         active = true
  51.     end
  52.     if event==1 then
  53.         if key == "j" then
  54.             vnum=vnum+0.1
  55.         end
  56.         if key == "m" then
  57.             vnum=vnum-0.1
  58.         end
  59.         if key == "h" and hud==1 then
  60.             tpt.unregister_step(status)
  61.             hud=0
  62.         else
  63.             if key == "h" and hud==0 then
  64.                 tpt.register_step(status)
  65.                 hud=1
  66.             end
  67.         end
  68.     end
  69. end
  70.  
  71. function contr(i,x,y,s,n)
  72. for r in sim.neighbors(x,y,2,2) do
  73.             if sim.partProperty(r, "type") ~= nil and sim.partProperty(r, "type") ~= elem.BAUER_PT_DRLL then
  74.                 sim.partChangeType(r, elem.DEFAULT_PT_BRCK)
  75.                 end
  76.         end
  77.         --this first part turns surrounding particles into brick so the tunnel doesn't collapse
  78.     if active==true then
  79.         if drillup==true then
  80.             local du = sim.partID(x, y - 1)
  81.             if du == nil then
  82.                 tpt.create(x, y - 1, 'drll')
  83.                 sim.partKill(i)            
  84.             elseif du ~= nil then
  85.                 sim.partProperty(du, "type", "drll")
  86.                 --sim.partKill(i)
  87.                 end
  88.             pdir = "up"
  89.             active = false                         
  90.         end
  91.         if drilldown==true then
  92.             local dd = sim.partID(x, y + 1)
  93.             if dd == nil then
  94.                 tpt.create(x, y + 1, 'drll')
  95.                 sim.partKill(i)            
  96.             elseif dd ~= nil then
  97.                 sim.partProperty(dd, "type", "drll")
  98.                 --sim.partKill(i)
  99.                 end
  100.             pdir = "down"
  101.             active = false
  102.         end
  103.         if drillright==true then
  104.             local dr = sim.partID(x - 1, y)
  105.             if dr == nil then
  106.                 tpt.create(x - 1, y, 'drll')
  107.                 sim.partKill(i)            
  108.             elseif dr ~= nil then
  109.                 sim.partProperty(dr, "type", "drll")  
  110.                 --sim.partKill(i)
  111.                 end
  112.             pdir = "left"
  113.             active = false
  114.         end
  115.         if drillleft==true then
  116.         local dl = sim.partID(x + 1, y)
  117.             if dl == nil then
  118.                 tpt.create(x + 1, y, 'drll')
  119.                 sim.partKill(i)            
  120.             elseif dl ~= nil then
  121.                 sim.partProperty(dl, "type", "drll")
  122.                 --sim.partKill(i)
  123.                 end
  124.             pdir = "right"
  125.             active = false
  126.         end
  127.     end
  128. end
  129. --kills surrounding particles and replaces with itself
  130. tpt.element_func(contr,elem.BAUER_PT_DRLL)
  131. tpt.register_keypress(control)
  132.  
  133. --Key control function y MrSalit0s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement