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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  My first time making a Plugin

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: My first time making a Plugin
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Llewellyn Owens   (2 posts)  [Biography] bio
Date Fri 04 May 2012 05:26 AM (UTC)  quote  ]
Message
I am trying to do a similar miniwindow for Lusternia. I am new to this and need some help though. I have got the script to work and show a miniwindow.

It just display a text list of people at the moment though. I would like to have an attempt at applying hot spots to each of the names so I can automatically target them. Buttons against each name would also work then I could chose to enemy or ally or follow etc. Could somebody give me some direction on how to modify the script above to do this.

The in game command "who here" returns the following:

You see the following people here:
Haghan, Toracu, Lyna, Ragak
[Go to top] top

Posted by Kevnuke   USA  (83 posts)  [Biography] bio
Date Mon 30 Apr 2012 06:27 AM (UTC)  quote  ]
Message
Jose, does your MUD use any type of Telnet subnegotiation protocol, such as MXP, ATCP, or GMCP?
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Thu 19 Apr 2012 10:38 AM (UTC)  quote  ]
Message
Probably the trigger did not match what you expected.

- Nick Gammon

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

Posted by Joseisme   (11 posts)  [Biography] bio
Date Thu 20 Oct 2011 03:30 AM (UTC)  quote  ]

Amended on Thu 20 Oct 2011 04:10 AM (UTC) by Joseisme

Message
WOW! That works so nicely now. I even added "SendNoEcho ("info")" to it so even that doesn't show up. Now only a single blank line appears when I update (which I can live with).

This little program can now be customized to work with a whole bunch of stuff in my little MUD.

Thanks again!


p.s. I owe you one.

p.s.s The dodgerblue in the heading does look a lot nicer.
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Thu 20 Oct 2011 02:27 AM (UTC)  quote  ]
Message
Forget the triggers. Just change the alias like this:


<aliases>
  <alias
   match="inv"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

require "wait"

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


local win = GetPluginID () .. ":status"
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 inventory

Send "info"  -- this mud uses info to get the status

-- wait for status screen to start

local line, wildcard, styles = wait.match ("Name: *", 10, trigger_flag.OmitFromOutput)

if not line then
  ColourNote ("white", "blue", "No status received within 10 seconds")
  return
end -- if

local inv = {}
local max_width = WindowTextWidth (win, font, "Status")

-- loop until end of status

while true do
  -- save status line
  table.insert (inv, styles)
  -- work out max width
  max_width = math.max (max_width, WindowTextWidth (win, font, line))

  line, wildcards, styles = wait.match ("*", 10, trigger_flag.OmitFromOutput)

  -- see if end of status

  if string.match (line, "%(To view *") then
    break
  end -- if

end -- while loop

local font_height = WindowFontInfo (win, font, 1)

local window_width = max_width + 10
local window_height = font_height * (#inv + 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, "Status", 5, 5, 0, 0, ColourNameToRGB  "dodgerblue")

-- draw each status line

local y = font_height * 2 + 5

for i, styles in ipairs (inv) 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 status item

WindowShow (win, true)


end)   -- end of coroutine</send>
  </alias>
</aliases>


- Nick Gammon

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

Posted by Joseisme   (11 posts)  [Biography] bio
Date Thu 20 Oct 2011 01:55 AM (UTC)  quote  ]
Message
Note I would use a lot of other triggers to omit the rest of it but I just included the first one as an example.
[Go to top] top

Posted by Joseisme   (11 posts)  [Biography] bio
Date Thu 20 Oct 2011 01:41 AM (UTC)  quote  ]

Amended on Thu 20 Oct 2011 01:49 AM (UTC) by Joseisme

Message
Thank you SOOOO much. It works beautifully! Ya I thought I had escaped it with a "\" at one time but in this context I now know to use a "%" Thanks!

The next problem I have is to make it update behind the scenes. (As mentioned previously) I would normally use triggers like this to white wash (omit) it away, line by line. But that no longer seems to work because when I do it it seems to remove the data from the script too so I get an error. (10 second time out error)

