Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MenuBg=colors.lightGray
- MenuBtn=colors.green
- Chunk=colors.black
- ActiveChunk=colors.lightBlue
- PlayerChunk=colors.lime
- p = peripheral.wrap('bottom')
- w = p.getWorld(p.getPeripheralWorldID())
- --w={}
- --w.map={[0]={[0]=true,[10]=true},[5]={[5]=true},[10]={[10]=true}}
- --w.isChunkLoaded=function(x,z)
- -- if w.map[z] then return w.map[z][x] end
- --end
- inifilename='cscan.ini'
- term.clear()
- inifile=fs.open(inifilename,'r')
- if inifile then
- cx,cz=string.match(inifile.readLine(),'cx=(%d+)%s+cz=(%d+)')
- cx=tonumber(cx) cz=tonumber(cz)
- inifile.close()
- else
- cx=0 cz=0
- end
- local work=true
- local eventKey={}
- local scantimer
- local buttons={}
- local function AddButton(name,x,y,proc)
- table.insert(buttons,{name=name, x1=x, x2=x+#name-1, y=y, proc=proc})
- end
- local function scan()
- local plpos={}
- local players = p.getPlayerUsernames()
- for i=1,#players do
- plpos[i]={}
- pl=p.getPlayerByName(players[i])
- ent=pl.asEntity()
- x,y,z=ent.getPosition()
- plpos[i].x=math.floor(x/16)
- plpos[i].z=math.floor(z/16)
- end
- term.setBackgroundColor(MenuBg)
- term.clear()
- term.setTextColor(Chunk)
- for i=1,19 do
- z=cz+i-10
- term.setCursorPos(1,i)
- for x=cx-9,cx+9 do
- if w.isChunkLoaded(x, z) then term.setBackgroundColor(ActiveChunk)
- else term.setBackgroundColor(Chunk) end
- for j=1,#plpos do
- if x==plpos[j].x and z==plpos[j].z then
- term.setBackgroundColor(PlayerChunk)
- break
- end
- end
- if x==cx and z==cz then
- term.setTextColor(colors.red)
- end
- write('[]')
- term.setTextColor(Chunk)
- end
- n=9
- for j=1,#plpos do
- if cx==plpos[j].x and cz==plpos[j].z then
- term.setCursorPos(40,n) write(players[i])
- n=n+1
- end
- end
- -- sleep(0)
- end
- term.setTextColor(colors.black)
- term.setBackgroundColor(MenuBg)
- term.setCursorPos(40,1) write('x='..16*cx..','..cx*16+15)
- term.setCursorPos(40,2) write('z='..16*cz..','..cz*16+15)
- term.setBackgroundColor(MenuBtn)
- for i=1,#buttons do
- term.setCursorPos(buttons[i].x1,buttons[i].y) write(buttons[i].name)
- end
- scantimer=os.startTimer(10)
- end
- eventKey[keys.left]=function()
- cx=cx-5 scan()
- end
- eventKey[keys.right]=function()
- cx=cx+5 scan()
- end
- eventKey[keys.up]=function()
- cz=cz-5 scan()
- end
- eventKey[keys.down]=function()
- cz=cz+5 scan()
- end
- eventKey[keys.f10]=function()
- work=false
- end
- function goto()
- term.setCursorPos(40,5) write('x=') cx=math.floor((tonumber(read()) or 0)/16)
- term.setCursorPos(40,6) write('z=') cz=math.floor((tonumber(read()) or 0)/16)
- end
- function jamp()
- term.setCursorPos(40,7) write('Name ')
- pl=p.getPlayerByName(read())
- if pl then
- term.setCursorPos(40,8) write('y=')
- x=cx*16+8
- y=tonumber(read())
- z=cz*16+8
- if not y then
- y=255
- while w.getBlockID(x, y, z)==0 and y>0 do y=y-1 end
- y=y+1
- end
- ent=pl.asEntity()
- ent.setPosition(x,y,z)
- end
- end
- function search()
- term.setCursorPos(40,9) write('blockID=') id=tonumber(read())
- if id then
- for y=0,255 do
- term.setCursorPos(40,10) write('y='..y..' ')
- for x=cx*16,cx*16+15 do
- for z=cz*16,cz*16+15 do
- if w.getBlockID(x, y, z)==id then
- term.setCursorPos(40,11) write('x='..x..' ')
- term.setCursorPos(40,12) write('z='..z..' ')
- term.setCursorPos(40,13) write('meta='..w.getMetadata(x, y, z)..' ')
- term.setCursorPos(40,14) write('Press Enter') read()
- term.setCursorPos(40,14) write(' ')
- end
- end
- end
- sleep(0)
- end
- end
- end
- AddButton(' Goto ',43,4,goto)
- AddButton(' Jamp ',43,6,jamp)
- AddButton('Search',43,8,search)
- AddButton(' Exit ',43,18,function() work=false end)
- scan()
- while work do
- local event,p1,mx,my=os.pullEvent()
- if event=='key' then
- if eventKey[p1]~=nil then eventKey[p1]() end
- elseif event=='mouse_click' then
- if mx>38 then
- term.setTextColor(colors.black)
- term.setBackgroundColor(MenuBg)
- for i=1,#buttons do
- if my==buttons[i].y and mx>=buttons[i].x1 and mx<=buttons[i].x2 then
- buttons[i].proc()
- scan()
- end
- end
- else
- mx=math.ceil(mx/2)
- cx=cx+mx-10
- cz=cz+my-10
- scan()
- end
- -- elseif event=='mouse_drag' then
- elseif event=='timer' then
- if p1==scantimer then scan() end
- end
- end
- inifile=fs.open(inifilename,'w')
- inifile.writeLine('cx='..cx..' cz='..cz)
- inifile.close()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement