Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mmp.game = false
- function mmp.echo(what)
- moveCursorEnd("main") if getCurrentLine() ~= "" then echo"\n" end
- decho("<112,229,0>(<73,149,0>mapper<112,229,0>): <255,255,255>")
- cecho(what)
- echo("\n")
- end
- function mmp.echon(what)
- moveCursorEnd("main") if getCurrentLine() ~= "" then echo"\n" end
- decho("<112,229,0>(<73,149,0>mapper<112,229,0>): <255,255,255>")
- cecho(what)
- end
- function mmp.deleteLineP()
- deleteLine()
- tempLineTrigger(1,1,[[
- if isPrompt() then deleteLine() end
- ]])
- end
- function mmp.pause(what)
- assert(what == nil or what == "on" or what == "off", "mmp.pause wants 'on', 'off' or nothing as an argument")
- if what == "on" or (what == nil and not mmp.paused) then
- mmp.paused = true
- elseif what == "off" or (what == nil and mmp.paused) then
- mmp.paused = false
- end
- mmp.echo("Speedwalking " .. (mmp.paused and "paused" or "unpaused") .. ".")
- if not mmp.paused then mmp.move() end
- end
- function mmp.getnums(roomname)
- local t = mmp.searchRoom(roomname)
- if not next(t) then
- return nil end
- local result = {}
- if not tonumber(select(2, next(t))) then
- for roomid,_ in pairs(t) do
- if roomid ~= 0 then result[#result+1] = tonumber(roomid) end
- end
- else
- for _,roomid in pairs(t) do
- if roomid ~= 0 then result[#result+1] = tonumber(roomid) end
- end
- end
- return result
- end
- -- for a given room name, we'll echo all the vnums
- function mmp.echonums(roomname, exact)
- local t = mmp.searchRoom(roomname)
- if not next(t) then
- echo "?" return nil end
- -- transform the kv table into a table of tables for cleaner code.
- -- + perhaps Mudlet in future will give this us anyway, sorted by relevancy
- local dt = {}
- if not tonumber(select(2, next(t))) then
- for roomid,room in pairs(t) do
- if not exact then
- dt[#dt+1] = {name = room, id = roomid}
- else
- if room:lower() == roomname:lower() then
- dt[#dt+1] = {name = room, id = roomid}
- end
- end
- end
- else
- for room,roomid in pairs(t) do
- if not exact then
- dt[#dt+1] = {name = room, id = roomid}
- else
- if room:lower() == roomname:lower() then
- dt[#dt+1] = {name = room, id = roomid}
- end
- end
- end
- end
- -- we can have nothing if we asked for exact match
- if not dt[1] then echo "?" return end
- -- display first three ids. Can't really nicely table.concat them.
- echoLink(dt[1].id, 'mmp.gotoRoom('..dt[1].id..')', string.format("Go to %s (%s)", dt[1].id, dt[1].name))
- if not dt[2] then return end
- echo", "
- echoLink(dt[2].id, 'mmp.gotoRoom('..dt[2].id..')', string.format("Go to %s (%s)", dt[2].id, dt[2].name))
- if not dt[3] then return end
- echo", "
- echoLink(dt[3].id, 'mmp.gotoRoom('..dt[3].id..')', string.format("Go to %s (%s)", dt[3].id, dt[3].name))
- if not dt[4] then return end
- echo", ..."
- end
- function mmp.roomEcho(query)
- local result = mmp.searchRoom(query)
- if not tonumber(select(2, next(result))) then
- for roomid, roomname in pairs(result) do roomid = tonumber(roomid)
- cecho("<DarkSlateGrey> (<blue>")
- echoLink(roomid, 'mmp.gotoRoom('..roomid..')', string.format("Go to %s (%s)", roomid, tostring(roomname)))
- cecho("<DarkSlateGrey>)")
- end
- else
- for roomname, roomid in pairs(result) do roomid = tonumber(roomid)
- cecho("<DarkSlateGrey> (<blue>")
- echoLink(roomid, 'mmp.gotoRoom('..roomid..')', string.format("Go to %s (%s)", roomid, tostring(roomname)))
- cecho("<DarkSlateGrey>)")
- end
- end
- end
- -- searchRoom with a cache!
- local cache = {}
- setmetatable(cache, {__mode = "kv"}) -- weak keys/values = it'll periodically get cleaned up by gc
- function mmp.searchRoom(what)
- local result = cache[what]
- if not result then
- result = searchRoom(what)
- local realResult = {}
- for key, value in pairs(result) do
- -- both ways, because searchRoom can return either id-room name or the reverse
- if type(key) == "string" then
- realResult[key:ends(" (road)") and key:sub(1, -8) or key] = value
- else
- realResult[key] = value:ends(" (road)") and value:sub(1, -8) or value
- end
- end
- cache[what] = realResult
- result = realResult
- end
- return result
- end
- local getpathcache = {}
- setmetatable(getpathcache, {__mode = "kv"}) -- weak keys/values = it'll periodically get cleaned up by gc
- function mmp.searchRoomExact(what)
- local roomTable = mmp.searchRoom(what)
- local realResult = {}
- for key, value in pairs (roomTable) do
- if (key == what or value == what) then
- if (type(key) == "string") then
- realResult[key:ends(" (road)") and key:sub(1, -8) or key] = value
- else
- realResult[key] = value:ends(" (road)") and value:sub(1, -8) or value
- end
- end
- end
- if (table.is_empty(realResult)) then
- return roomTable
- else
- return realResult
- end
- end
- function mmp.roomWhoFind(query)
- if query:ends('.') then query = query:sub(1,-2) end
- local result = mmp.searchRoomExact(query)
- if type(result) == "string" or not next(result) then
- cecho("<CadetBlue> You have no recollection of any room with that name.") return end
- if not tonumber(select(2, next(result))) then -- old style
- for roomid, roomname in pairs(result) do roomid = tonumber(roomid)
- cecho(string.format(" <LightSlateGray>%s<DarkSlateGrey> (<blue>",
- tostring(roomname)))
- echoLink(roomid, 'mmp.gotoRoom('..roomid..')', string.format("Go to %s (%s)", roomid, tostring(roomname)))
- cecho(string.format("<DarkSlateGrey>) <white>%s<DarkSlateGrey>.\n", tostring(mmp.areatabler[getRoomArea(roomid)])))
- end
- else -- new style
- for roomname, roomid in pairs(result) do roomid = tonumber(roomid)
- cecho(string.format(" <LightSlateGray>%s<DarkSlateGrey> (<blue>",
- tostring(roomname)))
- echoLink(roomid, 'mmp.gotoRoom('..roomid..')', string.format("Go to %s (%s)", roomid, tostring(roomname)))
- cecho(string.format("<DarkSlateGrey>) <white>%s<DarkSlateGrey>.\n", tostring(mmp.areatabler[getRoomArea(roomid)])))
- end
- end
- end
- -- DOES NOT ACCOUNT FOR CHANGING THE MAP YET (within a profile load), because we don't know when it happens
- function mmp.getPath(from, to)
- assert(tonumber(from) and tonumber(to), "mmp.getPath: both from and to have to be room IDs")
- local key = string.format("%s_%s", from, to)
- local resulttbl = getpathcache[key]
- -- not in cache?
- if not resulttbl then
- local boolean = getPath(from, to)
- -- save it into the cache & send away
- getpathcache[key] = {boolean, speedWalkDir, speedWalkPath}
- return boolean
- end
- -- or if it is, retrieve & send away
- speedWalkDir = getpathcache[key][2]
- speedWalkPath = getpathcache[key][3]
- return getpathcache[key][1]
- end
- function mmp.roomFind(query)
- if query:ends('.') then query = query:sub(1,-2) end
- local result = mmp.searchRoom(query)
- if type(result) == "string" or not next(result) then
- cecho("<grey>You have no recollection of any room with that name.") return end
- cecho("<DarkSlateGrey>You know the following relevant rooms::\n")
- currentRoom = mmp.currentroom
- if not tonumber(select(2, next(result))) then -- old style
- for roomid, roomname in pairs(result) do roomid = tonumber(roomid)
- cecho(string.format(" <LightSlateGray>%s<DarkSlateGrey> (<blue>",
- tostring(roomname)))
- echoLink(roomid, 'mmp.gotoRoom('..roomid..')', string.format("Go to %s (%s)", roomid, tostring(roomname)))
- cecho(string.format("<DarkSlateGrey>) in the <LightSlateGray>%s<DarkSlateGrey>.", tostring(mmp.areatabler[getRoomArea(roomid)])))
- _G.roomid = roomid
- echoLink(" > Show path\n", [[echoPath(currentRoom, roomid)]], "Display directions" .. roomid, true)
- end
- else -- new style
- for roomname, roomid in pairs(result) do roomid = tonumber(roomid)
- cecho(string.format(" <LightSlateGray>%s<DarkSlateGrey> (<blue>",
- tostring(roomname)))
- echoLink(roomid, 'mmp.gotoRoom('..roomid..')', string.format("Go to %s (%s)", roomid, tostring(roomname)))
- cecho(string.format("<DarkSlateGrey>) in the <LightSlateGray>%s<DarkSlateGrey>.\n", tostring(mmp.areatabler[getRoomArea(roomid)])))
- _G.roomid = roomid
- echoLink(" > Show path\n", [[echoPath(currentRoom, roomid)]], "Display directions", true)
- end
- end
- cecho(string.format(" <DarkSlateGrey>%d rooms found.\n", table.size(result)))
- end
- function mmp.findAreaID(areaname, exact)
- local areaname = areaname:lower()
- local list = getAreaTable()
- -- iterate over the list of areas, matching them with substring match.
- -- if we get match a single area, then return it's ID, otherwise return
- -- 'false' and a message that there are than one are matches
- local returnid, fullareaname, multipleareas = nil, nil, {}
- for area, id in pairs(list) do
- if (not exact and area:lower():find(areaname, 1, true)) or (exact and areaname == area:lower()) then
- returnid = id; fullareaname = area; multipleareas[#multipleareas+1] = area
- end
- end
- if #multipleareas == 1 then
- return returnid, fullareaname
- else
- return nil, nil, multipleareas
- end
- end
- function mmp.echoRoomList(areaname, exact)
- local id, msg, multiples = mmp.findAreaID(areaname, exact)
- if id then
- local roomlist, endresult = getAreaRooms(id), {}
- -- obtain a room list for each of the room IDs we got
- for _, id in pairs(roomlist) do
- endresult[id] = getRoomName(id)
- end
- -- sort room IDs so we can display them in order
- table.sort(roomlist)
- -- now display something half-decent looking
- cecho(string.format(
- "<DarkSlateGrey>List of all rooms in <grey>%s<DarkSlateGrey> (<grey>%d<DarkSlateGrey>):\n", msg, table.size(endresult)))
- for _, roomid in ipairs(roomlist) do
- local roomname = endresult[roomid]
- fg("blue") echoLink(string.format("%6s", roomid), 'mmp.gotoRoom('..roomid..')', string.format("Go to %s (%s)", roomid, tostring(roomname)), true)
- cecho(string.format("<DarkSlateGrey>: <LightSlateGray>%s<DarkSlateGrey>.\n", roomname))
- end
- elseif not id and #multiples > 0 then
- mmp.echo("For which area would you want to list rooms for?")
- fg("DimGrey")
- for _, areaname in ipairs(multiples) do
- echo" "; setUnderline(true) echoLink(areaname, 'mmp.echoRoomList("'..areaname..'", true)', "Click to view the room list for "..areaname, true) setUnderline(false) echo"\n"
- end
- resetFormat()
- else
- mmp.echo(string.format("Don't know of any area named '%s'.", areaname))
- end
- end
- function mmp.echoAreaList()
- local list = getAreaTable()
- local ids, rlist = {}, {}
- for area, id in pairs(list) do
- if id ~= 0 then ids[#ids+1] = id; rlist[id] = area end end
- table.sort(ids)
- cecho(string.format(
- "<DarkSlateGrey>List of all areas we know of (click to view room list):\n"))
- for _, id in pairs(ids) do
- cecho(string.format("<blue>%s%d ", string.rep(" ", (6-#tostring(id))), id))
- fg("DarkSlateGrey") echoLink(rlist[id], 'mmp.echoRoomList("'..rlist[id]..'", true)', "View the room list for "..rlist[id], true) echo("\n")
- end
- end
- function mmp.clearLabels(areaid)
- assert(type(areaid) == "number", "mmp.clearLabels: areaid must be a number")
- local t = getMapLabels(areaid)
- if type(t) ~= "table" then return end
- for labelid, _ in pairs(t) do deleteMapLabel(areaid, labelid) end
- mmp.echo(string.format("Cleared all labels in '%s'.", mmp.areatabler[areaid]))
- end
- function mmp.roomLook(input)
- -- we can do a report with a number
- local function handle_number(num)
- -- compile all available data
- if not mmp.roomexists(num) then mmp.echo(num.." doesn't seem to exist.") return end
- local s, areanum = pcall(getRoomArea,num)
- if not s then mmp.echo(areanum); return; end
- local exits = getRoomExits(num)
- local name = getRoomName(num)
- local islocked = roomLocked(num)
- local weight = (getRoomWeight(num) and getRoomWeight(num) or "?") -- getRoomWeight is buggy in one of the versions, is actually linked to setRoomWeight and thus returns nil
- local coords = {getRoomCoordinates(num)}
- local specexits = getSpecialExits(num)
- local env = getRoomEnv(num)
- local envname = (mmp.envidsr and mmp.envidsr[env]) or "?"
- -- generate a report
- mmp.echo(string.format("Room: %s #: %d area: %s (%d)",
- name, num, tostring(mmp.areatabler[areanum]), areanum))
- mmp.echo(string.format("Coordinates: x:%d, y:%d, z:%d, locked: %s, weight: %s", coords[1], coords[2], coords[3], (islocked and "yep" or "nope"), tostring(weight)))
- mmp.echo(string.format("Environment: %s (%d)", tostring(envname), env))
- mmp.echo(string.format("Exits (%d):", table.size(exits)))
- for exit, leadsto in pairs(exits) do
- echo(string.format(" %s -> %s (%d)%s\n", exit, getRoomName(leadsto), leadsto,
- ((getRoomArea(leadsto) or "?") == areanum and ""
- or " (in "..(mmp.areatabler[getRoomArea(leadsto)] or "?")..")")))
- end
- -- display special exits if we got any
- if next(specexits) then
- mmp.echo(string.format("Special exits (%d):",table.size(specexits)))
- for leadsto, command in pairs(specexits) do
- echo(string.format(" %s -> %s (%d)\n", command, getRoomName(leadsto), leadsto))
- end
- end
- -- actions we can do. This will be a short menu of sorts for actions
- mmp.echo("Stuff you can do:")
- echo" " echoLink("Clear all labels in this area", 'mmp.clearLabels('..areanum..')', '') echo"\n"
- end
- -- see if we can do anything with the name
- local function handle_name(name)
- local result = mmp.searchRoom(name)
- if type(result) == "string" then
- cecho("<grey>You have no recollection of any room with that name.") return end
- -- if we got one result, then act on it
- if table.size(result) == 1 then
- if type(next(result)) == "number" then
- handle_number(next(result))
- else
- handle_number(select(2, next(result)))
- end
- return
- end
- -- if not, then ask the user to clarify which one would they want
- mmp.echo("Which room specifically would you like to look up?")
- if not select(2, next(result)) or not tonumber(select(2, next(result))) then
- for roomid, roomname in pairs(result) do roomid = tonumber(roomid)
- cecho(string.format(" <LightSlateGray>%s<DarkSlateGrey> (<blue>",
- tostring(roomname)))
- echoLink(roomid, 'mmp.roomLook('..roomid..')', string.format("View room details for %s (%s)", roomid, tostring(roomname)))
- cecho(string.format("<DarkSlateGrey>) in the <LightSlateGray>%s<DarkSlateGrey>.\n", tostring(mmp.areatabler[getRoomArea(roomid)])))
- end
- else
- for roomname, roomid in pairs(result) do roomid = tonumber(roomid)
- cecho(string.format(" <LightSlateGray>%s<DarkSlateGrey> (<blue>",
- tostring(roomname)))
- echoLink(roomid, 'mmp.roomLook('..roomid..')', string.format("View room details for %s (%s)", roomid, tostring(roomname)))
- cecho(string.format("<DarkSlateGrey>) in the <LightSlateGray>%s<DarkSlateGrey>.\n", tostring(mmp.areatabler[getRoomArea(roomid)])))
- end
- end
- end
- if not input then
- if not mmp.roomexists(mmp.currentroom) then
- mmp.echo(mmp.currentroom.. " doesn't seem to be mapped yet.")
- else input = mmp.currentroom end
- end
- if tonumber(input) then
- handle_number(tonumber(input))
- else
- handle_name(input)
- end
- mmp.echo(string.format("version %s.", tostring(mmp.version)))
- end
- function mmp.roomexists(num)
- if not num then return false end
- if roomExists then return roomExists(num) end
- local s,m = pcall(getRoomArea, tonumber(num))
- return (s and true or false)
- end
- -- translates n to north and so forth
- function mmp.anytolong(exit)
- local t = {
- n = "north",
- e = "east",
- s = "south",
- w = "west",
- ne = "northeast",
- se = "southeast",
- sw = "southwest",
- nw = "northwest",
- u = "up",
- d = "down",
- i = "in",
- o = "out"
- }
- for s, l in pairs(t) do t[l] = l end
- return t[exit]
- end
- function mmp.anytoshort(exit)
- local t = {
- n = "north",
- e = "east",
- s = "south",
- w = "west",
- ne = "northeast",
- se = "southeast",
- sw = "southwest",
- nw = "northwest",
- u = "up",
- d = "down",
- ["in"] = "in",
- out = "out"
- }
- local rt = {}
- for s,l in pairs(t) do
- rt[l] = s; rt[s] = s
- end
- return rt[exit]
- end
- function mmp.ranytolong(exit)
- local t = {
- n = "south",
- north = "south",
- e = "west",
- east = "west",
- s = "north",
- south = "north",
- w = "east",
- west = "east",
- ne = "southwest",
- northeast = "southwest",
- se = "northwest",
- southeast = "northwest",
- sw = "northeast",
- southwest = "northeast",
- nw = "southeast",
- northwest = "southeast",
- u = "down",
- up = "down",
- d = "up",
- down = "up",
- i = "out",
- ["in"] = "out",
- o = "in",
- out = "in"
- }
- return t[exit]
- end
- -- returns nil or the room number relative to this one
- function mmp.relativeroom(from, dir)
- if not mmp.roomexists(from) then return end
- local exits = getRoomExits(tonumber(from))
- return exits[mmp.anytolong(dir)]
- end
- function mmp.deleteArea(name, exact)
- local id, fname, ma = mmp.findAreaID(name, exact)
- if id then
- deleteArea(id)
- mmp.echo(string.format("Deleted %s (%d).", fname, id))
- centerview(mmp.currentroom)
- elseif next(ma) then
- mmp.echo("Which one of these specifically would you like to delete?")
- fg("DimGrey")
- for _,name in ipairs(ma) do
- echo " " setUnderline(true) echoLink(name, [[mmp.deleteArea("]]..name..[[", true)]], "Delete "..name, true) setUnderline(false) echo"\n"
- end
- resetFormat()
- else
- mmp.echo("Don't know of that area.")
- end
- raiseEvent("mmp areas changed")
- end
- function mmp.renameArea(name, exact)
- if not (mmp.currentroom or getRoomArea(mmp.currentroom)) then
- mmp.echo("Don't know what area are we in at the moment, to rename it.")
- else
- setAreaName(getRoomArea(mmp.currentroom), name)
- mmp.echo(string.format("Renamed %s to %s (%d).", mmp.areatabler[getRoomArea(mmp.currentroom)], name, getRoomArea(mmp.currentroom)))
- centerview(mmp.currentroom)
- end
- raiseEvent("mmp areas changed")
- end
- function mmp.roomArea(otherroom, name, exact)
- local id,fname,ma
- if tonumber(name) then id = tonumber(name); fname = mmp.areatabler[id]
- else id, fname, ma = mmp.findAreaID(name, exact) end
- if otherroom ~= "" and not mmp.roomexists(otherroom) then
- mmp.echo("Room id "..otherroom.." doesn't seem to exist.")
- return
- elseif otherroom == "" and not mmp.roomexists(mmp.currentroom) then
- mmp.echo("Don't know where we are at the moment.")
- return
- end
- otherroom = otherroom ~= "" and otherroom or mmp.currentroom
- if id then
- setRoomArea(otherroom, id)
- mmp.echo(string.format("Moved %s to %s (%d).", (getRoomName(otherroom) ~= "" and getRoomName(otherroom) or "''"), fname, id))
- centerview(otherroom)
- elseif next(ma) then
- mmp.echo("Into which area exactly would you like to move the room?")
- fg("DimGrey")
- for _,name in ipairs(ma) do
- echo " " setUnderline(true) echoLink(name, [[mmp.roomArea('', "]]..name..[[", true)]], "Move the room to "..name, true) setUnderline(false) echo"\n"
- end
- resetFormat()
- else
- mmp.echo("Don't know of that area.")
- end
- end
- function mmp.getAreaBorders(areaid)
- local roomlist, endresult = getAreaRooms(areaid), {}
- -- sometimes getAreaRooms can give us no result :(
- if not roomlist then mmp.echo("Sorry, seems we can't go there - getAreaRooms("..areaid..") didn't give us any results (Mudlet problem - redownloading the map might help fix it)") return end
- -- obtain a room list for each of the room IDs we got
- for _, id in pairs(roomlist) do
- local exits = getRoomExits(id)
- for _, to in pairs(exits) do
- if not table.contains(roomlist, to) then
- endresult[id] = getRoomName(id)
- end
- end
- end
- return endresult
- end
- function mmp.locateAndEcho(room, person)
- local t = mmp.searchRoom(room)
- echo " ("
- mmp.echonums(room, true)
- echo ")"
- if not (t[room] or table.contains(t, room)) then return end
- echo"\n"
- if table.size(t) == 1 then
- local k,v = next(t)
- cecho("<red>From your knowledge, that room is in <orange_red>"..(mmp.areatabler[getRoomArea(type(k) == "number" and k or v)] or "?").."<red>.")
- else
- local k,v = next(t)
- local areas = {}
- if type(k) == "number" then
- for k, _ in pairs(t) do
- areas[mmp.areatabler[getRoomArea(k)] or "?"] = true
- end
- else
- for _, k in pairs(t) do
- areas[mmp.areatabler[getRoomArea(k)] or "?"] = true
- end
- end
- local flattened_areas = {}
- for k, _ in pairs(areas) do
- if k ~= "" then flattened_areas[#flattened_areas+1] = k end
- end
- cecho("<red>From your knowledge, that room might be in <orange_red>"..table.concat(flattened_areas, ", or ").."<red>.")
- end
- if person then
- mmp.pdb[person] = room
- mmp.pdb_lastupdate[person] = true
- raiseEvent("mmapper updated pdb")
- end
- end
- function mmp.viewArea (where, exact)
- if not where or not type(where)=="string" then
- mmp.echo("Which area would you like to view?") return end
- local areaid, msg, multiples = mmp.findAreaID(where, exact)
- if areaid then
- -- center on the first room ID, which typically is the start of an area
- centerview(getAreaRooms(areaid)[1])
- elseif not areaid and #multiples > 0 then
- mmp.echo("Which area would you like to view exactly?")
- fg("DimGrey")
- for _, areaname in ipairs(multiples) do
- echo" "; setUnderline(true) echoLink(areaname, 'mmp.viewArea("'..areaname..'", true)', "Click to view "..areaname, true) setUnderline(false) echo"\n"
- end
- resetFormat()
- return
- else
- mmp.echo(string.format("Don't know of any area named '%s'.", where))
- return
- end
- end
- -- room label the room I'm in
- -- room label 342 this is a label in room 342
- -- room label green this is a green label where I'm at
- -- room label green black this is a green to black label where I'm at
- -- room label 34 green black this is a green to black label at room 34
- -- how it works: split input string into tokens by space, then determine
- -- what to do by checking first few tokens, and finally call the local
- -- function with the proper arguments
- function mmp.roomLabel(input)
- if not createMapLabel then
- mmp.echo("Your Mudlet doesn't support createMapLabel() yet - please update to 2.0-test3 or better.") return
- end
- local tk = input:split(" ")
- local room, fg, bg, message = mmp.currentroom, "yellow", "red", "Some room label"
- -- input always have to be something, so tk[1] at least always exists
- if tonumber(tk[1]) then
- room = tonumber(table.remove(tk, 1)) -- remove the number, so we're left with the colors or msg
- end
- -- next: is this a foreground color?
- if tk[1] and color_table[tk[1]] then
- fg = table.remove(tk, 1)
- end
- -- next: is this a backround color?
- if tk[1] and color_table[tk[1]] then
- bg = table.remove(tk, 1)
- end
- -- the rest would be our message
- if tk[1] then
- message = table.concat(tk, " ")
- end
- -- if we haven't provided a room ID and we don't know where we are yet, we can't make a label
- if not room then
- mmp.echo("We don't know where we are to make a label here.") return
- end
- local x,y = getRoomCoordinates(room)
- local f1,f2,f3 = unpack(color_table[fg])
- local b1,b2,b3 = unpack(color_table[bg])
- -- finally: do it :)
- local lid = createMapLabel(getRoomArea(room), message, x, y, f1,f2,f3, b1,b2,b3)
- mmp.echo(string.format("Created new label #%d '%s' in %s.", lid, message, getRoomAreaName(getRoomArea(room))))
- end
- function mmp.areaLabels (where, exact)
- if not getMapLabels then
- mmp.echo("Your Mudlet doesn't support getMapLabels() yet - please update to 2.0-test3 or better.") return
- end
- if (not where or not type(where)=="string") and not mmp.currentroom then
- mmp.echo("For which area would you like to view labels?") return end
- if not where then
- exact = true
- where = getRoomAreaName(getRoomArea(mmp.currentroom))
- end
- local areaid, msg, multiples = mmp.findAreaID(where, exact)
- if areaid then
- local t = getMapLabels(areaid)
- if type(t) ~= "table" or not next(t) then
- mmp.echo(string.format("'%s' doesn't seem to have any labels.", getRoomAreaName(areaid)))
- return
- end
- mmp.echo(string.format("Area labels for '%s'", getRoomAreaName(areaid)))
- for labelid, labeltext in pairs(t) do
- fg("DimGrey")
- echo(string.format(" %d) %s (", labelid, labeltext))
- fg"orange_red" setUnderline(true) echoLink('-', string.format('deleteMapLabel(%d, %d)', areaid, labelid), "Delete label #"..labelid.." from "..getRoomAreaName(areaid))
- setUnderline(false) echo")\n"
- end
- resetFormat()
- elseif not areaid and #multiples > 0 then
- mmp.echo("Which area would you like to view exactly?")
- fg("DimGrey")
- for _, areaname in ipairs(multiples) do
- echo" "; setUnderline(true) echoLink(areaname, 'mmp.areaLabels("'..areaname..'", true)', "Click to view labels in "..areaname, true) setUnderline(false) echo"\n"
- end
- resetFormat()
- return
- else
- mmp.echo(string.format("Don't know of any area named '%s'.", where))
- return
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement