[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]  Capturing / Weird Characters and how to fix them
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Capturing / Weird Characters and how to fix them

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


Posted by Caelan   Vanuatu  (12 posts)  [Biography] bio
Date Sat 20 Jan 2007 08:11 PM (UTC)
Message
Part I. I was wondering how I could make something to capture certain names/locations off of Achaea's WHO command, and then organize it into a list.

Example (Achaea's WHO command looks like):
Super Johnny, Littlest Master (Over here)
Johnny Johnerton, John, of Noone (Over there)

The first one is named Johnny, the other John.

I want to be able to (if Johnny belongs to a certain list) record his location and display it when I type a certain command. Preferably, an entire list of people. If it helps, the names of the people are in a different color than the remainder of their titles. What would you recommend as the easiest way to do this? I was thinking (from reading around) that a table would work to record the name and location. But how would I compare it to the list of people I wanted to watch?

Preferably I would like it to run when I type WHO (going to have to hit MORE a few times) and capture basically everyone's location. Then I type WHOL or some such and it prints up like:

[Bad People] : Johnny (Over here)
[Bad People] : Other_Guy (Right here)



also, if someone has a really long title, it looks like this on the WHO command:
So and so, Tool, with absurd title((house) A candelit sanctuary). Is there a way to fix that?

Thanks in advance. Sorry if this has been asked before. I had a WHOLIST like this for ZMud but was wondering how I could do it for Mush or what would be the most efficient way of doing so.
[Go to top] top

Posted by Caelan   Vanuatu  (12 posts)  [Biography] bio
Date Reply #1 on Mon 22 Jan 2007 01:38 PM (UTC)
Message
I was poking around the HELP files and was wondering if I could use something like..

ArrayCreate to make a list of names and their locations (or would it have to be in a table?)

Then for the output maybe use Note(ArrayExportKeys("arrayname" , "-"))

- OR -
Would something using ArrayListKeys and ArrayGet be better? Also how to implement?

Would this work? And how would I go about making the table/array capture the name AND location?

Also, how could I turn it on and off so I don't constanly capture and instead only capture when I type WHO and off when it's done (could trigger it on a "There is no more" type msg??
[Go to top] top

Posted by Caelan   Vanuatu  (12 posts)  [Biography] bio
Date Reply #2 on Mon 22 Jan 2007 02:09 PM (UTC)
Message
Ok..sorry. Was poking around some more.

Would:

badpeople = {}
badpeople.wholist = {
name = "%1"
location = "%2"

capture what I want?

Then do like...

function wholisting (name, line, wildcards)
if city == badpeoplecity then
 table.foreach (badpeople.wholist) ColourNote("red", "black", "[BADPEOPLE]:”, print (badpeople.wholist.name) .. “      -      “  .. print (badpeople.wholist.location) .. )
end -- function


attached to an alias to do wholisting


Sorry, I am brand new to MUSH and scripting in any detail so any help would be hugely appreciated.
[Go to top] top

Posted by Nick Gammon   Australia  (21,609 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Mon 22 Jan 2007 07:30 PM (UTC)
Message
Quote:

Would something using ArrayListKeys and ArrayGet be better? Also how to implement?


I wouldn't use the Array stuff in MUSHclient, as that was added before Lua scripting. The Lua tables make managing table data (arrays) much more natural.

Quote:

Would:

badpeople = {}
badpeople.wholist = {
name = "%1"
location = "%2"

capture what I want?


This example would create a new table (assuming this is in a trigger) for each person, and thus the table would only every have one entry.

Something like this might work better for you:


badpeople = badpeople or {} -- make table if necessary
badpeople ["%1"] = "%2"  -- save location of this person


The first line creates the table "badpeople" if it does not exist.

The second line adds (or replaces) an entry, keyed by the person's name, with their location as the table data.

Quote:

Then do like...

function wholisting (name, line, wildcards)
if city == badpeoplecity then
table.foreach (badpeople.wholist) ColourNote("red", "black", "[BADPEOPLE]:”, print (badpeople.wholist.name) .. “ - “ .. print (badpeople.wholist.location) .. )
end -- function



The syntax is a bit skewed here. For one thing table.foreach is deprecated, and may not be in a future version. For another the table.foreach expects its second argument to be a function, to which it passes each item in the table it is iterating over. This code below should work, and looks simpler anyway:


function wholisting (name, line, wildcards)
  for name, location in pairs (badpeople) do
    ColourNote ("red", "black", 
       "[BADPEOPLE]: '" .. name .. "' - '" .. location .. "'")
  end -- for
end -- function


Inside the for loop above, I am retrieving the key and value of each table item (calling them 'name' and 'location') and using them inside a ColourNote.

- Nick Gammon

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

Posted by Wyd   (14 posts)  [Biography] bio
Date Reply #4 on Tue 23 Jan 2007 04:05 AM (UTC)
Message
On the same note,


I know it is possible to capture a line by colour (eg, only green text is considered), but is it possible to match part of a line with colour..

For example,

The line is:

This is a (green)test(/green) and I WANT ALL THIS AS WELL
and what is captured is:

test I WANT THIS AS WELL

I tried to do this using splitting the different styles (assuming that a new colour would be a new style), but it seems that doesn't work, unless I was doing something wrong


Hope this at least makes some sense,

Wyd

[Go to top] top

Posted by Nick Gammon   Australia  (21,609 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Wed 24 Jan 2007 06:12 AM (UTC)
Message
See GetStyleInfo - you can make a trigger that matches the line in any colour, then in a script check the style runs to see if it has a particular colour sequence. This is easier in Lua which passes the style information to trigger functions as an extra argument.

http://www.gammon.com.au/scripts/doc.php?function=GetStyleInfo

This has been covered a bit before in the forum, try searching for GetStyleInfo, or look for examples of checking styles in Lua.

- Nick Gammon

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

Posted by Wyd   (14 posts)  [Biography] bio
Date Reply #6 on Wed 24 Jan 2007 06:48 AM (UTC)
Message
Yup, worked out how to do it...thanks for the link
[Go to top] top

Posted by Caelan   Vanuatu  (12 posts)  [Biography] bio
Date Reply #7 on Tue 06 Feb 2007 04:20 PM (UTC)
Message
Trigger (would have to enable/disable the trigger group) and would be based on a color code since that's the easiest way to break the actual name from the title. Still can't mess with that (stupid firewall at work)

So if I put :

badpeople = badpeople or {} 

in the script file then

how would I trigger something like:
Super Johnny, Littlest Master (Over here)

Would I just trigger it to do:

wholist ["%1"] = "%2"


and then run the function (would be off an alias)

function wholisting (name, line, wildcards)
  for name, location in pairs (wholist) do
    ColourNote ("red", "black", 
       "[BAD PEOPLE]: '" .. name .. "' - '" .. location .. "'")
  end -- for
end -- function


Sorry if it's a stupid simple question. None of the manuals will load while here at work and I can't seem to find time once I get home (ironic eh?) and I just want to try and get it right before I throw in some other things. Where would I add in something like...

if @!CityEnemy.. would I make it in the function to do :

function wholisting (name, line, wildcards)
  for name, location in pairs (wholist) do
   if @!CityEnemy then
    ColourNote ("red", "black", "[CITY ENEMY]: '" .. name .. "' - '" .. location .. "'")
   end -- if
  end -- for
end -- function


Thanks a million for any and all help!
[Go to top] top

Posted by Nick Gammon   Australia  (21,609 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Tue 06 Feb 2007 06:55 PM (UTC)
Message
Quote:

if @!CityEnemy then


I can't quite visualise what you are trying to do here. Can you post some or all of the contents of the CityEnemy variable, to help me?

- Nick Gammon

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

Posted by Caelan   Vanuatu  (12 posts)  [Biography] bio
Date Reply #9 on Tue 06 Feb 2007 08:31 PM (UTC)
Message
DOH! Sorry. CityEnemy variable is basically a list of names seperated by a "|" pipe. So...

John|Paul|Mary...
[Go to top] top

Posted by Nick Gammon   Australia  (21,609 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Tue 06 Feb 2007 11:39 PM (UTC)

Amended on Tue 06 Feb 2007 11:41 PM (UTC) by Nick Gammon

Message
This snippet should show the general idea:



-- dummy wholist for testing

wholist = {
  John = "Town Square",
  Peter = "Fruit Shop",
  Mary = "Butcher",
  }

-- build table of enemies
enemies = {}
for w in string.gmatch ("John|Paul|Mary", "%a+") do
  enemies [w] = true
end -- for

-- check wholist against table

for name, location in pairs (wholist) do
   if enemies [name] then
    ColourNote ("red", "black", "[CITY ENEMY]: '" .. name .. "' - '" .. location .. "'")
   end -- if
  end -- for

Example output:

[CITY ENEMY]: 'John' - 'Town Square'
[CITY ENEMY]: 'Mary' - 'Butcher'





I have made a dummy wholist to show the general idea. Now in a trigger you could substitute your variable CityEnemy like this:


enemies = {}
for w in string.gmatch ("@!CityEnemy", "%a+") do
  enemies [w] = true
end -- for


But I think you may as well simply get the variable:


enemies = {}
for w in string.gmatch (GetVariable ("CityEnemy"), "%a+") do
  enemies [w] = true
end -- for

- Nick Gammon

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

Posted by Caelan   Vanuatu  (12 posts)  [Biography] bio
Date Reply #11 on Mon 12 Feb 2007 07:13 PM (UTC)
Message
8421376 aka 'teal' is the color I want to capture.

My question is, how do I capture it in a trigger? I clicked through the functions page and found some things I thought might work but don't.
Ex.
John's Angel, Maria, the HeartBreaker (Over Here in BFE)

where 'Maria' is the teal color and location is in ()s

GetStyleInfo(8421376) ??
GetLineInfo ??

Not quite sure how to actually get the trigger to recognize the color, and assign it to a variable/table if it's teal.

Thanks for the help so far.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #12 on Thu 08 Mar 2007 04:02 PM (UTC)
Message
You shouldn't be looking for colour teal in the line. The colour you see in the output window isn't really what the MUD sends - it's just what you happen to have a particular colour code sent by the MUD mapped to in the client's preferences.

What you should do is use the GetNormalColour/GetBoldColour functions to get the current RGB value for an ANSI colour, then figure out (from the ANSI colour settings dialog) which ANSI colour your "teal" corresponds to, and then, when a line matches, go through all the styles and compare the foreground colours to what is saved in your colour mapping table.

For example, if you wanted to find any words coloured with ANSI red (normal, not bold) in an incoming line, you could use a script like this:


-- list of colour names and values for callbacks
colours = {black = 1,
 red=2,
 green=3,
 yellow=4,
 blue=5,
 magenta=6,
 cyan=7,
 white=8
}

-- a function called by the trigger
function find_red(name, outp, wildcs, styles)
 for _,s in ipairs(styles) do
  if s.textcolour == GetNormalColour(colours.red) then
    print(s.text, " is red!")
  end
 end
end






[Go to top] top

Posted by Nick Gammon   Australia  (21,609 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Thu 08 Mar 2007 07:31 PM (UTC)
Message
Quote:

where 'Maria' is the teal color and location is in ()s

GetStyleInfo(8421376) ??
GetLineInfo ??

Not quite sure how to actually get the trigger to recognize the color, and assign it to a variable/table if it's teal.


There is an example trigger in the exampscript.lua file that comes with MUSHclient:


function ExampleTrigger (thename, theoutput, wildcards, line)

  require "tprint"

  Note ("Trigger " .. thename .. " fired.")
  Note ("Matching line was: " .. theoutput)
  Note ("Wildcards ...")
  tprint (wildcards)
  Note ("Line with style runs ...")
  tprint (line)

end -- of ExampleTrigger


If I put that in my script file, and then make a trigger to match my prompt line "<28hp 105m 110mv>" (which has multiple colours), you can see the general idea:


Trigger  fired.
Matching line was: <28hp 105m 110mv> 
Wildcards ...
1="28"
2=" 105m 110mv> "
0="<28hp 105m 110mv> "
Line with style runs ...
1:
  "textcolour"=12632256
  "backcolour"=0
  "length"=1
  "style"=0
  "text"="<"
2:
  "textcolour"=65535
  "backcolour"=0
  "length"=5
  "style"=1
  "text"="28hp "
3:
  "textcolour"=16776960
  "backcolour"=0
  "length"=5
  "style"=1
  "text"="105m "
4:
  "textcolour"=65280
  "backcolour"=0
  "length"=5
  "style"=1
  "text"="110mv"
5:
  "textcolour"=12632256
  "backcolour"=0
  "length"=2
  "style"=0
  "text"="> "
Script Loaded



In this case "28hp" was in yellow, "105m" was in cyan, and "110mv" was in green. We can confirm these by working backwards from the colours in the trigger match.


/print (RGBColourToName (65535))    --> yellow
/print (RGBColourToName (16776960)) --> cyan
/print (RGBColourToName (65280))    --> lime (a form of green)


Now you can use code like Ked suggested to find a match on the colour that you find, with the text you want.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


7,803 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]