Help - Search - Members - Calendar
Full Version: Coding My First Mush Script
Achaea's Forums > Off-Topic > Tech Support > Curing Systems and Scripts
Serethi
I would like to make an enemy watch script, but have no real understanding of mushclient coding. Serethi is an Apostate and the main reason for this script is to echo the herbs a targetted opponent eats. Which brings up two questions.

1. How do i tell a group of triggers to respond to my target?

2. How do i gag and change the text of my targetted opponent to custom text?

Any input at all is appreciated





Soludra
1) Join the MUSHclient clan. CLHELP MUSH

2) Join the MUSHclient clan. CLHELP MUSH


But really. 1 I'm not really sure I get. 2, just match the line, don't do anything in particular, and select a new color from the dropdown on the bottom-right quarter of the dialog.
Serethi
I am a member of the clan but i cannot connect to achaea at my college so i'm limited to using the forums for help.

What i meant for 1. was that i want the script only to alert me if my current target eats herbs or uses any salve to prevent any confusion when fighting in a room with multiple people.

Soludra
Ah. If the current target is in a MUSHclient variable (set with SetVariable() or by using the Variables dialog), you can use @targvariable directly in the match line. Just be sure to check the "Expand variables" box on the right, which allows that @-syntax.

Assuming the variable is named 'target', this would be the match line:
CODE
@target takes a drink from an ebony vial.


EDIT: Also assuming it's an ebony vial, but I'm sure you get that.
Serethi
Thats much simpler than what i would have thought. How would i go about changing the text into my own words?
Irion
QUOTE (Serethi @ Oct 18 2009, 08:38 PM) *
Thats much simpler than what i would have thought. How would i go about changing the text into my own words?


I'm assuming you mean something other than just a highlighted line?

To do that you just check the "omit from output" flag and that gags the line. Then in the send box you can use the Note("whatever"), or ColourNote("textcolor", "backgroundcolor", "message") function to echo messages to yourself. Make sure you have the send 'to script" option selected on the drop down menu.

You could also write a short lua script to do this for you, so like

enemyw {
alert = function(a)
Note("******* ",GetVariable("target"), " has ", a, "********")
Note("******* ",GetVariable("target"), " has ", a, "********")
Note("******* ",GetVariable("target"), " has ", a, "********")
end
}

so you would paste this into the script file and use enemyw.alert("whatever it is your enemy did") in your send box to do the same thing as above with less repetitive typing.

The first option is easier in the short run.

It is also possible to send messages to a miniwindow, however I do not know how to do this as I have never tried.
Serethi
enemyw {
alert = function(a)
Note("******* ",GetVariable("target"), " has ", a, "********")
Note("******* ",GetVariable("target"), " has ", a, "********")
Note("******* ",GetVariable("target"), " has ", a, "********")
end
}

enemyw.alert("@target eats a bloodroot leaf")

Note (" Enemy Watch: @target eating BLOODROOT!")



Is that what it should look like?

Can you break down how the script works in laymens terms? I think i understand the formula but not how it works.
Irion
Ok... my last post probably wasn't that clear. Sorry.

There are two ways to do this. Either you can just put your script commands in the send box in the trigger or you can make a script that contains those commands in a function that you can 'call' from the send box.

For the first way you would just use the Note or ColourNote functions.
To use these functions simply put:

Note("Whateveryouwanttosay") or ColourNote("textcolor", "backgroundcolor", "whateveryouwanttosay")

Into the send box of the function and select the "script" option from the "send" drop down menu.

For example:
CODE
Note("Someone just snapped you!!!!")
Note("THEFT!!!!!!THEFT!!!!!!THEFT!!!!!")

This would show:
CODE
Someone just snapped you!!!!
THEFT!!!!!!THEFT!!!!!!THEFT!!!!!

or something to that effect.

If you want to include a variable value in your Note() or ColourNote() functions than just use the GetVariable("varname") function.
For example:

Note(GetVariable("target"), " just attacked you!!")

This would show:
Irion just attacked you!!

this is the second way
The scripting thing is making a shortcut function that you can call (which is to say used) from any trigger or alias.

