Many thanks to Heiko for his assistance with this.
What I wanted was something really simple, everything I read had hundreds of lines of code. You will need to develop this and probably make some drastic changes, but this will at least allow you to play with the mapper.
This uses GMCP but if you can get the following from your mud by one means or another then this will probably work or at least not require a total overhaul to work.
RoomID, RoomName, ZoneName, ExitRooms
Also I used the Terrain to colour the map
- folder.PNG (5.55 KiB) Viewed 12004 times
the only scripts you need to make it work are mapSetup and roomEvent, the __ prefix just pretty it up a little.
helper functions - well it turned out I only made one and it just lists the rooms in a zone. What is handy is the ability to run lua from the command line and try to have a copy of the mapper API to hand.
the lua code is available on these forums i've copied it below but it isn't mine.
local f,e = loadstring("return "..matches[2])
if not f then
f,e = assert(loadstring(matches[2])) end
local a,b,c = f()
if a ~= nil then echo ("A: ") display(a,nil,1) end
if b ~= nil then echo ("B: ") display(b,nil,1) end
if c ~= nil then echo ("C: ") display(c,nil,1) end
if e ~= nil then echo ("Er: ") display(e,nil,1) end
it works from an alias
- lua.PNG (11.92 KiB) Viewed 12004 times
the helper function is
--helper functions
function echoRoomList(id)
local roomtable = getAreaRooms(id)or {}
-- obtain a room list for each of the room IDs we got
for _, id in ipairs(roomtable) do
local x,y,z = getRoomCoordinates(id)
echo("\n id "..id.." x "..x.." y "..y.." z "..z.." "..getRoomName(id))
end --for
end --function
Ok, so to the mapSetup
--map script exists
mudlet = mudlet or {}; mudlet.mapper_script = true
__debug__ = true;
addMapEvent("unHighlighCurrent","__unHighlightRoom")
-- map Setup
__mapper_room_x = 0
__mapper_room_y = 0
__mapper_room_z = 0
roomID = -1
The only things to mention here are
mudlet = mudlet or {}; mudlet.mapper_script = true tells mudlet a script exists
addMapEvent("unHighlighCurrent","__unHighlightRoom") adds an option to the right click menu to unhighlight rooms that have been highlighted because they collided i.e. 2 rooms have the same coordinates
The rest just to initialise a few things.
I should point out this doesn't use the preinstalled script. I think it works when you press the key to move, where as this works after you move by using the GMCP info.
I move using the keypad not the command line so I set lastmovedirection there. If the move fails, the GMCP doesnt get sent because I didn't move, so no harm done.
- keys.PNG (13.66 KiB) Viewed 12004 times
Not to tricky so far so onto the guts of it, roomEvent
The mud sends info like this. I included the use of the lua alias as well to show it in use. a picture speaks 1000 words.
- gmcp.PNG (9.55 KiB) Viewed 12004 times
And the script fires like this
- roomevent.PNG (10.78 KiB) Viewed 12004 times
function roomEvent( e )
_mapper_old_roomID = _mapper_roomID
_mapper_roomID = tonumber(gmcp.room.info.num)
display(gmcp.room.info)
initNewRoom( _mapper_roomID )
centerview(_mapper_roomID)
roomID = _mapper_roomID
end --function
function initNewRoom()
local isNewRoom = addRoom( _mapper_roomID )
local id = _mapper_roomID
local roomAreaName = gmcp.room.info.zone
local roomAreaID = addAreaName( roomAreaName );
if roomAreaID == -1 then
roomAreaID = getRoomAreaName( roomAreaName );
end --if
local stepLength = 1;
-- lastMoveDirection = command
-- I walk using the keypad so in the hotkeys I made lastMoveDirection = "north" etc
-- if you walk from the command line then use the above line but it does a compare a few
-- lines down so you might want to change north to n etc
if __debug__ then echo("last move command:"..lastMoveDirection.."\n") end--if
if isNewRoom then
if __debug__ then cecho("<red>ADDED new roomID: "..id.."\n") end--if
--set room name
local roomName = gmcp.room.info.name
setRoomName( id, roomName )
if __debug__ then cecho("<orange>ADDED room name: "..roomName.."\n") end--if
-- set room coordinates
if lastMoveDirection == "west" then --these might need set to 'w' etc
__mapper_room_x = __mapper_room_x - stepLength;
setExit(id, roomID, 4);
setExit(roomID, id, 5);
end--if
if lastMoveDirection == "east" then
__mapper_room_x = __mapper_room_x + stepLength;
setExit(id, roomID, 5);
setExit(roomID, id, 4);
end--if
if lastMoveDirection == "south" then
__mapper_room_y = __mapper_room_y - stepLength;
setExit(id, roomID, 1);
setExit(roomID, id, 6);
end--if
if lastMoveDirection == "north" then
__mapper_room_y = __mapper_room_y + stepLength;
setExit(id, roomID, 6);
setExit(roomID, id, 1);
end--if
if lastMoveDirection == "up" then
__mapper_room_z = __mapper_room_z + stepLength;
setExit(id, roomID, 10);
setExit(roomID, id, 9);
end--if
if lastMoveDirection == "down" then
__mapper_room_z = __mapper_room_z - stepLength;
setExit(id, roomID, 9);
setExit(roomID, id, 10);
end--if
cecho("<green>guessing new room coordinates\n")
setRoomCoordinates( id, __mapper_room_x, __mapper_room_y, __mapper_room_z )
setRoomArea( id, roomAreaID )-- set Area only for new rooms incase you change it
else
cecho("<green>KNOWN room, coordinates stay, just adding exits\n")
if lastMoveDirection == "west" then
setExit(id, roomID, 4);
setExit(roomID, id, 5);
end--if
if lastMoveDirection == "east" then
setExit(roomID, id, 5);
setExit(id, roomID, 4);
end--if
if lastMoveDirection == "south" then
setExit(roomID, id, 6);
setExit(id, roomID, 1);
end--if
if lastMoveDirection == "north" then
setExit(roomID, id, 1);
setExit(id, roomID, 6);
end--if
if lastMoveDirection == "up" then
setExit(roomID, id, 9);
setExit(id, roomID, 10);
end--if
if lastMoveDirection == "down" then
setExit(roomID, id, 10);
setExit(id, roomID, 9);
end--if
__mapper_room_x,__mapper_room_y,__mapper_room_z = getRoomCoordinates(id)
end--if isNewRoom
roomID = id;
__SetTerrainColor()--set the sector color
__roomCollision()--check for rooms in same coordinates
if __debug__ then
cecho("<yellow>DIR:"..lastMoveDirection.." new POS("..__mapper_room_x.."/"..__mapper_room_y.."/"..__mapper_room_z..")\n")
end--if
end--function
I put comments in the script where I thought they were needed. The other two functions are called at the end, you don't need them to get started just omit the lines
__SetTerrainColor()--set the sector color
__roomCollision()--check for rooms in same coordinates
to start, but you will want them after about 30 minutes playing with the map though.
One thing to note is the script makes two exits, one each direction of travel, this will cause problems with one way doors, but this is just meant to start someone off who can't get the thing to work at all (i.e. me).
-- set colors
function __SetTerrainColor()
local terrain = gmcp.room.info.terrain
local roomID = tonumber(gmcp.room.info.num)
cecho("<green>Terrain:"..terrain.."\n")
centerview(roomID)
-- the ID here must be >16 I started at 100 keeping out of trouble
if terrain == "Inside" then setRoomEnv( roomID, 100 ) ; setCustomEnvColor(100, 153, 0, 153, 255) --(ID, purple, transparancy)
elseif terrain == "City" then setRoomEnv( roomID, 110 ) ; setCustomEnvColor(110, 153, 76, 0, 255) --burnt orange
elseif terrain == "Forest" then setRoomEnv( roomID, 120 ) ; setCustomEnvColor(120, 0, 51, 0, 255) --dark green
elseif terrain == "Field" then setRoomEnv( roomID, 130 ) ; setCustomEnvColor(130, 0, 153, 0, 255) --green
elseif terrain == "ocean" then setRoomEnv( roomID, 140 ) ; setCustomEnvColor(140, 0, 0, 102, 255) --dark blue
elseif terrain == "Water (No Swim)" then setRoomEnv( roomID, 150 ) ; setCustomEnvColor(150, 102, 178, 255, 255) --light blue
elseif terrain == "Water (Swim)" then setRoomEnv( roomID, 160 ) ; setCustomEnvColor(160, 0, 102, 204, 255) --pale blue
else cecho("<orange> Need new color for terrain "..terrain)
end--if Terrain
end--function
only thing for the colours is keep your index above 16, 100 in my case, I spent ages wondering why green was maroon when the rest worked.
function __roomCollision()
local roomID = tonumber(gmcp.room.info.num)
local areaID = getRoomArea(roomID)
local x,y,z = getRoomCoordinates(roomID)
local i, v
local table = {}
local countelements = 0
table = getRoomsByPosition(areaID,x,y,z)
display(table)
for i,v in pairs(table) do
countelements = countelements + 1
end--for
echo ("count "..countelements)
if countelements > 1 then
for i,v in pairs(table) do
highlightRoom(v, 255,255,255,255,255,255,1,255,255)
echo("v "..v)
end--for
end--if
end--function
Lastly the collisions, it looks clumsy but it was the only way I could find to check if a table has more than 1 room in it.
So here is what it all looks like after a we while playing.
I added the letter L to a couple of rooms using right click add letter. L for locked, I need to go back there...
- map.PNG (30.15 KiB) Viewed 12004 times
Its very simple and probably in itself limited but when faced with a blank screen it might help.