mapAddOns Safe Delete and Move selected Rooms up or down on z axis

Share your scripts and packages with other Mudlet users.
Post Reply
jieiku
Posts: 33
Joined: Fri Mar 01, 2019 1:25 pm
Contact:

mapAddOns Safe Delete and Move selected Rooms up or down on z axis

Post by jieiku » Wed Mar 20, 2019 8:47 am

I attached the xml file, its a script file, code is also here if you rather enter it yourself instead of importing the xml file.

There is no collision checking on this, so depending on what your needing to do, you may get stacked rooms after changing your z axis, just keep that in mind.

This was extended from Jor'Mox Map Addons script (Thank You Jor'Mox!!!)
In that script the safedelete worked fine, but the shift rooms was not working for me.
The teleport here is now built in to mudlet by selecting "set location".
So I just kept the "safe delete" portion of Jor'Mox script and extended it with the Shift Up and Shift Down entries.

mapAddon script:
Code: [show] | [select all] lua
mapAddOns = mapAddOns or {}

local function safeDelete(ids)
    for _, id in ipairs(ids) do
        id = tonumber(id)
        local rooms = {}
        for _, room in ipairs(getAllRoomEntrances(id)) do
            for dir, exit in pairs(getRoomExits(room)) do
                if exit == id then
                    if rooms[room] then
                        if type(rooms[room]) == "table" then
                            table.insert(rooms[room],dir)
                        else
                            rooms[room] = {rooms[room], dir}
                        end
                    else
                        rooms[room] = dir
                    end
                end
            end
        end
        deleteRoom(id)
        for rid, dirs in pairs(rooms) do
            if type(dirs) == "table" then
                for _, dir in ipairs(dirs) do
                    setExitStub(rid, dir, true)
                end
            else
                setExitStub(rid, dirs, true)
            end
        end
    end
    updateMap()
end

local function shiftZ(direction)
  local selectedRooms = getMapSelection()
  for i in pairs(selectedRooms.rooms) do
  	local x,y,z = getRoomCoordinates(selectedRooms.rooms[i])
  	setRoomCoordinates(selectedRooms.rooms[i], x, y, z+direction)
  end
	updateMap()
end

function mapAddOns.eventHandler(event, mapEvent, ...)
    if event == "mapAddOnEvent" then
        if mapEvent == "safeDelete" then
            safeDelete(arg)
        elseif mapEvent == "shiftUp" then          
            shiftZ(1)
        elseif mapEvent == "shiftDown" then
            shiftZ(-1)
        end
    elseif event == "mapOpenEvent" then
        local events = {safeDelete = "Safe Delete", shiftUp = "Shift Up", shiftDown = "Shift Down"}
        local mapEvents = getMapEvents()
        for event, name in pairs(events) do
            if not mapEvents[event] then
                addMapEvent(event, "mapAddOnEvent","",name)
            end
        end
    end
end

registerAnonymousEventHandler("mapAddOnEvent","mapAddOns.eventHandler")
registerAnonymousEventHandler("mapOpenEvent","mapAddOns.eventHandler")
Attachments
mapAddons.xml
(2.38 KiB) Downloaded 53 times

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests