Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Newbie question

Newbie question

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


Pages: 1  2 

Posted by Jedhi   (37 posts)  Bio
Date Reply #15 on Thu 29 Sep 2011 11:43 AM (UTC)

Amended on Thu 29 Sep 2011 11:46 AM (UTC) by Jedhi

Message
now i don't know from where to start. i would like to create on alias/trigger which uses the where command (aardwolf) to locate the mob and if successful uses aard mapper to do mapper area location

where <mob>
response to previous command: <mob> <location>
mapper area <location>

how do i get the <location> into the variable?
Top

Posted by Jedhi   (37 posts)  Bio
Date Reply #16 on Fri 30 Sep 2011 11:19 AM (UTC)
Message
anyone?
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #17 on Fri 30 Sep 2011 12:33 PM (UTC)
Message
Can you post actual example output?

Basically you need a trigger to match whatever it is that gives the mob's location.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Jedhi   (37 posts)  Bio
Date Reply #18 on Fri 30 Sep 2011 12:45 PM (UTC)
Message

The Entrance to a Large Forest
  You have stumbled upon a well-trampled path that leads deeper into a lush
forest.  Game can be heard off to the north, and a small wisp of smoke can be
seen in the distance.  

[ Exits: north west ]
     A crude sign that points north is staked into the ground.

[2341/2341hp 2052/2052mn 1761/1771mv 7qt 3300tnl] > 
where fish
a flathead mudfish           On a Muddy Embankment

[2341/2341hp 2052/2052mn 1761/1771mv 7qt 3300tnl] > 


where fish is my command. would probably create an alias mwhere * and the line after that is the respons to my where command
Top

Posted by Jedhi   (37 posts)  Bio
Date Reply #19 on Sat 01 Oct 2011 09:37 PM (UTC)

Amended on Sat 01 Oct 2011 10:50 PM (UTC) by Jedhi

Message
i found one solution, it's not bulletproof, but works inb most cases.

first i created alias mfw * with script content

print ("-- begin --")
Simulate ("-- mob search --")
Execute ("where %1")


firstline print is to get allways the new line. then i created a trigger: ^\-\- mob search \-\-\n(.+)[ \t]{2,}(.+)$


room = "%2"
cmd = string.format ("mapper area %s", room)
Execute (cmd)


now the not bulletproof issue. incase mobs name is so long, that there won't be more than 1 spaces between mob and room name, it will not work.

maybe someone has better solution? can i get the rooms name with aardwolf gmcp?
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #20 on Sun 02 Oct 2011 01:01 AM (UTC)
Message
I believe so, but I haven't used it for a while. Try asking Fiendish.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Jedhi   (37 posts)  Bio
Date Reply #21 on Tue 04 Oct 2011 10:24 PM (UTC)
Message
i started digging into aardwolf's gmcp plugin. with trial and error i managed to get the info into the room variable:


res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264", "gmcpval", "room.info")

luastmt = "room = " .. gmcparg
assert (loadstring (luastmt or "")) ()


can someone explain the code syntax for me? like why does the first line start with res, what does the 2nd and 3rd line do?

or some link to the info would help also.

thank you!
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #22 on Wed 05 Oct 2011 01:32 AM (UTC)

Amended on Wed 05 Oct 2011 02:53 AM (UTC) by Nick Gammon

Message
Well let's work through it. Logging in and typing the first line with a scripting prefix, nothing seems to happen:


/ res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264", "gmcpval", "room.info")


Now let's print the two values returned from CallPlugin:


/ print (res, gmcparg)


I get:


0 {
  coord = {
    y = "20",
    x = "30",
    cont = "0",
    id = "0",
    },
  num = "35233",
  exits = {
    e = "35235",
    w = "35234",
    s = "35229",
    n = "35308",
    },
  terrain = "afountain",
  details = "",
  name = "Academy Courtyard Fountain",
  zone = "academy",
  }


The zero means "this went OK", and the rest is the GMCP stuff as a text string.

Now if I do the second line:


/ luastmt = "room = " .. gmcparg


And print the resulting variable:


/ print (luastmt)


I get:


room = {
  coord = {
    y = "20",
    x = "30",
    cont = "0",
    id = "0",
    },
  num = "35233",
  exits = {
    e = "35235",
    w = "35234",
    s = "35229",
    n = "35308",
    },
  terrain = "afountain",
  details = "",
  name = "Academy Courtyard Fountain",
  zone = "academy",
  }


That looks like something that will define a table. So we now evaluate that:


/ assert (loadstring (luastmt or "")) ()


That should have turned that Lua text into a table. Let's check:


/ require "tprint"; tprint (room)


I get:


"coord":
  "y"="20"
  "x"="30"
  "cont"="0"
  "id"="0"
"num"="35233"
"exits":
  "n"="35308"
  "e"="35235"
  "s"="35229"
  "w"="35234"
"details"=""
"terrain"="afountain"
"name"="Academy Courtyard Fountain"
"zone"="academy"


So now, room.num is our room number, like this:


/ print (room.num)


Results:


35233


So in short, to get the room number you would do this:


res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264", "gmcpval", "room.info")
luastmt = "room = " .. gmcparg
assert (loadstring (luastmt or "")) ()
room_number = tonumber (room.num)


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Jedhi   (37 posts)  Bio
Date Reply #23 on Wed 16 Jan 2013 10:53 AM (UTC)
Message
where command response:


You are in area : The Grand City of Aylor
Area created by : Aardwolf
Level range is  : 1 to 201
Players near you:
Player_1                       Among the Philosophes
Player_2                       Among the Philosophes
Player_3                       In the Tower of Strength


how can i get player name and location into an array, where key was the player name and value the location. is it possible? there can be n+1 players in the area...
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #24 on Wed 16 Jan 2013 06:47 PM (UTC)
Message
Template:faq=37 Please read the MUSHclient FAQ - point 37.


For each line you would need a regular expression (or ordinary match text) along the lines of: * *

Where the first wildcard is the name and the second the rest of the line after the space.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Jedhi   (37 posts)  Bio
Date Reply #25 on Thu 17 Jan 2013 12:06 AM (UTC)

Amended on Thu 17 Jan 2013 02:23 PM (UTC) by Jedhi

Message
thanx!

now i'm having trouble with hyperlink. somehow following line is not clickable

Hyperlink ("say test", "this is a test", "you say test", "lightgreen", "black", 0)

i use it inside function
Top

Posted by Jedhi   (37 posts)  Bio
Date Reply #26 on Fri 18 Jan 2013 09:49 PM (UTC)
Message
is there a way to trigger a functon on plugin install and deinstall?
Top

Posted by Chyort   USA  (58 posts)  Bio
Date Reply #27 on Sat 19 Jan 2013 01:25 AM (UTC)
Message
straight out of the sample_plugin.xml

j) Use the OnPluginInstall callback routine to do any customising you might want when the plugin is first loaded (eg. setting up variables). You might also use this opportunity to move variables from MUSHclient variables to local variables.


Pulled from another plugin...

function OnPluginInstall()
blablabla


And searched off the site.
http://www.gammon.com.au/scripts/doc.php?general=plugin_callbacks
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.


76,494 views.

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

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

Go to topic:           Search the forum


[Go to top] top

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