CODE
enemyw {
alert = function(a)
Note("******* ",GetVariable("target"), " has ", a, "********")
Note("******* ",GetVariable("target"), " has ", a, "********")
Note("******* ",GetVariable("target"), " has ", a, "********")
end
}


this goes in the script file, you can see where your script file is by doing SHIFT + CTRL + 6

then create a new script file. it should open in the mush editor. paste in the above uh...Group of vars and functions? What is this called in lua anyway Soludra? Or is it just a block of script for purposes of organization and encapsulation?

Explanation of the above: (important terms in bold)

Alert is the name of the function. This is what you call when you want the function to run.
You call this function by sending enemyw.alert("enemyname") to script.
The part with the enemyname inserted is called the functions arguments.

Anyway you can now access the function alert by typing:
CODE
enemyw.alert(%1)


This should give the output:
CODE
******* Irion has sipped health ********
******* Irion has sipped health ********
******* Irion has sipped health ********


Into the send box of the trigger. and selecting the send to script option.
This will cause the trigger to access the script file and substituted whatever you put in for the arguments to wherever the 'a' is located into the function. This 'a' is a local variable and has no power outside of its function. For example, you couldn't access 'a' from a trigger, it has no stored value except while the function is being run.

Does that answer your question?

Also, note that the two methods are substitutes for each other, so you can do whichever you want. Just the second way has less typing for every trigger you want to make.
Soludra
May be worth noting that, for the first way, you can use the @variablename syntax instead of GetVariable("variablename") if you have Expand Variables checked. But otherwise, stellar post.

EDIT: @Irion, it's called a table. Strictly speaking, you didn't even need to put it in a table.

EDIT 2: Also, quote the %1 when you're calling the function.

CODE
enemyw.alert("%1")


EDIT 3 (lol): With the table, you need to put an '=' sign after the name and before the opening brace. You're creating a table {} and assigning it to a variable.

CODE
enemyw = {
  -- stuff goes here
}
Serethi
Thats everything I needed. Thank you both
Penquin
Same thing, maybe a little differently


CODE
Match:
^(!@target) takes a drink from (an|an) (\w+) vial\.$

Regexp: yes
Expand Variables: yes
Send to : Script



CODE
ColourTell('blue','black','<%1>:')
ColourNote('white','black',' took a sip from a vial!')


That would match on only the value of the 'target' variable matching in the line, along with sipping from any vial.

And would look sorta like:
QUOTE
Rakon takes a sip from an ebony vial.
<Rakon>: took a sip from a vial!


Also, looking over the MUSHClient script functions list and in particular ColourNote pages, might help.
Trevize
QUOTE (Penquin @ Oct 19 2009, 02:39 PM) *
CODE
^(!@target) takes a drink from (an|an) (\w+) vial\.$


What is !@target for? As far as I know, you only need @target. Similar, but not necessary, is @!target which is used for vertical bar-delimited string lists.

Also, I think you mean (a|an) not (an|an). Also, simpler, you could use an? instead.
Penquin
QUOTE (Trevize @ Oct 20 2009, 08:31 AM) *
QUOTE (Penquin @ Oct 19 2009, 02:39 PM) *
CODE
^(!@target) takes a drink from (an|an) (\w+) vial\.$


What is !@target for? As far as I know, you only need @target. Similar, but not necessary, is @!target which is used for vertical bar-delimited string lists.

Also, I think you mean (a|an) not (an|an). Also, simpler, you could use an? instead.


Of course you are right in all regards to the above quoted post.
I was trying to write that post off the top of my head.

It's been more than a little while since I've tried making stuff for MUSH tongue.gif
Serethi
I've run into a few problems with the script.

enemyw = {
alert = function(a)
Note("******* ",GetVariable("target"), " has ", a, "********")
Note("******* ",GetVariable("target"), " has ", a, "********")
Note("******* ",GetVariable("target"), " has ", a, "********")
end,
}

<aliases>
<alias
match="t *"
enabled="y"
send_to="12"
sequence="100"
>
<send>SetVariable ("target", "%1")
Note ("Changed Target To: %1!")
</send>
</alias>
</aliases>

