A question about mapper.lua.

Posted by Lzkd on Wed 05 Nov 2014 10:08 AM — 30 posts, 94,326 views.

#0
Hello,

I'm from China.Please forgive my English is not good enough.I have some experience using MUSHclient.But I never use mapper.lua.

Can you give me a tutorial on how to use mapper.lua, or link.I want to get this information through MUSHclient.
Amended on Wed 05 Nov 2014 10:10 AM by Lzkd
#1
Hello,

I'm from China.Please forgive my English is not good enough.I have some experience using MUSHclient.But I never use mapper.lua.

Can you give me a tutorial on how to use mapper.lua, or link.I want to get this information through MUSHclient
Quote:

map = {
{ vnum = 1, name = "Entrance", exits = { south = 4, east = 2 } },
{ vnum = 2, name = "Kitchen", exits = { west = 1, east = 3, south = 5 } },
{ vnum = 3, name = "Garden", exits = { west = 2, south = 6 } },
{ vnum = 4, name = "Livingroom", exits = { north = 1, east = 5 } },
{ vnum = 5, name = "Bedroom", exits = { north = 2, west = 4 } },
{ vnum = 6, name = "Toilet", exits = { north = 3, west = 5 } },
{ vnum = 7, name = "Nowhere", exits = {} },
}



I just get this data will be enough.I can own the data in a text or SQLite.
Thank you very much for taking the time to read my post.
Amended on Wed 05 Nov 2014 10:14 AM by Lzkd
Australia Forum Administrator #2
Please read this:

Template:post=12635
Please see the forum thread: http://gammon.com.au/forum/?id=12635.
#3
Thank you for your attention.I'll go and read.
Thank you once again.
#4
Nick Gammon said:

Please read this:

(post=12635)


Hi,Nick

I think I understand this link.But I hope in my code, do not use plug-in.I try to modify the plugin, but failed.
Could you please give me a not plug-in examples or link.Thank you again.
Australia Forum Administrator #5
What went wrong? Post your code please. I don't have an example which is not in a plugin.
#6
Hi,Nick

Considering the different situation of each MUD.I chose to test this picture of the situation

http://gammon.com.au/images/mapper/mapper_show_simple_mud.png


I thought I could code for removing unwanted.The final results are as follows.

Quote:


-- mapper module
require "mapper"

-- configuration table
config = { }

rooms = {

[1] = {
name = "Town Square",
exits = { n = 2, s = 3, e = 4}
},

[2] = {
name = "The Inn",
exits = { s = 1 }
},

[3] = {
name = "Butcher",
exits = { n = 1 }
},

[4] = {
name = "Main Street",
exits = { w = 1, e = 5 }
},

[5] = {
name = "West Main Street",
exits = { w = 4 }
},

} -- example rooms table

-- -----------------------------------------------------------------
-- mapper 'get_room' callback - it wants to know about room uid
-- -----------------------------------------------------------------
function get_room (uid)

room = rooms [uid]
if not room then
return nil
end -- if not found

room.area = "The swamp" -- OK, let's assume every room is in this area
room.hovermessage = room.name

return room
end -- get_room

-- -----------------------------------------------------------------
-- Plugin Install
-- -----------------------------------------------------------------
function OnPluginInstall ()
-- initialize mapper
mapper.init {
config = config, -- ie. colours, sizes
get_room = get_room, -- info about room (uid)
show_help = OnHelp, -- to show help
}

mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
end -- OnPluginInstall

-- -----------------------------------------------------------------
-- Plugin Help
-- -----------------------------------------------------------------
function OnHelp ()
mapper.mapprint (string.format ("[MUSHclient mapper, version %0.1f]", mapper.VERSION))
mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
end

-- -----------------------------------------------------------------
-- test
-- -----------------------------------------------------------------
function test (name, line, wildcards)
mapper.draw (1) -- draw room 1
end -- test

Amended on Fri 07 Nov 2014 01:41 PM by Lzkd
#7
Then I run.

Quote:

/test()


The last error code.

Quote:


Run-time error
World: mapper-test
Immediate execution
D:\MUSHclient\lua\mapper.lua:215: attempt to call upvalue 'supplied_get_room' (a nil value)
stack traceback:
D:\MUSHclient\lua\mapper.lua:215: in function 'get_room'
D:\MUSHclient\lua\mapper.lua:933: in function 'draw'
[string "Script file"]:86: in function 'test'
[string "Command line"]:1: in main chunk


