Advertisement
ZNZNCOOP

cscan

Dec 17th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.64 KB | None | 0 0
  1. MenuBg=colors.lightGray
  2. MenuBtn=colors.green
  3. Chunk=colors.black
  4. ActiveChunk=colors.lightBlue
  5. PlayerChunk=colors.lime
  6. p = peripheral.wrap('bottom')
  7. w = p.getWorld(p.getPeripheralWorldID())
  8. --w={}
  9. --w.map={[0]={[0]=true,[10]=true},[5]={[5]=true},[10]={[10]=true}}
  10. --w.isChunkLoaded=function(x,z)
  11. --  if w.map[z] then return w.map[z][x] end
  12. --end
  13.  
  14. inifilename='cscan.ini'
  15. term.clear()
  16. inifile=fs.open(inifilename,'r')
  17. if inifile then
  18.   cx,cz=string.match(inifile.readLine(),'cx=(%d+)%s+cz=(%d+)')
  19.   cx=tonumber(cx) cz=tonumber(cz)
  20.   inifile.close()
  21. else
  22.   cx=0 cz=0
  23. end
  24. local work=true
  25. local eventKey={}
  26. local scantimer
  27. local buttons={}
  28. local function AddButton(name,x,y,proc)
  29.   table.insert(buttons,{name=name, x1=x, x2=x+#name-1, y=y, proc=proc})
  30. end
  31.  
  32. local function scan()
  33.   local plpos={}
  34.   local players = p.getPlayerUsernames()
  35.   for i=1,#players do
  36.     plpos[i]={}
  37.     pl=p.getPlayerByName(players[i])
  38.     ent=pl.asEntity()
  39.     x,y,z=ent.getPosition()
  40.     plpos[i].x=math.floor(x/16)
  41.     plpos[i].z=math.floor(z/16)
  42.   end
  43.   term.setBackgroundColor(MenuBg)
  44.   term.clear()
  45.   term.setTextColor(Chunk)
  46.   for i=1,19 do
  47.     z=cz+i-10
  48.     term.setCursorPos(1,i)
  49.     for x=cx-9,cx+9 do
  50.       if w.isChunkLoaded(x, z) then term.setBackgroundColor(ActiveChunk)
  51.       else term.setBackgroundColor(Chunk) end
  52.       for j=1,#plpos do
  53.         if x==plpos[j].x and z==plpos[j].z then
  54.           term.setBackgroundColor(PlayerChunk)
  55.           break
  56.         end
  57.       end
  58.       if x==cx and z==cz  then
  59.         term.setTextColor(colors.red)
  60.       end
  61.       write('[]')
  62.       term.setTextColor(Chunk)
  63.     end
  64.     n=9
  65.     for j=1,#plpos do
  66.       if cx==plpos[j].x and cz==plpos[j].z then
  67.         term.setCursorPos(40,n) write(players[i])
  68.         n=n+1
  69.       end
  70.     end
  71. --    sleep(0)
  72.   end
  73.   term.setTextColor(colors.black)
  74.   term.setBackgroundColor(MenuBg)
  75.   term.setCursorPos(40,1) write('x='..16*cx..','..cx*16+15)
  76.   term.setCursorPos(40,2) write('z='..16*cz..','..cz*16+15)
  77.   term.setBackgroundColor(MenuBtn)
  78.   for i=1,#buttons do
  79.     term.setCursorPos(buttons[i].x1,buttons[i].y) write(buttons[i].name)
  80.   end
  81.   scantimer=os.startTimer(10)
  82. end
  83.  
  84. eventKey[keys.left]=function()
  85.   cx=cx-5 scan()
  86. end
  87.  
  88. eventKey[keys.right]=function()
  89.   cx=cx+5 scan()
  90. end
  91.  
  92. eventKey[keys.up]=function()
  93.   cz=cz-5 scan()
  94. end
  95.  
  96. eventKey[keys.down]=function()
  97.   cz=cz+5 scan()
  98. end
  99.  
  100. eventKey[keys.f10]=function()
  101.   work=false
  102. end
  103.  
  104. function goto()
  105.   term.setCursorPos(40,5) write('x=') cx=math.floor((tonumber(read()) or 0)/16)
  106.   term.setCursorPos(40,6) write('z=') cz=math.floor((tonumber(read()) or 0)/16)
  107. end
  108.  
  109. function jamp()
  110.   term.setCursorPos(40,7) write('Name ')
  111.   pl=p.getPlayerByName(read())
  112.   if pl then
  113.     term.setCursorPos(40,8) write('y=')
  114.     x=cx*16+8
  115.     y=tonumber(read())
  116.     z=cz*16+8
  117.     if not y then
  118.       y=255
  119.       while w.getBlockID(x, y, z)==0 and y>0 do y=y-1 end
  120.       y=y+1
  121.     end
  122.     ent=pl.asEntity()
  123.     ent.setPosition(x,y,z)
  124.   end
  125. end
  126.  
  127. function search()
  128.   term.setCursorPos(40,9) write('blockID=') id=tonumber(read())
  129.   if id then
  130.     for y=0,255 do
  131.       term.setCursorPos(40,10) write('y='..y..' ')
  132.       for x=cx*16,cx*16+15 do
  133.         for z=cz*16,cz*16+15 do
  134.           if w.getBlockID(x, y, z)==id then
  135.             term.setCursorPos(40,11) write('x='..x..'  ')
  136.             term.setCursorPos(40,12) write('z='..z..'  ')
  137.             term.setCursorPos(40,13) write('meta='..w.getMetadata(x, y, z)..'  ')
  138.             term.setCursorPos(40,14) write('Press Enter') read()
  139.             term.setCursorPos(40,14) write('           ')
  140.           end
  141.         end
  142.       end
  143.       sleep(0)
  144.     end
  145.   end
  146. end
  147.  
  148. AddButton(' Goto ',43,4,goto)
  149. AddButton(' Jamp ',43,6,jamp)
  150. AddButton('Search',43,8,search)
  151. AddButton(' Exit ',43,18,function() work=false end)
  152. scan()
  153. while work do
  154.   local event,p1,mx,my=os.pullEvent()
  155.   if event=='key' then
  156.     if eventKey[p1]~=nil then eventKey[p1]() end
  157.   elseif event=='mouse_click' then
  158.     if mx>38 then
  159.       term.setTextColor(colors.black)
  160.       term.setBackgroundColor(MenuBg)
  161.       for i=1,#buttons do
  162.         if my==buttons[i].y and mx>=buttons[i].x1 and mx<=buttons[i].x2 then
  163.           buttons[i].proc()
  164.           scan()
  165.         end
  166.       end
  167.     else
  168.       mx=math.ceil(mx/2)
  169.       cx=cx+mx-10
  170.       cz=cz+my-10
  171.       scan()
  172.     end
  173. --  elseif event=='mouse_drag' then
  174.   elseif event=='timer' then
  175.     if p1==scantimer then scan() end
  176.   end
  177. end
  178.  
  179. inifile=fs.open(inifilename,'w')
  180. inifile.writeLine('cx='..cx..' cz='..cz)
  181. inifile.close()
  182. term.setTextColor(colors.white)
  183. term.setBackgroundColor(colors.black)
  184. term.clear()
  185. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement