Basic Simple Mapping Script Thread

All and any discussion and development of the Mudlet Mapper.
Silvine
Posts: 142
Joined: Sat Oct 23, 2010 2:36 pm

Re: Mapping

Post by Silvine »

Lost me, please explain how.

User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Re: Mapping

Post by chris »

Here's an example:

make a script called colorEvent, give it the event handler colorEvent as well
Code: [show] | [select all] lua
addMapMenu("Color")
addMapEvent("Red", "colorEvent", "Color")
addMapEvent("Green", "colorEvent", "Color")
addMapEvent("Blue", "colorEvent", "Color")
setCustomEnvColor(1,255,0,0,255)
setCustomEnvColor(2,0,255,0,255)
setCustomEnvColor(3,0,0,255,255)
colorMap = {Red=1, Green=2, Blue=3}
function colorEvent(...)
	display(arg)
        local color = arg[2]    
        local env = colorMap[color]
        for i = 3,arg['n'] do
                setRoomEnv(arg[i],env)
        end
end
This will color rooms highlighted, you can do display(arg) in the code to get all the arguments provided, arguments 3..n are room ids

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

Re: Mapping

Post by Silvine »

Thanks,
that is extremely useful. I did this with it
Code: [show] | [select all] lua
function __IncreaseZ(...)
		local x,y,z 
--        display(arg)
        for i = 3,arg['n'] do
				x,y,z = getRoomCoordinates(arg[i])
--    			echo("\n id "..arg[i].." x "..x.." y "..y.." z "..z.." "..getRoomName(arg[i]))
              setRoomCoordinates(arg[i],x,y,(z+1))
        end--for
        centerview(arg[3])
end--function
and also
Code: [show] | [select all] lua
function __DecreaseZ(...)
		local x,y,z
--      display(arg)
        for i = 3,arg['n'] do
				x,y,z = getRoomCoordinates(arg[i])
--  			echo("\n id "..arg[i].." x "..x.." y "..y.." z "..z.." "..getRoomName(arg[i]))
              setRoomCoordinates(arg[i],x,y,(z-1))
        end--for
        centerview(arg[3])
end--function
I hate walking up/down steps and not knowing where I am on them, so I like to group them on the same z level and offset them. This works becase my mud is just n,s,w,e,u,d so the u,d go where ne,sw would be.

Its remarkable how much you can map with so little code, functions etc

Also later i did this for adding doors
Code: [show] | [select all] lua
addMapMenu("Closed","Doors","Closed")
addMapMenu("Locked","Doors","Locked")
addMapMenu("Remove","Doors","Remove")
addMapEvent("CNorth","__DoorAction","Closed","North")
addMapEvent("CSouth","__DoorAction","Closed","South")
addMapEvent("CWest","__DoorAction","Closed","West")
addMapEvent("CEast","__DoorAction","Closed","East")
addMapEvent("LNorth","__DoorAction","Locked","North")
addMapEvent("LSouth","__DoorAction","Locked","South")
addMapEvent("LWest","__DoorAction","Locked","West")
addMapEvent("LEast","__DoorAction","Locked","East")
addMapEvent("RNorth","__DoorAction","Remove","North")
addMapEvent("RSouth","__DoorAction","Remove","South")
addMapEvent("RWest","__DoorAction","Remove","West")
addMapEvent("REast","__DoorAction","Remove","East")
Code: [show] | [select all] lua
function __DoorAction(...)

local roomid = arg[3]
local door = arg[2]

local doorDirectionMap = (
{LNorth="n", LSouth="s", LWest="w", LEast="e", LUp="u", LDown="d", 
 CNorth="n", CSouth="s", CWest="w", CEast="e", CUp="u", CDown="d", 
 RNorth="n", RSouth="s", RWest="w", REast="e", RUp="u", RDown="d"}
)
local doorStatusMap = (
{LNorth=3, LSouth=3, LWest=3, LEast=3, LUp=3, LDown=3, 
 CNorth=2, CSouth=2, CWest=2, CEast=2, CUp=2, CDown=2, 
 RNorth=0, RSouth=0, RWest=0, REast=0, RUp=0, RDown=0}
)

local doorStatus = doorStatusMap[door]
local doorDirection = doorDirectionMap[door]

echo("\n Set Door id "..roomid.." exit "..doorDirection.." status "..doorStatus)
setDoor(roomid, doorDirection, doorStatus)
end--function
I have up / down in the function but not in the menu. I'm not sure if you can make up/down doors but either way its no big deal really to adjust it.
I was trying to find a away to pass an argument using the addMapEvent function as well as the arg table but couldn't get it to work. This is kinda clunky but it works just fine.
Last edited by Silvine on Sun Jan 13, 2013 1:19 am, edited 1 time in total.

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

Re: Mapping

Post by Silvine »

I've starting getting a couple of strange lines on my map, and ideas why? When I move around they disappear and my exits look ok. I tried deleting a room but the strange line tends to move to another room. It seems to happen on up/down rooms. Thanks
line.PNG
line.PNG (13.77 KiB) Viewed 10009 times

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

Re: Mapping

Post by Silvine »