I don't know, what I missed code.I believe, just some local error.But I can't find this mistake.Thank you very much for your help.
Thank you again, you spend valuable time to read this post.
Amended on Fri 07 Nov 2014 02:06 PM by Lzkd
Australia Forum Administrator #8
You are testing outside a plugin, therefore OnPluginInstall was not called (this is called when a plugin is loaded).

Your code works if you do this:


/OnPluginInstall ()  -- load mapper (do this once)


Then:


/test ()  -- draw room 1
Australia Forum Administrator #9
You could remove this too if you want:


-- -----------------------------------------------------------------
-- Plugin Help
-- -----------------------------------------------------------------
function OnHelp ()
mapper.mapprint (string.format ("[MUSHclient mapper, version %0.1f]", mapper.VERSION))
mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
end


But if you do the mapper "help" button won't work. But that code wouldn't work anyway because GetPluginInfo is only relevant inside a plugin.
Amended on Fri 07 Nov 2014 07:59 PM by Nick Gammon
#10
Thank you very much for your help.I think I can continue to the back of the code.
Thank you again, you spend precious time to pay attention to my post.
Australia Forum Administrator #11
I think some of the miniwindow stuff will not work so well if you are not using a plugin. Also, if you make a plugin (as in my example thread above) then it is much, much easier to distribute it to your friends, rather than getting them to add scripts, triggers, etc. to their individual worlds.
#12
Nick Gammon said:

I think some of the miniwindow stuff will not work so well if you are not using a plugin. Also, if you make a plugin (as in my example thread above) then it is much, much easier to distribute it to your friends, rather than getting them to add scripts, triggers, etc. to their individual worlds.



Hi,Nick

Thank you for your guidance.I am in today's code work, also felt the question you said.The same code, plugins environment is very good, whereas the error.
I think we should listen to your advice, to give up the previous ideas, let mapper.lua run in the plug-in environment.This can avoid a lot of strange errors.

I'm in the process of reading mapper.lua, have a new problem.
Quote:

start_speedwalk (path) -- starts speedwalking. path is a table of directions/uids
build_speedwalk (path) -- builds a client speedwalk string from path
cancel_speedwalk () -- cancel current speedwalk, if any
check_we_can_find () -- returns true if doing a find is OK right now
find (f, show_uid, count, walk) -- generic room finder
find_paths (uid, f) -- lower-level room finder (for getting back a path)


I believe, these functions can be finished in the map, in the map of the one uid for other uid walking.But I can't let it run correctly.
Could you please give me a examples or link.Thank you again.
Thank you for the use of valuable time, read my post.
Amended on Sat 08 Nov 2014 09:16 AM by Lzkd
Australia Forum Administrator #13
There are examples of most of those in this plugin:

https://github.com/nickgammon/plugins/blob/master/Realm_Of_Magic_Mapper.xml

Quote:

But I can't let it run correctly.


If that doesn't help post what you are doing, and what happens.
#14
Nick Gammon said:

There are examples of most of those in this plugin:

https://github.com/nickgammon/plugins/blob/master/Realm_Of_Magic_Mapper.xml

Quote:

But I can't let it run correctly.


If that doesn't help post what you are doing, and what happens.


Hi,Nick
After learning this link. I tried to make the test.Got a strange results.
Now I say I want to get what.I went to a new world.So the need to draw a new map.I am not a programmer.But I love MUD and MUSHclient.
After the study, I made the following efforts.

I have completed most of the function map.Lack is, how to get the path from one room to another room.I can make the map data me like this.


  map = {
    { vnum = 1, name = "Entrance", exits = { south = 4, east = 2 } },
    { vnum = 2, name = "Kitchen", exits = { west = 1, east = 3, south = 5 } },
    { vnum = 3, name = "Garden", exits = { west = 2, south = 6 } },
    { vnum = 4, name = "Livingroom", exits = { north = 1, east = 5 } },
    { vnum = 5, name = "Bedroom", exits = { north = 2, west = 4 } },
    { vnum = 6, name = "Toilet", exits = { north = 3, west = 5 } },
    { vnum = 7, name = "Nowhere", exits = {} },
}


But paint a room, the room can not automatically return to the current_room.I hope to have a path.I made the attempt.



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="Example_Mapper"
   author="Nick Gammon"
   id="63e6909083318cf63707c044"
   language="Lua"
   purpose="Example mapper"
   save_state="y"
   date_written="2014-10-22"
   requires="4.61"
   version="1.0"
   >

