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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Miniwindows
. . -> [Subject]  Map redirection

Map redirection

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


Posted by Nate7240   (16 posts)  [Biography] bio
Date Sun 14 Mar 2010 04:32 PM (UTC)
Message
Alright so after following Nick's completely awesome inventory mini window (your the man :P), I've finally managed to come up with a script that actually captures the map from my output, and redirects it into a mini window. Now of course, there is always one more problem. Before I go any further, here is my script.



require "wait"

function MapView_Redirect ()
wait.make (function () -- coroutine starts here

local win = GetPluginID () .. ":map"
local font = "f"

if not WindowInfo (win, 1) then
  WindowCreate (win, 0, 0, 0, 0, 6, 0, 0)
  WindowFont (win, font, "Lucida Console", 9)  
end -- if


-- request map


Send "look"


-- wait for map to start

local x = wait.match ("-*- v* -*-")

if not x then
  ColourNote ("white", "blue", "No map received within 5 seconds")
  return
end -- if


local map = {}
local max_width = WindowTextWidth (win, font, "Map")

-- loop untill end of map

while true do
   local line, wildcards, styles = wait.match ("*")

   -- save map
   table.insert (map, styles)
   -- work out max width
   max_width = math.max (max_width, WindowTextWidth (win, font, line))

   -- see if end of map
   if string.match (line, "^-*- %d+:%d+:%d+ -*-") or
   string.match (line, "^-* %-%d+:%d+:%d+ -*-") or
   string.match (line, "^-* %d+:%-%d+:%d+ -*-") or
   string.match (line, "^-* %d+:%d+:%-%d+ -*-") or
   string.match (line, "^-* %-%d+:%-%d+:%d+ -*-") or
   string.match (line, "^-* %d+:%-%d+:%-%d+ -*-") or
   string.match (line, "^-* %-%d+:%d+:%-%d+ -*-") or
   string.match (line, "^-* %-%d+:%-%d+:%-%d+ -*-") then
   break
   end -- if

end -- while


local font_height = WindowFontInfo (win, font, 1)

local window_width = max_width + 10
local window_height = font_height * (#map + 2) +10

-- make window correct size
WindowCreate (win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB "#373737")
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- heading line

WindowText (win, font, "Map:", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each map line

local y = font_height * 2 + 5

for i, styles in ipairs (map) do

  local x = 5
  for _, style in ipairs (styles) do
    x = x + WindowText (win, font, style.text, x, y, 0, 0, style.textcolour)
  end -- for
  y = y + font_height

end -- for each inventory item

WindowShow (win, true)




end) -- end of coroutine
end -- function MapView_Redirect()



Now this works all fine and dandy, but there is one problem. I use these three triggers to omit the map from the output and...


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   keep_evaluating="y"
   match="^\-\-\-\-\-\-\-\-\-\-\- v4512 \-\-\-\-\-\-\-\-\-\-\-$"
   name="start"
   omit_from_log="y"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>EnableTrigger("middle", true)
EnableTrigger("end", true)

</send>
  </trigger>
</triggers>



<triggers>
  <trigger
   expand_variables="y"
   keep_evaluating="y"
   match="^(.*?)$"
   name="middle"
   omit_from_log="y"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  </trigger>
</triggers>



<triggers>
  <trigger
   expand_variables="y"
   lines_to_match="10"
   keep_evaluating="y"
   match="^\-\-\-\-\-\-\-\-\-\- 2\:18\:0 \-\-\-\-\-\-\-\-\-\-\-$"
   name="end"
   omit_from_log="y"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>EnableTrigger("end", false)
EnableTrigger("middle", false)
</send>
  </trigger>
</triggers>


it does omit the map from the output like I wanted it to, but, when I manually call the script that redirects the map, it doesn't omit the map from the output anymore, and sometimes will omit half the map, its weird. Bottom line is when I call the map redirect while I'm in a room where the map SHOULD be omitted, the map doesn't get omitted all the way, even though it should be. The map redirect seems to still work though. Another thing, in some rooms, when I walk in and call the script, the mini window seems to "blow up" across the whole screen. I've been stumped on these problems for the past few days and help would be greatly appreciated. Thanks again.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 14 Mar 2010 09:14 PM (UTC)
Message
On this page:

Template:post=9965 Please see the forum thread: http://gammon.com.au/forum/?id=9965.


It mentions (further down the page) about adding a flag to the main script to omit the matching lines from output. Then you don't need to add extra triggers.

- Nick Gammon

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

Posted by Nate7240   (16 posts)  [Biography] bio
Date Reply #2 on Sun 14 Mar 2010 09:38 PM (UTC)

Amended on Sun 14 Mar 2010 09:47 PM (UTC) by Nate7240

Message
Alright I did change the file, and it did work. Now, the way the map view works on aetolia is that each time you walk into a new room, it displays the map in your output. How would I go about implementing this so that it displays the mini window map without me having to manually call the function each time I go into a new room?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sun 14 Mar 2010 11:55 PM (UTC)
Message

I have been working on a mapper module, and interfacing it with IRE MUDs, amongst other. See this (from Aetolia):

You may wish to wait a few days for this to be released.


- Nick Gammon

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

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sun 14 Mar 2010 11:56 PM (UTC)
Message
Nate7240 said:

Alright I did change the file, and it did work. Now, the way the map view works on aetolia is that each time you walk into a new room, it displays the map in your output. How would I go about implementing this so that it displays the mini window map without me having to manually call the function each time I go into a new room?


To display your own map, you need to detect room changes. One way is to use the ATCP procotol, that sends a Room.Num message when the room changes.

- Nick Gammon

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

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #5 on Sun 14 Mar 2010 11:57 PM (UTC)
Message
Nick Gammon said:

Nate7240 said:

Alright I did change the file, and it did work. Now, the way the map view works on aetolia is that each time you walk into a new room, it displays the map in your output. How would I go about implementing this so that it displays the mini window map without me having to manually call the function each time I go into a new room?


To display your own map, you need to detect room changes. One way is to use the ATCP procotol, that sends a Room.Num message when the room changes.


This is a good approach, and is exactly what I did with my own map-window plugin. Except I used Room.Exits, since Room.Num hadn't been added yet, but they're sent in exactly the same situations.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nate7240   (16 posts)  [Biography] bio
Date Reply #6 on Mon 15 Mar 2010 12:39 AM (UTC)
Message
Nick, you mentioned I should use the ATCP protocol? Problem is I have not the slightest clue what that is, what it does, or how to use it. Maybe you can point me in the right way? Or if it helps, there may be a way to trigger a room change by the actual name of the room that is given. For example:

Old road nearing the plains. (road)
----------- v1304 -----------
/
[ ]-[ ]
/
[ ]
|
[ ]-
/
[+]
|
[ ]-
|
[ ]
\
[ ]
|
---------- -4:-5:0 ----------

Maybe I could trigger off of "Old road nearing the plains. (road)"? problem is the names can obviously vary and the (road) tag is not always there. The name is, however, always the same color of yellow.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #7 on Mon 15 Mar 2010 12:49 AM (UTC)

Amended on Mon 15 Mar 2010 12:51 AM (UTC) by Twisol

Message
Have you ever used Nexus, the Java-based client that's one of IRE's two official clients? The compass, gauges, latency meter, and map display are all powered by ATCP to some extent.

What is ATCP? It's a protocol based on Telnet's "subnegotiation" facility, sending hidden extra data embedded within the normal text. With a properly-enabled client, you can gain access to this extra data and use it for your own plugins.

MUSHclient doesn't come with ATCP support out of the box; however, both Nick and I have written ATCP plugins that make the ATCP data available. I've also recently written an ATCP library that any plugin can use without depending on a separate plugin, but it's still somewhat under review. You can get my plugin at [1], Nick's version at [2], and my ATCP library (which is probably easier to use than either of the plugins, though again still in beta) at [3].

If you decide to use my plugin, you'll probably also want to download my Roomname plugin to start from as a base, since I don't have any decent documentation yet. However, it's really easy to use.

(EDIT: And you might want to use [code][/code] tags for stuff like the MAP output you posted, so you preserve the formatting of the map.)

[1] http://jonathan.com/?page_id=29

[2] http://www.gammon.com.au/forum/bbshowpost.php?id=10129&page=1

[3] http://www.gammon.com.au/forum/bbshowpost.php?id=10129&page=3

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Mon 15 Mar 2010 12:50 AM (UTC)
Message
Just install the plugin mentioned here:

Template:post=10129 Please see the forum thread: http://gammon.com.au/forum/?id=10129.


Then, as suggested in the comments near the start of it, put in a OnPluginBroadcast function into your script, and you are away!


function OnPluginBroadcast (msg, id, name, text)
  if id == "85f72d0e263d75df7bde6f00" then
  
    if msg == 4 then
       
     -- room number has changed

    end -- if   
 
  end -- if ATCP message
end


- Nick Gammon

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

Posted by Nate7240   (16 posts)  [Biography] bio
Date Reply #9 on Mon 15 Mar 2010 01:20 AM (UTC)
Message
I need to get some rest, I've been at this all day. Can we pick this up tomorrow? And as for downloading the plugin, I'll have to download a newer version of MUSHclient, so it says. But thanks again for all the help today guys.

Oh, and by the way, If I just download that plugin and slap that bit of code into my script file/Map redirect function (which one?) it will magically work? Bear with me, I'm taking in as much info as I can :D.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Mon 15 Mar 2010 01:27 AM (UTC)
Message
Nate7240 said:

Alright I did change the file, and it did work. Now, the way the map view works on aetolia is that each time you walk into a new room, it displays the map in your output. How would I go about implementing this so that it displays the mini window map without me having to manually call the function each time I go into a new room?


Now that I re-read your question, I'm not sure the ATCP stuff will help. Your function relies on the map appearing, right? So knowing you have changed rooms won't do much.

You need to get your regexp right. And looking at this:


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   keep_evaluating="y"
   match="^\-\-\-\-\-\-\-\-\-\-\- v4512 \-\-\-\-\-\-\-\-\-\-\-$"
   name="start"
   omit_from_log="y"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>EnableTrigger("middle", true)
EnableTrigger("end", true)

</send>
  </trigger>
</triggers>


That looks to me like it will only work for room v4512. So you need to make a better regexp for the start of the map.

Something like:


match="^\-{11} \w+ \-{11}$"


Ditto for the other ones.

- Nick Gammon

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

Posted by Nate7240   (16 posts)  [Biography] bio
Date Reply #11 on Mon 15 Mar 2010 01:39 AM (UTC)

Amended on Mon 15 Mar 2010 01:53 AM (UTC) by Nate7240

Message
Alright I believe we all are off track :D so allow me to clear things up. Here is my current function that displays the map (it is called manually for right now, hence why it sends "look"):

edit: I do not use the triggers stated before at all, so ignore them.


require "wait"

function MapView_Redirect ()
wait.make (function () -- coroutine starts here

local win = GetPluginID () .. ":map"
local font = "f"

if not WindowInfo (win, 1) then
  WindowCreate (win, 0, 0, 0, 0, 6, 0, 0)
  WindowFont (win, font, "Lucida Console", 9)  
end -- if


-- request map

Send "look"

-- wait for map to start

local x = wait.match ("-*- v* -*-", 5, trigger_flag.OmitFromOutput)

if not x then
  return
end -- if

local map = {}
local max_width = WindowTextWidth (win, font, "Map")

-- loop untill end of map

while true do
   local line, wildcards, styles = wait.match ("*", 0, trigger_flag.OmitFromOutput)

   -- save map
   table.insert (map, styles)
   -- work out max width
   max_width = math.max (max_width, WindowTextWidth (win, font, line))

   -- see if end of map
   if string.match (line, "^-*- %d+:%d+:%d+ -*-") or
   string.match (line, "^-* %-%d+:%d+:%d+ -*-") or
   string.match (line, "^-* %d+:%-%d+:%d+ -*-") or
   string.match (line, "^-* %d+:%d+:%-%d+ -*-") or
   string.match (line, "^-* %-%d+:%-%d+:%d+ -*-") or
   string.match (line, "^-* %d+:%-%d+:%-%d+ -*-") or
   string.match (line, "^-* %-%d+:%d+:%-%d+ -*-") or
   string.match (line, "^-* %-%d+:%-%d+:%-%d+ -*-") then
   break
   end -- if

end -- while


local font_height = WindowFontInfo (win, font, 1)

local window_width = max_width + 10
local window_height = font_height * (#map + 2) +10

-- make window correct size
WindowCreate (win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB "#373737")
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

-- heading line

WindowText (win, font, "Map:", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each map line

local y = font_height * 2 + 5

for i, styles in ipairs (map) do

  local x = 5
  for _, style in ipairs (styles) do
    x = x + WindowText (win, font, style.text, x, y, 0, 0, style.textcolour)
  end -- for
  y = y + font_height

end -- for each inventory item

WindowShow (win, true)

end) -- end of coroutine
end -- function MapView_Redirect()


With that being said, my goal is to have the map from my output gagged and then redirected into the mini window, which is what this function does. Problem is, I have to call it manually (using /MapView_Redirect() in the command bar, which defeats the purpose because when I go into a new room, it is displayed in the output first, then when I call it manually, it updates he mini window). I am looking for a way to have it automatically detect a room change and redisplay the map accordingly. Here is an example of the map the MUD displays:


Fork in road through dusty plains. (road)
----------- v276 ------------
          | 
         [ ]
            \
             [ ]
              | 
             [ ]
              | 
             [+]-
            /   \
     [ ]-[ ]
    /
-[ ]
                             
                             
                             
--------- -3:-10:0 ----------


So when I go into a new room, that is whats displayed every time, of course the numbers and the room name will vary. If I have to completely modify my function I will but Please by all means throw any questions at me.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Mon 15 Mar 2010 03:00 AM (UTC)

Amended on Mon 15 Mar 2010 03:01 AM (UTC) by Nick Gammon

Message
Ah right. Well it seems you know when you change rooms, right, because you get the map.

So what I would do is this ...


  • Make a trigger along the lines of what I showed which matches the start of a map. This omits from output so you don't see that line, eg.

    
    ----------- v276 ------------
    


    However what the trigger does is call MapView_Redirect.

  • In MapView_Redirect, you don't do a "look" (because you already have the map), and you don't wait for that line, because you already have it. So you omit this:

    
    -- request map
    
    Send "look"
    
    -- wait for map to start
    
    local x = wait.match ("-*- v* -*-", 5, trigger_flag.OmitFromOutput)
    
    if not x then
      return
    end -- if
    


  • From now on though, the mapper code kicks in, omits the other lines, and draws the map.

- Nick Gammon

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

Posted by Nate7240   (16 posts)  [Biography] bio
Date Reply #13 on Mon 15 Mar 2010 07:54 PM (UTC)
Message
Alright Nick thanks a ton, it works perfectly now. And a big thank you to all the other people that made this happen :P. Id you'd like, when I'm all finished tweaking how it looks, I can post it as a plugin, but I'm not sure that you'd want me to considering I the whole entire thing is based off of your idea (brilliant idea. But once again, thanks guys and I'm sure you'll hear more dumb questions from me in the future.
[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.


25,373 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]