(example of the first trigger used to omit the original output)

<triggers>
  <trigger
   enabled="y"
   match="^Name\: (.*?)    Race\:  (.*?)    Gender\: (.*?)$"
   omit_from_output="y"
   regexp="y"
   sequence="100"
  >
  </trigger>
</triggers>


You have already done so much to help me on this project so if you just want to point me in right direction I will research it and do what I can.
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Thu 20 Oct 2011 12:51 AM (UTC)  quote  ]
Message
Nick Gammon said:

Well if you watched the video there would be a trigger as well.


Er, alias. ;)

- Nick Gammon

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

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Thu 20 Oct 2011 12:49 AM (UTC)  quote  ]
Message
Oh, wait. It doesn't show the name. Well with a little reorganizing it can:


<aliases>
  <alias
   match="inv"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

require "wait"

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


local win = GetPluginID () .. ":status"
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 inventory

Send "info"  -- this mud uses info to get the status

-- wait for status screen to start

local line, wildcard, styles = wait.match ("Name: *", 10)

if not line then
  ColourNote ("white", "blue", "No status received within 10 seconds")
  return
end -- if

local inv = {}
local max_width = WindowTextWidth (win, font, "Status")

-- loop until end of status

while true do
  -- save status line
  table.insert (inv, styles)
  -- work out max width
  max_width = math.max (max_width, WindowTextWidth (win, font, line))

  line, wildcards, styles = wait.match ("*")

  -- see if end of status

  if string.match (line, "%(To view *") then
    break
  end -- if

end -- while loop

local font_height = WindowFontInfo (win, font, 1)

local window_width = max_width + 10
local window_height = font_height * (#inv + 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, "Status", 5, 5, 0, 0, ColourNameToRGB  "dodgerblue")

-- draw each status line

local y = font_height * 2 + 5

for i, styles in ipairs (inv) 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 status item

WindowShow (win, true)


end)   -- end of coroutine</send>
  </alias>
</aliases>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.



- Nick Gammon

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

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Thu 20 Oct 2011 12:44 AM (UTC)  quote  ]
Message
With that correction it appears to work, I get this:


- Nick Gammon

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

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Thu 20 Oct 2011 12:41 AM (UTC)  quote  ]
Message
This line:


  if string.match (line, "(To view *") then


gives me:


C:\Program Files\MUSHclient\lua\wait.lua:67: [string "Alias: "]:39: unfinished capture


If you need to use brackets in a string.match you have to "escape" them with % like this:


  if string.match (line, "%(To view *") then

- Nick Gammon

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

Posted by Joseisme   (11 posts)  [Biography] bio
Date Thu 20 Oct 2011 12:20 AM (UTC)  quote  ]
Message
Sure thing. Here is the entire script plus the alias. Umm I re-watched the videos again just to make sure I didn't miss a "trigger". As far as I could tell there isn't one in this tutorial. An update trigger was mentioned at the end when he talks about the "when you drop a mace" but it was never really worked on and I myself would have no trouble making something like that from scratch. I would probably have it update whenever you lost health or energy.

Tutorial
part 1
http://www.youtube.com/watch?v=l5jXqHOn7L0
part 2
http://www.youtube.com/watch?v=0AF1AvPwVxk

By the way, I mentioned another tutorial that works off of a trigger but that has nothing to do with this particular code.


<aliases>
  <alias
   match="inv"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

require "wait"

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


local win = GetPluginID () .. ":status"
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 inventory

Send "info"  -- this mud uses info to get the status

-- wait for status screen to start

local x = wait.match ("Name: *", 10)

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

local inv = {}
local max_width = WindowTextWidth (win, font, "Status")

-- loop until end of status

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

  -- see if end of status

  if string.match (line, "(To view *") then
    break
  end -- if

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

end -- while loop

local font_height = WindowFontInfo (win, font, 1)