<description trim="y">
<![CDATA[
AUTOMATIC MAPPER ...  by Nick Gammon

ACTIONS

mapper help         --> this help  (or click the "?" button on the bottom right)
]]>
</description>

</plugin>

<aliases>
  <alias
   match="mapper help"
   script="OnHelp"
   enabled="y"
  >
  </alias>

  <alias
   match="mapper test"
   script="test"
   enabled="y"
  >
  </alias>
---------################ Here is my own to add. ##############-----
  <alias
   match="find test"
   script="find_test"
   enabled="y"
  >
  </alias>

</aliases>
  
<!--  Script  -->

<script>
<![CDATA[
-- mapper module
require "mapper"
require "tprint"

-- configuration table
config = { }    

rooms = {

  [1] = {
        name = "Town Square",
        exits = { n = 2, s = 3, e = 4}
        },

  [2] = {
        name = "The Inn",
        exits = { s = 1 }
        },

  [3] = {
        name = "Butcher",
        exits = { n = 1  }
        },
                
  [4] = {
        name = "Main Street",
        exits = { w = 1, e = 5  }
        },

  [5] = {
        name = "West Main Street",
        exits = {  w = 4  }
        },
                
        }  -- example rooms table
        
-- -----------------------------------------------------------------
-- mapper 'get_room' callback - it wants to know about room uid
-- -----------------------------------------------------------------
function get_room (uid)
 
  room = rooms [uid]
  if not room then
    return nil
  end -- if not found
  
  room.area = "The swamp"  -- OK, let's assume every room is in this area
  room.hovermessage = room.name

  return room
end -- get_room

-- -----------------------------------------------------------------
-- Plugin Install
-- -----------------------------------------------------------------
function OnPluginInstall ()
  -- initialize mapper
  mapper.init { 
            config     = config,   -- ie. colours, sizes
            get_room   = get_room, -- info about room (uid)
            show_help  = OnHelp,   -- to show help
              }
               
  mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
end -- OnPluginInstall

-- -----------------------------------------------------------------
-- Plugin Help
-- -----------------------------------------------------------------
function OnHelp ()
  mapper.mapprint (string.format ("[MUSHclient mapper, version %0.1f]", mapper.VERSION))
  mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
end

-- -----------------------------------------------------------------
-- test
-- -----------------------------------------------------------------
function test (name, line, wildcards)
  mapper.draw (1)  -- draw room 1
end -- test

---------################ Here is my own to add. ##############-----
function find_test ()
myuid = 5
	a, b, c = mapper.find_paths(1, 
	           function (myuid)
             return uid == wanted,  -- wanted room?
                    uid == wanted   -- stop searching?
            end)
	print(a)
	print("b = "..b)
	print("c = "..c)
	tprint(a)
end

]]>
</script>
</muclient>

Amended on Sun 09 Nov 2014 06:39 AM by Nick Gammon
#15
But the final results.

Removed plugin Example_Mapper (63e6909083318cf63707c044)
MUSHclient mapper installed, version 2.5
Added plugin D:\MUSHclient\worlds\plugins\t_maper.xml
table: 022F4F58
b = 1
c = 1
4:
  "reason"=true
  "path":
    1:
      "uid"=4
      "dir"="e"


I just want to get the room 1 to room 5 path.But this is not what I want.
Please tell me, how can I do, to get what I want.
Thank you again to spend valuable time, read my post.
Amended on Sun 09 Nov 2014 04:14 AM by Lzkd
Australia Forum Administrator #16
Change the function to:


---------################ Here is my own to add. ##############-----
function find_test ()
current = 1   -- where we start
wanted = 5    -- where we want to go

	a, b, c = mapper.find_paths(current, 
	           function (uid)
             return uid == wanted,  -- wanted room?
                    uid == wanted   -- stop searching?
            end)
	print(a)
	print("b = "..b)
	print("c = "..c)
	tprint(a)
end


It searches until this is true:


 function (uid)
             return uid == wanted,  -- wanted room?
                    uid == wanted   -- stop searching?
            end)


That is the current uid is equal to the wanted uid.
Australia Forum Administrator #17
"stop searching" is for deciding if one match will do. For example, to find a room, a single match will stop the search.

For finding (say) shops, you might get many shops.
Australia Forum Administrator #18
Results of modified code:


