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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Getting mobs out of a room.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Getting mobs out of a room.

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


Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Thu 25 Feb 2016 01:30 AM (UTC)

Amended on Thu 25 Feb 2016 01:35 AM (UTC) by Wuggly

Message
What I'm basically trying to do is get a list of all the mobs in a current room and throw them into a table (to show in a miniwindow).

Problem is the room description, the weather (if any), and the mobs are all together.

Here's an example of what a room looks like on a MUD I play.

An Entrance to the Caverns
[Exits: north up]

Partially hidden by the brush on the side of the mountain, a large cave opens 
before you. Seeming to appear right out of the rock and brush, guards confront
you as you try to enter the caves.
The sky is cloudless and a cold northern gust blows.
A small dog sniffs around here.
A ranger guard stands here, keeping watch.
A ranger guard stands here, keeping watch.



I'm not too sure if this is possible, but figured I'd ask since the mob names are always in a dark purple color thinking it might be possible using something like GetStyles, but I just have no clue where to begin on something like this since the column numbers would always be different plus since it would be multiple lines and no specific words to match on.

Thinking out loud here (feel free to ignore everything below this).
Perhaps have a trigger for exits to set a variable like start_reading = true then when a blank line shows up (since there is always a blank line before room description/weather/mobs) if that start_reading variable is true to start somehow putting every line into its own variable until the prompt which would change the start_reading variable to false. Then get the style of each line and only print out the ones in the dark purple color, which would be the mobs in the room.

What if I made a trigger in regex like ^$ that would set start_reading = true, and when it sees your prompt it would turn it back off.

Maybe a series of triggers like when that blank line is matched that turns start_reading to true to have it turn on a trigger, something like ^(.+)$ then when matched, it puts all that into a variable, lets say line_one = %1, turns that trigger off, and turns another similar trigger on except the variable in that one would be line_two = %1 and make like 20 or 30 triggers to make sure I capture every line in the room.

Lets say a room only has 9 lines then I could just put an if statement in the line_one line_two and so on variables like if start_reading = true so it doesnt run through all of them for smaller rooms. Then maybe some sort of failsafe like have the prompt turn all of those ^(.+)$ triggers off...

Yeah I'm pretty lost and just babbling on... got to be an efficient way to accomplish this... but then again if I can't match the colors to get those mobs its all pointless anyways or maybe Im just way overthinking this. Any ideas?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 25 Feb 2016 06:12 AM (UTC)
Message
See this: http://www.gammon.com.au/forum/bbshowpost.php?id=7818

It should be easy to take a word (eg. "small dog"), find what column that is at, and then find the style of that column. The page above has an example.

- Nick Gammon

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

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #2 on Thu 25 Feb 2016 03:14 PM (UTC)
Message
If I could just match it by mob name then I would have no need to figure out the color of it and it would be easy, the problem is the mobs are always different and there are thousands of different mob names, maybe even more than that, which would make this a massive project. Players who have been on this particular server for over the past 15 years still don't know every mob there is.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 25 Feb 2016 08:21 PM (UTC)
Message
OK, well in a trigger you can get the style runs. You just "walk" them looking for a specific colour. Quite possibly, since the messages are computer-generated, a mob name will always be a particular style run (eg. the 3rd one).

So just check if the 3rd style run happens to be purple.

- Nick Gammon

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

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #4 on Fri 26 Feb 2016 04:47 PM (UTC)

Amended on Fri 26 Feb 2016 04:58 PM (UTC) by Wuggly

Message
Thanks Nick. Also after re-reading my last reply it sounds a bit rude now, so sorry if it sounded that way to you too, just at the time, I was trying to be detailed.
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #5 on Fri 26 Feb 2016 05:54 PM (UTC)

Amended on Fri 26 Feb 2016 06:00 PM (UTC) by Wuggly

Message
I've ran into another problem. I am successfully reading the mobs in the room and putting them into a table by detecting their colour.

However, when a mob has a - in the name, it doesn't add that mob into the table.

Here is the trigger that turns on after seeing the exits to start reading everything in the room.

  <trigger
   enabled="n"
   keep_evaluating="y"
   match="^(.+)$"
   regexp="y"
   name="read_lines"
   script="check_lines"
   sequence="100"
  >
  </trigger>


And here the function that puts the mobs into the table.

