Newbie question

Posted by Jedhi on Thu 22 Sep 2011 05:20 PM — 28 posts, 110,584 views.

#0
Hello,

i have tried everything to make a lua script work with simple one line trigger without any success. can someone please give me an example what i must exectly type into myscript.lua to match "this is a line" and send to the world "say this is a test"

Thank you!
#1
why not just give us an example of what your trying to catch. will make it easier for us to help.
are you trying to match chats, hp, targets, mobs.
bob says...
#2
I'm just trying to get myself started with this scripting thing. just match the line i gave. really doesn't matter cause i can't match anything with scripting
USA #3

<triggers>

<trigger
 match="this is a line"
 enabled="y"
 regexp="n"
 send_to="12"
 sequence="100"
>
<send>
Send("say this is a test")
</send>
</trigger>

</triggers>


That's your fairly basic TRIGGER trigger. If you wanted to match a line within a script, you could always do something like string.find(), string.match(), string.sub(), etc.

One such script that I just wrote is as follows:


location = "rep12089176"
items = {
  id = "12098735",
  name = "Item Name"
}
if string.match(location,"rep",1) ~= nil then
  Note("Received container contents!!")
  Note("Container number: " .. string.sub(location,4))
  for k, v in pairs(items) do
    Note(v)
  end -- for
end -- if


The string.match(location,"rep",1) returns a numerical position of the first occurrence of the search string "rep" if it exists anywhere in the "location" variable.

The string.sub(location,4) returns the substring in the "location" variable from position 4 onward -> "12089176".

So you COULD do something like string.sub(location,string.match(location,"rep",1))

So in plain English, location is a string variable. Items is a table with two string variables.

If location has the word "rep" anywhere within it, then print the string from the position where "rep" ends onward to the end. Then for every variable in the items table, print the value of it. But only do this if "rep" exists in the location string.
Amended on Thu 22 Sep 2011 06:13 PM by Daniel P
Australia Forum Administrator #4
Jedhi said:

Hello,

i have tried everything to make a lua script work with simple one line trigger without any success. can someone please give me an example what i must exectly type into myscript.lua to match "this is a line" and send to the world "say this is a test"

Thank you!


You don't need to use myscript.lua at all initially. Just script directly inside triggers as Daniel illustrated.

However if you want to go the trigger/script file route, please paste both your trigger, and your script file.

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.
#5
Thank you!
Is it possible to chech inside a trigger the room i'm in and then dicide which action to take?
#6
I have tried to figure this mush+lua out.

can someone please point me to right tutorials or something. like where can i find <trigger> <alias> detailid description?

like what do the trigger variables send_to="12" sequence="100" stand for? how can i use custom functions with triggers, how to interact with the mud(aard). for example how to get the rooms id and so on...

like what's the difference between <alias> and AddAlias

AddAlias("test_aliases", "my_test", "gt this is a test", alias_flag.Enabled, "")

is it possible to use user function as a return value?

i hava so many questions.
Amended on Fri 23 Sep 2011 07:32 PM by Jedhi
Australia Forum Administrator #7
Look at my "getting started" videos:

http://www.gammon.com.au/forum/?id=10212

And others from that part of the forum.
Australia Forum Administrator #8
Jedhi said:

like what do the trigger variables send_to="12" sequence="100" stand for? how can i use custom functions with triggers, how to interact with the mud(aard). for example how to get the rooms id and so on...



A lot of that is documented here:

http://www.gammon.com.au/forum/?id=7123

However in most cases you just use the GUI interface to create triggers and aliases, and it will put the correct things in there for you.
#9
thanx again.

i'm trying to create an alias for portals, in mushclient alias settings, which takes the portal out of bag, wears it and then enters.


dest = (%1)
portals = {}

portals['knossos'] = '288375488'

cmd = string.format('get %s bag', portals[dest])

Execute (cmd)


it doesn't work. seems i can't get the value of array. alias name is: prt *
syntax: prt knossos

where i went wrong with this?
USA #10
Use "%1" instead of (%1). The expansion syntax - %1 and @foo - isn't part of Lua, it's something MUSHclient does for you before the script is run. So when it sees %1, it just replaces it directly in the script with its value.

When Lua gets what you have now, it sees dest = (knossos), which doesn't mean what you want. It sees knossos as a variable name, and tries to find what value it has. Of course, there is no knossos variable, so dest just gets nil.

If you use "%1", Lua sees dest = "knossos". Lua knows "knossos" is a string, so dest gets that value.
Amended on Tue 27 Sep 2011 05:29 PM by Twisol
#11

dest = %1
portals = {}

portals['knossos'] = '288375488'

portal = portals[dest]

cmd = string.format('get %s bag', portal)

Execute (cmd)


i still get the error. value for portal is nil
#12
btw this (%1) is working in another alias!


lvl = (%1)
gear = {}
gear[41] = {284550683,284554076,284553104,284550901,284554217,284550117,284548701,231001032,58189977,284555249,253689542,284551389,284552750,284552936,284551681}
gear[61] = {284931904,284931530,284922537,284929035,284930297,284922748}
eqset = gear[lvl]

if eqset then
  j = table.getn(eqset)
  for i=1, j do
    s = string.format("get %s 272661297;wear %s", eqset,eqset)
    Execute (s)
  end
else
  print ("ERROR: Gear set not found")
end
USA #13
You didn't add the quotes. You went from (%1) to %1 - you need "%1".

It works in the other one because, as far as I can tell, you expect %1 to contain a number. (42) is valid Lua code - it understands 42 to be a numeric literal value. But (foobar), which would be the case in your original code, is interpreted as a variable access, not a literal string value like "foobar".
#14
got it. if anyone interested, this is how working version looks like:


portals = {}

portals["knossos"] = "288375488"
prt = portals["%1"]

cmd = string.format("get %s bag;wear %s;enter;dual dagger;put %s bag", prt, prt, prt)

Execute (cmd)
#15
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?
Amended on Thu 29 Sep 2011 11:46 AM by Jedhi
#16
anyone?
Australia Forum Administrator #17
Can you post actual example output?

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

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
#19
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?
Amended on Sat 01 Oct 2011 10:50 PM by Jedhi
Australia Forum Administrator #20
I believe so, but I haven't used it for a while. Try asking Fiendish.
#21
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!
Australia Forum Administrator #22
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)

Amended on Wed 05 Oct 2011 02:53 AM by Nick Gammon
#23
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...
Australia Forum Administrator #24
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.
#25
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
Amended on Thu 17 Jan 2013 02:23 PM by Jedhi
#26
is there a way to trigger a functon on plugin install and deinstall?
USA #27
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