b = 2
c = 2
5:
  "reason"=true
  "path":
    1:
      "dir"="e"
      "uid"=4
    2:
      "uid"=5
      "dir"="e"


It is two rooms to the east, taking a depth of 2 rooms search.
#19
Thank you very much, I think I get what I want.
Thanks again for your kind help.
The hope can quickly draw the map.Go!Go!!Go!!!
Australia Forum Administrator #20
Quote:

I'm from China.


I just want to point out that the mapper will handle Unicode text for room names and area names. For example:



The tricky part is the mouseover (tooltip) parts because the tooltips are hard (or impossible) to get Unicode text into.

To work around this I have amended the mapper to detect mouse-overs. See:

https://github.com/nickgammon/mushclient/commit/90c3ce9

Source for mapper.lua:

https://github.com/nickgammon/mushclient/blob/master/lua/mapper.lua


The amended code detects mouse-overs for the rooms, and builds its own tooltip using WindowPolygon and a transparent window which sits on top of the mapper window. This seems to work OK, have fun playing with it.

Plugin changed to display these tooltips:

Template:saveplugin=Example_Mapper
To save and install the Example_Mapper plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. Save to disk on your PC, preferably in your plugins directory, as Example_Mapper.xml
    • The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Example_Mapper.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. Save your world file, so that the plugin loads next time you open it.



<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="Example_Mapper"
   author="Nick Gammon"
   id="63e6909083318cf63707c044"
   language="Lua"
   purpose="Example mapper"
   save_state="y"
   date_written="2014-10-22"
   requires="4.61"
   version="1.0"
   >

<description trim="y">
<![CDATA[
AUTOMATIC MAPPER ...  by Nick Gammon

ACTIONS

mapper help         --> this help  (or click the "?" button on the bottom right)
]]>
</description>

</plugin>

<aliases>
  <alias
   match="mapper help"
   script="OnHelp"
   enabled="y"
  >
  </alias>

  <alias
   match="mapper test"
   script="test"
   enabled="y"
  >
  </alias>

</aliases>
  
<!--  Script  -->

<script>
<![CDATA[

-- mapper module
require "mapper"

-- configuration table
config = { }    

rooms = {

  [1] = {
        name = "沼泽",
        exits = { n = 2, s = 3, e = 4}
        },

  [2] = {
        name = "酒馆",
        exits = { s = 1 }
        },

  [3] = {
        name = "屠夫",
        exits = { n = 1  }
        },
                
  [4] = {
        name = "屠夫",
        exits = { w = 1, e = 5  }
        },

  [5] = {
        name = "西大街",
        exits = {  w = 4  }
        },
                
        }  -- example rooms table
       
-- -----------------------------------------------------------------
-- mapper 'mouseover' callback - draw a tooltip
-- -----------------------------------------------------------------
         
function mouseover_room (uid, flags)
  local room = rooms [tonumber (uid)]
  if not room then
    return
  end -- room not found
  
  local hotspot_left = WindowHotspotInfo (mapper.win, uid, 1)
  local hotspot_top = WindowHotspotInfo (mapper.win, uid, 2)
  local main_left = WindowInfo (mapper.win, 10)
  local main_top = WindowInfo (mapper.win, 11)
  
  if not hotspot_left or not hotspot_top then
    return
  end -- hotspot not found
  
  local message = "*信息*\n" .. room.name
  
  mw.tooltip (win_tooltip,        -- window name to use
              font_tooltip,       -- font to use for each line
              bold_font_tooltip,  -- font to use for bold lines
              message,        -- tooltip text
              hotspot_left + main_left + 2, hotspot_top + main_top + 3,      -- where to put it
              0,  -- colour for text   (black)
              0,  -- colour for border (black)
              tooltip_background_colour) -- colour for background

end -- mouseover_room

function cancelmouseover_room (uid, flags)
  WindowShow (win_tooltip, false)
end -- cancelmouseover_room
        
-- -----------------------------------------------------------------
-- mapper 'get_room' callback - it wants to know about room uid
-- -----------------------------------------------------------------
function get_room (uid)
 
  room = rooms [uid]
  if not room then
    return nil
  end -- if not found
  
  room.area = "悲伤之地"  -- OK, let's assume every room is in this area
  room.hovermessage = ""

  return room
end -- get_room

-- -----------------------------------------------------------------
-- Plugin Install
-- -----------------------------------------------------------------
function OnPluginInstall ()
  -- initialize mapper
  mapper.init { 
            config     = config,   -- ie. colours, sizes
            get_room   = get_room, -- info about room (uid)
            show_help  = OnHelp,   -- to show help
            room_mouseover = mouseover_room,
            room_cancelmouseover = cancelmouseover_room,
              }
               
  mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
  
    -- get ready for tooltips
  win_tooltip = GetPluginID () .. "_tooltip"
  font_tooltip = "tf"
  bold_font_tooltip = "tfb"
  WindowCreate (win_tooltip, 0, 0, 0, 0, 0, 0, 0)
  WindowFont (win_tooltip, font_tooltip, "SimSun", 12)
  WindowFont (win_tooltip, bold_font_tooltip, "SimSun", 12, true)
  tooltip_background_colour =  ColourNameToRGB ("#FFFFE1")

end -- OnPluginInstall

-- -----------------------------------------------------------------
-- Plugin Help
-- -----------------------------------------------------------------
function OnHelp ()
  mapper.mapprint (string.format ("[MUSHclient mapper, version %0.1f]", mapper.VERSION))
  mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
end

-- -----------------------------------------------------------------
-- test
-- -----------------------------------------------------------------
function test (name, line, wildcards)
  mapper.draw (1)  -- draw room 1
end -- test

]]>
</script>
</muclient>


[EDIT] Moved tooltip stuff into mw.lua. Latest version:

https://github.com/nickgammon/mushclient/blob/master/lua/mw.lua

Improved drawing of text boxes (eg. area name, room name) so that text isn't jammed up against the edge. See gauge.lua:

https://github.com/nickgammon/mushclient/blob/master/lua/gauge.lua

Improved screenshot:

Amended on Wed 12 Nov 2014 03:27 AM by Nick Gammon
#21
Hi,Nick

It's amazing to me!!!
This looks really interesting.I must have a good research.
Thank you again for your guidance.
Australia Forum Administrator #22
I made a few more changes to mw.lua.

Now the tooltip has rounded corners, and you can put lines in bold, like this:



The plugin above has been amended slightly to allow you to supply a bold font to the tooltip function.
Amended on Wed 12 Nov 2014 03:24 AM by Nick Gammon
#23
Nick Gammon said:


The plugin above has been amended slightly to allow you to supply a bold font to the tooltip function.


Wa!!!!

This is too strong.This can be turned into a very beautiful.
I love MUSHclient.I love Nick.
#24
Hi,Nick

I did some tests.Has been unable to solve the problem.
I updated it several files.mapper.lua,mw.lua,gauge.lua
Then loading plug-ins.Finally get the same result.
------
Sorry, I don't know how the pictures.Please click this link.
http://i.imgur.com/gKypHAh.jpg
------
I have been looking for, where it is wrong.Finally, I noted.

<?xml version="1.0" encoding="utf-8"?>


I think, may be the cause of UTF-8.I will save the plugin, into utf-8.Then the success of the show.
-------
Please click this link.
http://i.imgur.com/le2Xrcd.jpg
-------
But, in my world.I can't get utf-8.Just to get GBK(GB2312).Excuse me, this method can be solved?
Thank you again for your help, and attention to this post.
Amended on Sat 15 Nov 2014 02:29 AM by Lzkd
Australia Forum Administrator #25
Can't you use Notepad and use UTF-8?

I don't know of any easy way of converting from GB2312 to UTF-8.

You could try:

http://www.gammon.com.au/scripts/doc.php?lua=utils.utf8convert
Australia Forum Administrator #26
Also see iconv
#27
Nick Gammon said:

Can't you use Notepad and use UTF-8?

I don't know of any easy way of converting from GB2312 to UTF-8.

You could try:

http://www.gammon.com.au/scripts/doc.php?lua=utils.utf8convert


Hi,Nick
Thank you for your guidance.I think I completed the expected effect.However, instead of using utils.utf8convert() to complete.I search to a DLL file, it can be completed GB2312 to utf-8.

Thank you again for your concern and help.
Amended on Sat 15 Nov 2014 08:50 AM by Lzkd
#28
Nick Gammon said:

Can't you use Notepad and use UTF-8?



Hi,Nick

Yesterday forgot to explain.I can make my notepad use utf-8.But in my world, the string can be, are gb2312.
Australia Forum Administrator #29
I don't understand that, and I'm not sure of how to answer it.