function check_lines (name, line, wildcards, styles)
 
  -- find location of word
  col = string.find (line, wildcards[1])
  if not col then
    return
  end -- word not found

  -- get style at that location
  style = GetStyle (styles, col)

  mob_colour = RGBColourToName (style.textcolour)

  -- display it
 if mob_colour == "purple" then
  room_mobs [#room_mobs + 1] = style.text
 end -- mob_colour
end -- check_lines


ie: His tail wagging, a long-haired black dog watches you curiously.

I imagine when it adds a name like that into the table it's using the minus in the name to subtract. Any idea how to fix something like this so it adds it in?

I've tried a few things, but with no luck. Is there some way to escape that character if it appears in a mob name when adding it into a table? I'm lost on this one...
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Fri 26 Feb 2016 08:25 PM (UTC)
Message

  col = string.find (line, wildcards[1])


I don't even see what that code does. "line" is the matching line, and "wildcards [1]" is also the matching line. What is the point of the string.find?

- Nick Gammon

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

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #7 on Fri 26 Feb 2016 08:56 PM (UTC)

Amended on Fri 26 Feb 2016 09:45 PM (UTC) by Wuggly

Message
Yeah you're right, no idea what I was thinking at the time, I've just never messed with styles before. Also any ideas about the - in mob names getting them to add into the table?

I changed it up and it makes sense now. Here's the function.

function check_lines (name, line, wildcards, styles)

  -- get style at that location
  style = GetStyle (styles, 1)

  mob_color = RGBColourToName (style.textcolour)

  -- display it
 if mob_color == "purple" then
  room_mobs [#room_mobs + 1] = style.text
 end -- mob_color
end -- check_lines


EDIT: Actually never mind. Fixing the function fixed my table problem. Thanks for the clarity Nick!

Very much appreciated!
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #8 on Sat 27 Feb 2016 03:23 PM (UTC)
Message
So I have two colours that are the same that I'm trying to pull out, but I'm not sure how to refer to a second colour of the same colour. I have two silver colours, and I need to match the second silver sentence.

I also don't know how to pull out the sentence after the second matched colour.

ie:
The sky is cloudless and a cold northern gust blows..
matches for first silver.

(White Aura) A white black-tailed bunny hops here.
( matches for second silver. Not sure why it doesn't pick up the whole (White Aura).

Sentence is in purple.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Sat 27 Feb 2016 08:25 PM (UTC)
Message
Quote:

Not sure why it doesn't pick up the whole


I'm not sure what "it" refers to here. Your code? I can't advise on what code that I can't see does or doesn't do.

- Nick Gammon

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

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #10 on Sat 27 Feb 2016 09:24 PM (UTC)
Message
Nick Gammon said:

I'm not sure what "it" refers to here. Your code? I can't advise on what code that I can't see does or doesn't do.


Yes the code.


function check_lines (name, line, wildcards, styles)

  -- get style at that location
  style = GetStyle (styles, 1)

  mob_colour = RGBColourToName (style.textcolour)

  -- display it
 if mob_color == "purple" then
  room_mobs [#room_mobs + 1] = style.text
 end -- mob_colour
end -- check_lines


Just added a print ("word is in", RGBColourToName (style.textcolour))

When ran through looking in a room, for weather it shows silver and if the mob has an aura, like (White Aura) it also says silver, and when I add in print ("words matched ", style.text) the weather shows fine but the second silver, the one that says (White Aura), says the text for it is just ( the first symbol.

Trying to figure out how to catch all of the second silver line.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Sun 28 Feb 2016 03:16 AM (UTC)
Message
Try tprinting the styles like this:


function check_lines (name, line, wildcards, styles)

  require "tprint"
  tprint (styles)

end -- check_lines


It might become more obvious what to do. For example, if style 1 is in silver you might just test style 2 instead.

- Nick Gammon

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

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #12 on Mon 29 Feb 2016 02:19 PM (UTC)

Amended on Mon 29 Feb 2016 02:22 PM (UTC) by Wuggly

Message
I still can't quite figure out how to get the White Aura style and display it into the mini window.

Currently when reading the lines in between Exits and your prompt, I have it where it only stores the styles if the textcolour is purple.


function check_lines (name, line, wildcards, styles)

require "getstyle"

 style = GetStyle (styles, 1)
 mob_colour = RGBColourToName (style.textcolour)
   if mob_colour == "purple" then
    table.insert (room_mobs, styles)
    print ("Read and stored styles into table")
    draw_a_room_mob ()
   end -- mob_colour

end -- check_lines


I tried storing all of the styles instead of just the purple text ones, but then I wasn't sure how to pull specific ones back out for when drawing it into the mini-window.

Here's how it is drawn into the mini-window.

function draw_a_room_mob ()
  local font = "f"
  local font_height = 11
  -- clear the background
  check (WindowDrawImage (a_room_mob_window, "a_room_mob_background", 0, 0, 0, 0, 1))  -- redraw the background
  local y = font_height * 2 + 5 - 25
  for i, styles in ipairs (room_mobs) do
    local x = 3
     for _, style in ipairs (styles) do
      x = x + WindowText (a_room_mob_window, font, style.text, x, y, 0, 0, style.textcolour, false)
     end -- for
   y = y + font_height
  end -- for each mob style
 Redraw ()
end -- draw_a_room_mob


So when I have check_lines storing all the styles instead of just the purple ones into the room_mobs table, in draw_a_room_mob function how can I pull it out for the WindowText?

Trying to be able to display mobs with (White Aura) and the mob name and display the normal ones without the white aura.

Here's the styles it shows when looking in a room with a (White Aura) mob in it.

1:
  "textcolour"=12632256
  "backcolour"=0
  "length"=1
  "style"=0
  "text"="("
2:
  "textcolour"=16777215
  "backcolour"=0
  "length"=10
  "style"=1
  "text"="White Aura"
3:
  "textcolour"=12632256
  "backcolour"=0
  "length"=2
  "style"=0
  "text"=") "
4:
  "textcolour"=8388736
  "backcolour"=0
  "length"=55
  "style"=0
  "text"="A Warden of the Frontier stands here alert for trouble."
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Mon 29 Feb 2016 07:41 PM (UTC)

Amended on Tue 01 Mar 2016 09:06 PM (UTC) by Nick Gammon

Message
Something like this?


function check_lines (name, line, wildcards, styles)

 -- check each style
 for k, style in ipairs (styles) do
   if RGBColourToName (style.textcolour) == "purple" then
    table.insert (room_mobs, style.text)
    print ("Read and stored", style.text, "into table")
    draw_a_room_mob ()
    break  -- stop once we find one
   end -- mob_colour
  end -- for
  
end -- check_lines

- Nick Gammon

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

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #14 on Tue 01 Mar 2016 01:26 PM (UTC)
Message
Exactly what I was needing. Only thing I changed with it was so it stored the whole style instead of just the text so it can reflect the background and text colour too.

Thank you Nick and thanks for answering all my questions getting me through all these roadblocks with Lua these past couple months. The support you and others provide here is amazing.
[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.


3,865 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 FutureQuest]