I've been trying to get your MSDP script (on page18) working with my MUD (Legends of Kallisti, legendsofkallisti.com/4000); however, it seems to be running into some issues where the coordinates aren't being set correctly for some rooms while others are. I'm having issues with figuring out why. I've attached the code so you can take a look at where I setup the MSDP functions and added a setRoomName call. Any help would be appreciated!
Code: Select all
map = map or {}
map.room_info = map.room_info or {}
map.prev_info = map.prev_info or {}
map.aliases = map.aliases or {}
local defaults = {
-- using Geyser to handle the mapper in this, since this is a totally new script
mapper = {x = "-21%", y = 0, width = "20%", height = "30%"}
}
local terrain_types = {
-- used to make rooms of different terrain types have different colors
-- add a new entry for each terrain type, and set the color with RGB values
-- each id value must be unique, terrain types not listed here will use mapper default color
["Inside"] = {id = 1, r = 255, g = 0, b = 0},
}
-- list of possible movement directions and appropriate coordinate changes
local move_vectors = {
north = {0,1,0}, south = {0,-1,0}, east = {1,0,0}, west = {-1,0,0},
northwest = {-1,1,0}, northeast = {1,1,0}, southwest = {-1,-1,0}, southeast = {1,-1,0},
up = {0,0,1}, down = {0,0,-1}
}
-- used to convert short dirs for full dirs
local exits = {
n = "north", s = "south", w = "west", e = "east",
nw = "northwest", ne = "northeast", sw = "southwest", se = "southeast",
u = "up", d = "down"
}
local exitmap = {[1] = "north", [2] = "northeast", [3] = "northwest", [4] = "east",
[5] = "west", [6] = "south", [7] = "southeast", [8] = "southwest",
[9] = "up", [10] = "down", [11] = "in", [12] = "out",}
local function make_room()
local info = map.room_info
local coords = {0,0,0}
addRoom(info.vnum)
setRoomName(info.vnum, info.name)
local areas = getAreaTable()
local areaID = areas[info.area]
if not areaID then
areaID = addAreaName(info.area)
else
coords = {getRoomCoordinates(map.prev_info.vnum)}
local shift = {0,0,0}
for k,v in pairs(map.prev_info.exits) do
echo("\nv: " .. v .. " info.vnum: " .. info.vnum .. "\n")
if v == info.vnum and move_vectors[k] then
shift = move_vectors[k]
break
end
end
echo("final shift:\n")
display(shift)
for n = 1,3 do
coords[n] = coords[1] + shift[n]
end
-- map stretching
local overlap = getRoomsByPosition(areaID,coords[1],coords[2],coords[3])
if not table.is_empty(overlap) then
local rooms = getAreaRooms(areaID)
local rcoords
for _,id in ipairs(rooms) do
rcoords = getRoomCoordinates(id)
echo("RCOORDS:\n")
display(rcoords)
for n = 1,3 do
echo("shift["..n.."]: " .. shift[n] .. " coords[n]: " .. coords[n] .. "\n")
if shift[n] ~= 0 and (rcoords[n] - coords[n]) * shift[n] >= 0 then
rcoords[n] = rcoords[n] + shift[n]
end
end
echo("\nCOORDS:\n")
display(rcoords)
setRoomCoords(id,rcoords[1],rcoords[2],rcoords[3])
end
end
end
setRoomArea(info.vnum, areaID)
--setRoomName(info.vnum, info.name)
setRoomCoordinates(info.vnum, coords[1], coords[2], coords[3])
if terrain_types[info.terrain] then
setRoomEnv(info.vnum, terrain_types[info.terrain].id)
end
for dir, id in pairs(info.exits) do
-- need to see how special exits are represented to handle those properly here
if getRoomName(id) then
setExit(info.vnum, id, dir)
else
setExitStub(info.vnum, dir, true)
end
end
end
local function shift_room(dir)
local ID = map.room_info.vnum
local x,y,z = getRoomCoordinates(ID)
local x1,y1,z1 = move_vector[dir]
x = x + x1
y = y + y1
z = z + z1
setRoomCoordinates(ID,x,y,z)
updateMap()
end
local function handle_move()
local info = map.room_info
if not getRoomName(info.vnum) then
make_room()
else
local stubs = getExitStubs1(info.vnum)
if stubs then
for _, n in ipairs(stubs) do
local dir = exitmap[n]
local id = info.exits[dir]
-- need to see how special exits are represented to handle those properly here
if getRoomName(id) then
setExit(info.vnum, id, dir)
end
end
end
end
centerview(map.room_info.vnum)
end
local function config()
-- don't actually know how MSDP works... but this seems to be in line with the examples I have seen
-- setting terrain colors
for k,v in pairs(terrain_types) do
setCustomEnvColor(v.id, v.r, v.g, v.b, 255)
end
-- making mapper window
local info = defaults.mapper
Geyser.Mapper:new({name = "myMap", x = info.x, y = info.y, width = info.width, height = info.height})
-- clearing existing aliases if they exist
for k,v in pairs(map.aliases) do
killAlias(k)
end
-- making an alias to let the user shift a room around via command line
table.insert(map.aliases,tempAlias([[^shift (\w+)$]],[[raiseEvent("shiftRoom",matches[2])]]))
table.insert(map.aliases,tempAlias([[^make_room$]],[[make_room()]]))
end
function map.eventHandler(event,...)
-- don't actually know how MSDP works... but this seems to be in line with the examples I have seen
if event == "msdp.ROOM_VNUM" then
local roomExits = {}
for k, v in pairs(msdp.ROOM_EXITS) do
if tonumber(v) then
roomExits[k] = tonumber(v)
end
end
--tempTimer(1, function()
map.prev_info = map.room_info
echo("\nPREVINFO:\n")
display(map.prev_info)
map.room_info = table.update({}, {vnum = tonumber(msdp.ROOM_VNUM), area = msdp.AREA_NAME, name = msdp.ROOM_NAME, exits = roomExits})
echo("\nROOMINFO:\n")
display(map.room_info)
handle_move()
--end)
elseif event == "shiftRoom" then
local dir = exits[arg[1]] or arg[1]
if not table.contains(exits, dir) then
echo("Error: Invalid direction '" .. dir .. "'.")
else
shift_room(dir)
end
elseif event == "sysConnectionEvent" then
config()
end
end
registerAnonymousEventHandler("msdp.ROOM_VNUM","map.eventHandler")
registerAnonymousEventHandler("shiftRoom","map.eventHandler")
registerAnonymousEventHandler("sysConnectionEvent", "map.eventHandler")