Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mapPath = "./data/map"
- logPath = "./data/queries/"
- myX, myY, myZ = gps.locate()
- myX = math.floor(myX)
- myY = math.floor(myY)
- myZ = math.floor(myZ)
- args = {...}
- if args[1] == "me" then
- print("I am at",myX,myY,myZ)
- elseif args[1] == "type" then
- getType = tostring(args[2])
- elseif args[1] == "pos" then
- if args[4] then
- getX = tonumber(args[2])
- getY = tonumber(args[3])
- getZ = tonumber(args[4])
- end
- else print("Usage:\n'query me'\n'query pos <x> <y> <z>'\n'query type <block_name>'") end
- if myX == getX and myY == getY and myZ == getZ then
- print("That's me! \2")
- elseif (getX ~= nil) or (getType ~= nil) then
- if not fs.exists(mapPath) then
- print("Requires map to exist")
- else
- mapFile = fs.open(mapPath, "r")
- map = mapFile.readAll()
- map = textutils.unserialise(map)
- mapFile.close()
- found = false
- qResult = {}
- for i = 1,#map do
- if getX and (found == false) then
- if map[i].x == getX and map[i].y == getY and map[i].z == getZ then
- name = map[i].name
- found = true
- end
- elseif getType ~= nil then
- name = map[i].name
- name = name:sub((string.find(name, ":"))+1,#name)
- if name == getType then
- found = true
- table.insert(qResult, {x=map[i].x,y=map[i].y,z=map[i].z})
- end
- end
- end
- if getType and found then
- print(found,#qResult)
- if #qResult < 2 then
- for res = 1,#qResult do
- write("Found @ "..qResult[res].x.." "..qResult[res].y.." "..qResult[res].z.."\n")
- end
- elseif #qResult > 1 then
- print("Save query result to file? <y/n>")
- evt, key = os.pullEvent("key")
- sleep(0)
- if key == keys.y then
- fName = getType.."_query"
- file = fs.open(logPath..fName, "w")
- for save = 1,#qResult do
- file.writeLine(qResult[save])
- end
- file.close()
- end
- end
- elseif getX and found then
- print(found,name)
- else print(found) end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment