[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Mapper help

Mapper help

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Shady Stranger   USA  (45 posts)  [Biography] bio
Date Sun 10 Jan 2016 02:00 AM (UTC)

Amended on Sun 10 Jan 2016 02:09 AM (UTC) by Shady Stranger

Message
I am using a modified version of A Simple Mapper and it only maps when a command is sent to move. Is it possible to also have it map based off another type of movement where a command is not entered? Specifically, when following in a group.

An example of what I want it to trigger on: You follow Bart southwest.

Secondly, I tried adding the skill sneaking to valid commands but I ended up with errors.


valid_direction = {
  n = "n",
  s = "s",
  e = "e",
  w = "w",
  u = "u",
  d = "d",
  ne = "ne",
  sw = "sw",
  nw = "nw",
  se = "se",
  north = "n",
  south = "s",
  east = "e",
  west = "w",
  up = "u",
  down = "d",
  northeast = "ne",
  northwest = "nw",
  southeast = "se",
  southwest = "sw",
  ['in'] = "in",
  out = "out",
--  sneak n = "sneak n",
--  sneak s = "sneak s",
--  sneak e = "sneak e",
--  sneak w = "sneak w",
--  sneak up = "sneak up",
--  sneak down = "sneak down",
--  sneak ne = "sneak ne",
--  sneak sw = "sneak sw",
--  sneak nw = "sneak nw",
--  sneak se = "sneak se",
  }  -- end of valid_direction



Compile error
Plugin: Shattered_Isles_Mapper (called from world: Shattered Isles)
Immediate execution
[string "Plugin"]:72: '}' expected (to close '{' at line 49) near 'n'
Error context in script:
  68 :   southeast = "se",
  69 :   southwest = "sw",
  70 :   ['in'] = "in",
  71 :   out = "out",
  72*:   sneak n = "sneak n",
  73 :   sneak s = "sneak s",
  74 :   sneak e = "sneak e",
  75 :   sneak w = "sneak w",
  76 :   sneak up = "sneak up",
[WARNING] C:\Program Files (x86)\MUSHclient\worlds\plugins\mapper.xml
Line   81: Error parsing script (Cannot load)


Maybe it has something to do with the spaces?

Thank you.
Edit: fixed code boxes and put in error message.
[Go to top] top

Posted by Nick Gammon   Australia  (22,988 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 10 Jan 2016 06:35 AM (UTC)
Message
For two words, you need to quote them and put them in brackets, like "in" in your example.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shady Stranger   USA  (45 posts)  [Biography] bio
Date Reply #2 on Sun 10 Jan 2016 07:26 AM (UTC)
Message
Nick Gammon said:

For two words, you need to quote them and put them in brackets, like "in" in your example.


This stopped me from getting the error but it still doesn't draw the map even though I get the response that it mapped the room. I am just going to post the whole plugin because I can't seem to figure out why it doesn't work. I also added the third trigger to attempt to map when I'm following but that doesn't work either. I get a "No matches." message each time I follow someone into a room.
[Go to top] top

Posted by Shady Stranger   USA  (45 posts)  [Biography] bio
Date Reply #3 on Sun 10 Jan 2016 07:28 AM (UTC)
Message

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Shattered_Isles_Mapper"
   author="Teef"
   id="8b5490301cec2d16454f2234"
   language="Lua"
   purpose="Simple Mapper for Shattered Isles"
   save_state="y"
   date_written="2010-08-30"
   requires="4.51"
   version="1.1"
   >
<![CDATA[
Install this plugin to show a map.

This creates a map that can be dragged around by the name using the Mapper plugin included in MUSHclient 4.51 and up

Zoom in with scroll wheel.
Adjust colors and size with configure button in corner
Hover cursor over square to get room name.
Click on square to speedwalk to it. 

The map uses room names, room descriptions, and exits to draw.
You have to teach the mapper by going back and forth since it doesn't assume that all directions are two-way.


Modified by Teef
Based on Simple Mapper by Nick Gammon

]]>
</plugin>


<!--  Triggers  -->

<triggers>
   <trigger
   enabled="y"
   group="mappertest"
   lines_to_match="4"
   keep_evaluating="y"
   match="^[(?!Delay)(.+?).]nn(.*n(S.*n)*)Z"
   multi_line="y"
   name="Name_Desc"
   regexp="y"
   script="Name_Desc"
   sequence="100"
  >
  </trigger>

  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^Obvious Exits: .*"
   name="Name_Or_Exits"
   regexp="y"
   script="Name_Or_Exits"
   sequence="100"
  >
  </trigger>

  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^You follow (.*?)$"
   regexp="y"
   script="map_find"
   sequence="100"
  >
  </trigger>
</triggers>

<aliases>
<alias
   match="^mapper find ([w* %d/&quot;]+)$"
   enabled="y"
   sequence="100"
   script="map_find"
   regexp="y"
  >
  
  </alias>  
  </aliases>
  

[Go to top] top

Posted by Shady Stranger   USA  (45 posts)  [Biography] bio
Date Reply #4 on Sun 10 Jan 2016 07:29 AM (UTC)
Message

<!--  Script  -->


<script>
<![CDATA[

local MAX_NAME_LENGTH = 60
local MUD_NAME = "Shattered Isles"

require "mapper"
require "serialize"
require "copytable"
require "commas"
  
default_config = {
  -- assorted colours
  BACKGROUND_COLOUR       = { name = "Background",        colour =  ColourNameToRGB "lightseagreen", },
  ROOM_COLOUR             = { name = "Room",              colour =  ColourNameToRGB "cyan", },
  EXIT_COLOUR             = { name = "Exit",              colour =  ColourNameToRGB "darkgreen", },
  EXIT_COLOUR_UP_DOWN     = { name = "Exit up/down",      colour =  ColourNameToRGB "darkmagenta", },
  EXIT_COLOUR_IN_OUT      = { name = "Exit in/out",       colour =  ColourNameToRGB "#3775E8", },
  OUR_ROOM_COLOUR         = { name = "Our room",          colour =  ColourNameToRGB "black", },
  UNKNOWN_ROOM_COLOUR     = { name = "Unknown room",      colour =  ColourNameToRGB "#00CACA", },
  DIFFERENT_AREA_COLOUR   = { name = "Another area",      colour =  ColourNameToRGB "#009393", },
  MAPPER_NOTE_COLOUR      = { name = "Messages",          colour =  ColourNameToRGB "lightgreen" },
  
  ROOM_NAME_TEXT          = { name = "Room name text",    colour = ColourNameToRGB "#BEF3F1", },
  ROOM_NAME_FILL          = { name = "Room name fill",    colour = ColourNameToRGB "#105653", },
  ROOM_NAME_BORDER        = { name = "Room name box",     colour = ColourNameToRGB "black", },
  
  AREA_NAME_TEXT          = { name = "Area name text",    colour = ColourNameToRGB "#BEF3F1",},
  AREA_NAME_FILL          = { name = "Area name fill",    colour = ColourNameToRGB "#105653", },   
  AREA_NAME_BORDER        = { name = "Area name box",     colour = ColourNameToRGB "black", },
               
  FONT = { name =  get_preferred_font {"Dina",  "Lucida Console",  "Fixedsys", "Courier", "Sylfaen",} ,
           size = 8
         } ,
         
  -- size of map window
  WINDOW = { width = 400, height = 400 },
  
  -- how far from where we are standing to draw (rooms)
  SCAN = { depth = 30 },
  
  -- speedwalk delay
  DELAY = { time = 0.3 },
  
  -- how many seconds to show "recent visit" lines (default 3 minutes)
  LAST_VISIT_TIME = { time = 60 * 3 },  
  
  }
  
rooms = {}

[Go to top] top

Posted by Shady Stranger   USA  (45 posts)  [Biography] bio
Date Reply #5 on Sun 10 Jan 2016 07:30 AM (UTC)
Message

valid_direction = {
  n = "n",
  s = "s",
  e = "e",
  w = "w",
  u = "u",
  d = "d",
  ne = "ne",
  sw = "sw",
  nw = "nw",
  se = "se",
  north = "n",
  south = "s",
  east = "e",
  west = "w",
  up = "u",
  down = "d",
  northeast = "ne",
  northwest = "nw",
  southeast = "se",
  southwest = "sw",
  ['in'] = "in",
  out = "out",
  ['sneak n'] = "sneak n",
  ['sneak s'] = "sneak s",
  ['sneak e'] = "sneak e",
  ['sneak w'] = "sneak w",
  ['sneak up'] = "sneak up",
  ['sneak down'] = "sneak down",
  ['sneak ne'] = "sneak ne",
  ['sneak sw'] = "sneak sw",
  ['sneak nw'] = "sneak nw",
  ['sneak se'] = "sneak se",
  }  -- end of valid_direction
  
-- -----------------------------------------------------------------
-- We have a room name and room exits
-- -----------------------------------------------------------------

function process_exits (exits_str)-- changed from process_room_desc
 -- local roomname = trim (wildcards.roomname)
 -- local exits_str = trim (wildcards.exits)
 -- local roomdesc = trim (wildcards.roomdesc)

  -- ColourNote ("white", "blue", "exits: " .. exits_str)  -- debug
  
  -- generate a "room ID" by hashing the room description and exits
  uid = utils.tohex (utils.md5 (roomname .. roomdesc .. exits_str))
  uid = uid:sub (1, 25)  

  -- break up exits into individual directions
  exits = {}
  
  for exit in string.gmatch (exits_str, "%w+") do
    local ex = valid_direction [exit]
    if ex then
      exits [ex] = "0"  -- don't know where it goes yet
    end -- if
  end -- for
  
  local name = roomname
  
  if #name > MAX_NAME_LENGTH then
    name = name:sub (1, MAX_NAME_LENGTH - 3) .. "..."
  end -- if too long
  
  -- add to table if not known
  if not rooms [uid] then
    ColourNote ("cyan", "", "Mapper adding room " .. uid:sub (1, 8) .. ", name: " .. name)
    rooms [uid] = { name = name, desc = roomdesc, exits = exits, area = MUD_NAME }
  end -- if

  -- save so we know current room later on  
  current_room = uid
  
  -- call mapper to draw this rom
  mapper.draw (uid)

  -- try to work out where previous room's exit led  
  if expected_exit == "0" and from_room then
    fix_up_exit ()
  end -- exit was wrong
    
end -- Name_Or_Exits


function Name_Or_Exits (name, line, wildcards)

  exits = string.match (line, "^Obvious Exits: (.*)")
  
  if exits then
    process_exits (exits)
  end -- if

  --roomname = line
  --roomdesc = nil
  
end -- Name_Or_Exits

function Name_Desc (name, line, wildcards) -- Teef roomname and roomdesc grab
  roomname = wildcards[1]
  roomitems = wildcards[2]
  roomdesc = string.gsub (roomitems , "  You notice .+$", "n")
  
  --roomdesc = (roomdesc or "" ) .. line .. "n"--Teef
end -- Name_Desc

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

function get_room (uid)
  
  if not rooms [uid] then 
   return nil
  end -- if
 
  local room = copytable.deep (rooms [uid])
 
  local texits = {}
  for dir in pairs (room.exits) do
    table.insert (texits, dir)
  end -- for
  table.sort (texits)
  
  room.hovermessage = string.format (
       "%stExits: %snRoom: %s",
        room.name or "unknown", 
        table.concat (texits, ", "),
      uid
      )
      
  if uid == current_room then
    room.bordercolour = config.OUR_ROOM_COLOUR.colour
    room.borderpenwidth = 2
  end -- not in this area
      
  return room
  
end -- get_room
[Go to top] top

Posted by Shady Stranger   USA  (45 posts)  [Biography] bio
Date Reply #6 on Sun 10 Jan 2016 07:31 AM (UTC)
Message


-- -----------------------------------------------------------------
-- We have changed rooms - work out where the previous room led to 
-- -----------------------------------------------------------------

function fix_up_exit ()

  -- where we were before
  local room = rooms [from_room]
  
  -- leads to here
  room.exits [last_direction_moved] = current_room
    
  -- clear for next time
  last_direction_moved = nil
  from_room = nil
  
end -- fix_up_exit

-- -----------------------------------------------------------------
-- try to detect when we send a movement command
-- -----------------------------------------------------------------

function OnPluginSent (sText)
  if valid_direction [sText] then
    last_direction_moved = valid_direction [sText]
    -- print ("Just moved", last_direction_moved)
    if current_room and rooms [current_room] then
      expected_exit = rooms [current_room].exits [last_direction_moved]
      if expected_exit then
        from_room = current_room
      end -- if
    -- print ("expected exit for this direction is to room", expected_exit)
    end -- if
  end -- if 
end -- function

-- -----------------------------------------------------------------
-- Plugin Install
-- -----------------------------------------------------------------

function OnPluginInstall ()
  
  config = {}  -- in case not found

  -- get saved configuration
  assert (loadstring (GetVariable ("config") or "")) ()

  -- allow for additions to config
  for k, v in pairs (default_config) do
    config [k] = config [k] or v
  end -- for
    
  -- and rooms
  assert (loadstring (GetVariable ("rooms") or "")) ()
  
  -- initialize mapper
  
  mapper.init { config = config, get_room = get_room  } 
  mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))

end -- OnPluginInstall

-- -----------------------------------------------------------------
-- Plugin Save State
-- -----------------------------------------------------------------

function OnPluginSaveState ()
  mapper.save_state ()
  SetVariable ("config", "config = " .. serialize.save_simple (config))
  SetVariable ("rooms", "rooms = " .. serialize.save_simple (rooms))
end -- OnPluginSaveState

-- -----------------------------------------------------------------
-- Plugin just connected to world
-- -----------------------------------------------------------------

function OnPluginConnect ()
  from_room = nil
  last_direction_moved = nil
end -- OnPluginConnect
  
-- -----------------------------------------------------------------
-- Find a room
-- -----------------------------------------------------------------

function map_find (name, line, wildcards)
 
  local room_ids = {}
  local count = 0
  local wanted = (wildcards [1]):lower ()

  -- scan all rooms looking for a simple match  
  for k, v in pairs (rooms) do
     local desc = v.desc:lower ()
     if string.find (desc, wanted, 1, true) then
       room_ids [k] = true
       count = count + 1
     end -- if
  end   -- finding room
  
  -- see if nearby
  mapper.find (
    function (uid) 
      local room = room_ids [uid] 
      if room then
        room_ids [uid] = nil
      end -- if
      return room, next (room_ids) == nil
    end,  -- function
    show_vnums,  -- show vnum?
    count,      -- how many to expect
    false       -- don't auto-walk
    )
  
end -- map_find


]]>
</script>