local window_width = max_width + 10
local window_height = font_height * (#inv + 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, "Status", 5, 5, 0, 0, ColourNameToRGB  "blue")

-- draw each status line

local y = font_height * 2 + 5

for i, styles in ipairs (inv) 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 status item

WindowShow (win, true)


end)   -- end of coroutine</send>
  </alias>
</aliases>


That's every thing that was included in the tutorial. The only thing I changed was some of the names, colors and of course tinkering with the match loop to try to get it to read the whole status window. Thanks for all the feedback.

If you want to take it a step further and test something in the same environment as I am, here is the mud address clok.contrarium.net port: 4000 And I already set up a testing char with some damage on his status. --login Ploogene abc

(means his name is "Ploogene" and pass is "abc". Once logged in type "info" for status screen)

[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Wed 19 Oct 2011 08:35 PM (UTC)  quote  ]
Message
Well if you watched the video there would be a trigger as well. Can you post the whole thing, and not just the script part?

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


Then I can test it against your test data.

- Nick Gammon

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

Posted by Joseisme   (11 posts)  [Biography] bio
Date Wed 19 Oct 2011 09:59 AM (UTC)  quote  ]

Amended on Wed 19 Oct 2011 10:02 AM (UTC) by Joseisme

Message
Thanks for the reply!

Ya that is the tutorial I watched earlier (read previous post about tutorial #2)

I am not very fluent in Lua so I tried a few things with it but could never get it to quite work. The best I had it doing was to list all of the damage section. (that's the part below "Fatigue: Fully Rested Hunger: Well-Fed" and above "(To view your skills, type skills"

I even let it go at that at one point but the problem is it would no longer let me use other triggers to omit the lines of the original output. The reason I am omitting that is because I want to set up triggers to have the status update frequently and don't want to have it cluttering up the screen with the same info over and over again to do so. (kinda a secret update or a move to status window dealio)

I'll show what I tried:


require "wait"

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


local win = GetPluginID () .. ":status"
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 inventory

Send "i"  -- this mud uses the letter i to get the status

-- wait for status screen to start

local x = wait.match ("Name: *", 10)

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

local inv = {}
local max_width = WindowTextWidth (win, font, "Status")

-- loop until end of status

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

  -- see if end of status

  if string.match ("(To view *") then
    break
  end -- if

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

end -- while loop

local font_height = WindowFontInfo (win, font, 1)

local window_width = max_width + 10
local window_height = font_height * (#inv + 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, "Status", 5, 5, 0, 0, ColourNameToRGB  "blue")

-- draw each status line

local y = font_height * 2 + 5

for i, styles in ipairs (inv) 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 status item

WindowShow (win, true)


end)   -- end of coroutine


It would seem the problem area is the match loop. So without altering it too much I made another version as close to the original as I could

(matching loop portion only)

local x = wait.match ("Fatigue: *", 10)

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

local inv = {}
local max_width = WindowTextWidth (win, font, "Inventory")

-- loop until end of inventory

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

  -- see if end of inventory

  if not string.match ("Your *") then
    break
  end -- if 


The one above at least did something but I was missing a lot of info from the status screen and I was unable to omit the parts from the output that I -WAS- able push up to the window.



I even tried to get fancy and use regular expressions (which don't seem to work in this format)


local x = wait.match ("^Name\: (.*?)    Race\:  (.*?)    Gender\: (.*?)$", 10)

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

local inv = {}
local max_width = WindowTextWidth (win, font, "Inventory")

-- loop until end of inventory

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

  -- see if end of inventory

  if string.match ("^\(To view your skills\, type skills$") then
    break
  end -- if


Odds are I am overlooking something simple. (like I said I'm new) But if there is a way to match the entire status screen and omit it from output. Please let me know.
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Wed 19 Oct 2011 07:48 AM (UTC)  quote  ]
Message
This one should be what you want:

http://www.youtube.com/watch?v=l5jXqHOn7L0


If it isn't working can you post what you have so far?

- 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.


2,251 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]