<triggers>
<trigger
expand_variables="y"
group="Enemy.W"
match="^@target eats a bloodroot leaf\.$"
regexp="y"
send_to="12"
sequence="100"
>
<send>enemyw.alert("%1")</send>
</trigger>
<trigger
expand_variables="y"
group="Enemy.W"
match="^@target eats a goldenseal root\.$"
regexp="y"
send_to="12"
sequence="100"
>
<send>enemyw.alert("%1")</send>
</trigger>
<trigger
expand_variables="y"
group="Enemy.W"
match="^@target eats a lobelia seed\.$"
regexp="y"
send_to="12"
sequence="100"
>
<send>enemyw.alert("%1")</send>
</trigger>
<trigger
expand_variables="y"
group="Enemy.W"
match="^@target eats a piece of kelp\.$"
regexp="y"
send_to="12"
sequence="100"
>
<send>enemyw.alert("%1")</send>
</trigger>
<trigger
expand_variables="y"
group="Enemy.W"
match="^@target eats some prickly ash bark\.$"
regexp="y"
send_to="12"
sequence="100"
>
<send>enemyw.alert("%1")</send>
</trigger>
<trigger
expand_variables="y"
group="Enemy.W"
match="^@target takes a long drag off (his|her) .+? pipe\.$"
regexp="y"
send_to="12"
sequence="100"
>
<send>enemyw.alert("%1")</send>
</trigger>
<trigger
expand_variables="y"
group="Enemy.W"
match="^@target takes some salve from a vial and rubs it on (his|her) (arms|legs)."
regexp="y"
send_to="12"
sequence="100"
>
<send>enemyw.alert("%1")</send>
</trigger>
</triggers>


These are all the triggers involved with the script so far.

While i have the script enabled i get an error message saying script is not enabled every time balance is used. ( i cant login to mush from here so i dont know the exact message)

Does anyone know how to fix this problem?
Irion
Basically you have no %1 for the script to send to the function. You can either have one trigger for eating that would be like:

^@target eat (a|some) (.+)\.$

(I'm not sure in the %1 is right. You might need to use %2.)

OR:

You could just have the same triggers you have now and actually type in the message. So:

enemyw.alert("eaten bloodroot")

Serethi
I've run into some new problems.

I get this error whenever i enable scripting.

Compile error
World: Achaea (vadi)
Immediate execution
[string "Script file"]:7: unexpected symbol near 'char(30)'
Error context in script:
3 : Note("******* ",GetVariable("target"), " has ", a, "********")
4 : Note("******* ",GetVariable("target"), " has ", a, "********")
5 : Note("******* ",GetVariable("target"), " has ", a, "********")
6 : end,
7*: }


I get this error when i try to target or regain either balance or equilibrium. I get these errors regardless of whether scripting is enabled or not.

Send-to-script cannot execute because scripting is not enabled.

<aliases>
<alias
match="t *"
enabled="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>SetVariable ("target", "%1")
Note ("Changed Target To: %1!")
</send>
</alias>
</aliases>

<triggers>
<trigger
enabled="y"
match="^You have recovered balance on all limbs\.$"
omit_from_output="y"
regexp="y"
send_to="14"
sequence="100"
>
<send>ColourNote("blue","yellow","((---((-(-(!!!!BACK ON BALANCE!!!!)-)-))---))")</send>
</trigger>
<trigger
enabled="y"
match="^You have recovered equilibrium\.$"
omit_from_output="y"
regexp="y"
send_to="14"
sequence="100"
>
<send>ColourNote("black","green","((---((-(-(!!!!EQUILIBRIUM!!!!)-)-))---))")</send>
</trigger>
</triggers>


Does anyone see what i'm doing wrong?
Dontarion
That looks like Lua. You can't do a, "aaa", b, "bbb" it should be
b = "you"
c = "for"
Note("This is how " .. b .. " concatenate in Lua " .. c .. " cool stuff.")
Output: This is how you concatenate in Lua for cool stuff.
Soludra
No, Note() accepts any number of arguments and concatenates them together. See the error - it says there's a char(30) there. In ASCII, that's RS or Record Separator, a nonprintable character (basically inivisible).

Serethi, delete the 'end,' and '}' lines, then re-type those. Hopefully you'll have removed the RS character and not accidentally added it back in.
Serethi
Thank you!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.