Simple, Basic Mapping Script Thread

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Mapping

Post by Heiko »

Are you trying to make a mapper script for the MUD Aardwolf?

Silvine
Posts: 142
Joined: Sat Oct 23, 2010 2:36 pm

Re: Mapping

Post by Silvine »

No, its just looked the easiest script to start with.

This is the GMCP i get regarding a room.
Code: [show] | [select all] lua
 'room': table {
    'info': table {
      'num': 3005
      'name': 'The Temple Fountain'
      'zone': 'Northern Garathorm Main City'
      'terrain': 'City'
      'exits': table {
        'e': 3063
        'w': 3004
        's': 3006
        'n': 3001
      }
    }
Last edited by Silvine on Mon Dec 17, 2012 8:16 pm, edited 1 time in total.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Mapping

Post by Heiko »

Well, which mud do you want to map?

Silvine
Posts: 142
Joined: Sat Oct 23, 2010 2:36 pm

Re: Mapping

Post by Silvine »

Bedlam

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Mapping

Post by Heiko »

Ok let's see what it's like then ...

Silvine
Posts: 142
Joined: Sat Oct 23, 2010 2:36 pm

Re: Mapping

Post by Silvine »

Did something change with test5 that affected the way mini consoles display? I've lost a couple from my build, that reappear if I resize them.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Mapping

Post by Vadi »

That's not related to mapping at all. See the end of http://forums.mudlet.org/viewtopic.php?f=5&t=1874 though.

Silvine
Posts: 142
Joined: Sat Oct 23, 2010 2:36 pm

Re: Mapping-Starter Script GMCP

Post by Silvine »

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
folder.PNG (5.55 KiB) Viewed 11561 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.
Code: [show] | [select all] lua
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
lua.PNG (11.92 KiB) Viewed 11561 times
the helper function is
Code: [show] | [select all] lua
--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
Code: [show] | [select all] lua
--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
keys.PNG (13.66 KiB) Viewed 11561 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
gmcp.PNG (9.55 KiB) Viewed 11561 times
And the script fires like this
roomevent.PNG
roomevent.PNG (10.78 KiB) Viewed 11561 times
Code: [show] | [select all] lua
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).
Code: [show] | [select all] lua
-- 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.
Code: [show] | [select all] lua
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
map.PNG (30.15 KiB) Viewed 11561 times
Its very simple and probably in itself limited but when faced with a blank screen it might help.

Silvine
Posts: 142
Joined: Sat Oct 23, 2010 2:36 pm

Re: Mapping

Post by Silvine »

I was wondering what is the best way to make the exits on rooms that run in loops, return to each other etc. Below is a small example of a few rooms that loop back to each other.
loops.PNG
loops.PNG (3.14 KiB) Viewed 11551 times
When I map by hand if its more complicated than this I would draw an arrow out of the exit and put a letter on it. Then on the room I would mark it with the letter. If it returns to the same room I draw a return arrow.
loop2.PNG
loop2.PNG (6.14 KiB) Viewed 11551 times
Its hard to write with a touchpad :)
I'm not sure whats the best approach here. Do I just leave them linked up as the mapper shows it? I can still see where I am so its still easy to navigate but it doesn't look pleasing to my eye, any suggestions how to cope with this?
I assume this is where the custom exit lines come in. I don't see anything about them in the API. Is there a flag for them that I can test for, so they are not over written by a script?

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Mapping

Post by Vadi »

You can use custom exit lines to draw your arrows right on the map, actually!

Select a room, right-click and pick a line color. Click on the exit you'd like to draw the line from. Left-click on the map to draw points - and right-click to stop drawing.

Post Reply