</muclient>
[Go to top] top

Posted by Nick Gammon   Australia  (22,988 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Mon 11 Jan 2016 08:40 AM (UTC)
Message
Try uncommenting the debugging line here:


function OnPluginSent (sText)
  if valid_direction [sText] then
    last_direction_moved = valid_direction [sText]
    print ("Just moved", last_direction_moved)  -- <---- this one
    if current_room and rooms [current_room] then
      expected_exit = rooms [current_room].exits [last_direction_moved]
      if expected_exit then
        from_room = current_room
      end -- if
    -- print ("expected exit for this direction is to room", expected_exit)
    end -- if
  end -- if 
end -- function

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shady Stranger   USA  (45 posts)  [Biography] bio
Date Reply #8 on Tue 12 Jan 2016 12:09 AM (UTC)

Amended on Tue 12 Jan 2016 12:42 AM (UTC) by Shady Stranger

Message
I think I know what the problem is. When I sneak into a new room, I get a message on whether or not it was a successful sneak attempt. On a normal move, there is no message.

You quietly sneak east. -- Success
You clumsily sneak east. -- Fail

I believe the plugin is looking for the room name and description first so when it gets this message, it still finds the room and adds it but does not map it unless I move normally. I tried changing the lines to match in the initial trigger to 5 but that doesn't work either, which still goes with my theory that receiving the extra line of text after the move is messing with the mapper.

Here's another attempt but it ends up messing with the mapper and still doesn't map.


<triggers>
   <trigger
   enabled="y"
   group="mappertest"
   lines_to_match="4"
   keep_evaluating="y"
   match="^($!You quietly sneak)(.*?)\.$|($!You clumsily sneak)(.*?)\.$|[(?!Delay)(.+?)\.]\n\n(.*\n(\S.*\n)*)\Z"
   multi_line="y"
   name="Name_Desc"
   regexp="y"
   script="Name_Desc"
   sequence="100"
  >
  </trigger>


This is what the game output looks like when I sneak into a room...


You quietly sneak west.

[Side Street, Tavern.]

The ground in front of the entrance is littered with broken glass, shredded cloth, and blood drippings.  Goblins rush past laughing and swinging into the tavern, while a few other ones use this area to treat their wounds.  Despite the putrid smell, many goblins buy and sell loot to one another, while others just mill about, conversing and gloating as they share stories.  Moving through the area requires some well-placed footsteps to avoid walking in muck.  You notice a broken pine cage, and a crooked swinging wooden half-door.

Also here: a disgruntled goblin, and a rowdy goblin patron 

Obvious Exits: west, and east. 
[Go to top] top

Posted by Nick Gammon   Australia  (22,988 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Tue 12 Jan 2016 02:20 AM (UTC)
Message

  ['sneak n'] = "sneak n",
  ['sneak s'] = "sneak s",
  ['sneak e'] = "sneak e",
  ['sneak w'] = "sneak w",
  ['sneak up'] = "sneak up",
  ['sneak down'] = "sneak down",
  ['sneak ne'] = "sneak ne",
  ['sneak sw'] = "sneak sw",
  ['sneak nw'] = "sneak nw",
  ['sneak se'] = "sneak se",


Maybe you just need the directions on the right without sneak in front of them. eg.


  ['sneak n'] = "n",
  ['sneak s'] = "s",
  ['sneak e'] = "e",
  ['sneak w'] = "w",
  ['sneak up'] = "up",
  ['sneak down'] = "down",
  ['sneak ne'] = "ne",
  ['sneak sw'] = "sw",
  ['sneak nw'] = "nw",
  ['sneak se'] = "se",


I think the purpose of that table is to convert what you type (eg. "north") into a single direction for use in the mapper. Thus "north", "n" and "sneak north" would all map to "n".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shady Stranger   USA  (45 posts)  [Biography] bio
Date Reply #10 on Tue 12 Jan 2016 02:28 AM (UTC)
Message
Nick Gammon said:


  ['sneak n'] = "sneak n",
  ['sneak s'] = "sneak s",
  ['sneak e'] = "sneak e",
  ['sneak w'] = "sneak w",
  ['sneak up'] = "sneak up",
  ['sneak down'] = "sneak down",
  ['sneak ne'] = "sneak ne",
  ['sneak sw'] = "sneak sw",
  ['sneak nw'] = "sneak nw",
  ['sneak se'] = "sneak se",


Maybe you just need the directions on the right without sneak in front of them. eg.


  ['sneak n'] = "n",
  ['sneak s'] = "s",
  ['sneak e'] = "e",
  ['sneak w'] = "w",
  ['sneak up'] = "up",
  ['sneak down'] = "down",
  ['sneak ne'] = "ne",
  ['sneak sw'] = "sw",
  ['sneak nw'] = "nw",
  ['sneak se'] = "se",


I think the purpose of that table is to convert what you type (eg. "north") into a single direction for use in the mapper. Thus "north", "n" and "sneak north" would all map to "n".


This fixed it. Thank you once again, Nick.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


18,836 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]