I have a load of text labels on the map, but depending on the zoom, I can't read the labels. Is it possible to update them all somehow so that they won't scale with the zoom?
Some labels predate the showOnTop property, but they are all set to background for the one more recent ones.

below are the labels in zone 1
labelarea.PNG
labelarea.PNG (3.58 KiB) Viewed 9969 times
below are the properties of label 1 in zone 1
labelproperty.PNG
labelproperty.PNG (4.13 KiB) Viewed 9969 times
I saw this on the API
labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)

But don't know if I can alter my existing labels or do I have to make new ones?
I don't want to try and write code to iterate through all the labels and mess up the whole map, any suggestions please?

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

Re: Mapping

Post by Heiko »

Using screen space labels imho isn't a good idea, but you can use scalable map space labels with larger label png sizes to get better quality fonts when scaling. The higher the quality of the font, the more RAM is being used of course, so don't overdo it.
You don't have to be afraid of breaking anything because you can roll back your map to older save states.

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

Re: Mapping

Post by Silvine »

What would you recommend for labels? The labels are basically just pointers to zones or mobs so I have a frame of reference. I don't want or need anything fancy, functional works well for me.
I'm not sure I understand what you mean by screen space labels.

It turns out I've 212 labels and don't really want to create them all again
Code: [show] | [select all] lua
function labels()
areas = {}
arealabels = {}
labelvalues = {}
totallabel = 0
areas = getAreaTableSwap() 
if areas ~= nill then

	for i,v in pairs(areas) do
		cecho("Area "..i.." v "..v.."\n")
		echo("------------------------\n")
		arealabels = getMapLabels(i) 
		if arealabels ~= i then
			for j,w in pairs(arealabels) do
				totallabel = totallabel + 1
				labelvalues = getMapLabel(i,j)
				areaval = i
				areatext = v
				xval = labelvalues.X
				yval = labelvalues.Y
				zval = labelvalues.Z
				tval = labelvalues.Text
				hval = labelvalues.Height
				wval = labelvalues.Width
				cecho("x "..xval.." y "..yval.." z "..zval.." "..tval.." h "..hval.." ".." w "..wval.."\n")
			end --for
		end--if
	end --for
end --if
echo ("total "..totallabel)
end --function
Attachments
labels.PNG
labels.PNG (26.76 KiB) Viewed 9962 times

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

Re: Mapping

Post by Heiko »

You don't need to recreate them manually. Checkout the respective map label api and do this programatically.

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

Re: Mapping

Post by Silvine »

Ok its a bit confused looking but hey it works :)
makes every label size 10 font, cyan, and stays readable no matter how the map is zoomed. It neatened the whole thing up nicely.
Code: [show] | [select all] lua
function labels()
local areas = {}
local arealabels = {}
local labelvalues = {}
local totallabel = 0
local areas = getAreaTableSwap()
local arearooms = {}
	newlabels = {}
if areas ~= nill then

	for i,v in pairs(areas) do
		echo("------------------------\n")
		cecho("Area "..i.." v "..v.."\n")
		echo("------------------------\n")
		arealabels = getMapLabels(i) 
		if arealabels ~= i then
			for j,w in pairs(arealabels) do
				totallabel = totallabel + 1
				labelvalues = getMapLabel(i,j)
				areaval = i
				areatext = v
				xval = labelvalues.X
				yval = labelvalues.Y
				zval = labelvalues.Z
				tval = labelvalues.Text
--				hval = labelvalues.Height
--				wval = labelvalues.Width
				cecho("Area "..i.." x "..xval.." y "..yval.." z "..zval.." "..tval.."\n")
				cecho("<green>Add label "..i.."\n")
				
				table.insert(newlabels,{		["Label"] = totallabel,
											 	["areaID"] = i,
												["text"] = tval,
												["posx"] = xval,
												["posy"] = yval,
												["posz"] = zval })
				

				cecho("<red>Delete area"..i.." label "..j.."\n")
				deleteMapLabel(i, j) 
			end --for
		end--if
	arearooms = getAreaRooms(i)
	if arearooms[1] == nil then
	echo("##################################\n")
	echo("####### No rooms in Area "..i.." #####\n")
	echo("##################################\n")
	end--if
		
	end --for
end --if
echo ("total "..totallabel)

for  z = 1, #newlabels do
	nareaID = newlabels[z].areaID
	nposx = newlabels[z].posx
	nposy = newlabels[z].posy
	nposz = newlabels[z].posz
	ntext = newlabels[z].text
	createMapLabel(nareaID, ntext, nposx, nposy, nposz, 0, 255, 255, 0, 0, 0, 20, 10, false, true)
	cecho("<cyan>Made label ("..nareaID..","..ntext..","..nposx..","..nposy..","..nposz..",0, 255, 0, 0, 0, 20, 10, false, true)\n")

end--for
end --function
Attachments
labelsfixed.PNG
labelsfixed.PNG (39.92 KiB) Viewed 9943 times

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

Re: Mapping

Post by Silvine »

So, its time to try and make a small package, with the aliases, scripts, and keys. I can get those into an .xml but how do I add the map?
I tried to make a blank profile as suggested somewhere in the doc's but it won't let me without putting in a server address and port.

Thanks in advance.

Post Reply