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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Jscript ➜ Ok I am completely lost...

Ok I am completely lost...

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


Posted by Kelli   USA  (7 posts)  Bio
Date Tue 07 Mar 2006 07:54 AM (UTC)

Amended on Tue 07 Mar 2006 07:57 AM (UTC) by Kelli

Message
I have tried to figgure out how to do this script. I have seen it done for zmud but can not find one for mush. What I want is some thing to add the amount of gold I get in an hour then report it to me. my problem is getting the trigger variables to work. I really do not know scripting and the help file are not helping me. I am missing some piece of information that will not let it all click in to place. can any one tell me of a book or webiste that is good to learn scripting at? I hate to as any one to just do the script for me as I have alot that I want to do. here is the frist problem that I am coming up on.

I kill a mob and get (x) gold

save x to a variable (total)
save killed mob to (mtotal)

next mob kill I want to save x gold to (total)
save kill mob to (mtotal + 1)

(so on and on for an hour)

at the end of the hour send to the world a report of the
total gold
total mob
gold per mob average
reset total to 0
reset mtotal to 0


I know that it can not be all that hard but I just can not figure it out

I do understand how to make triggers and alise. both of them with and with out variables. I do not understand how to take the varible from the trigger to the script. I have read the GetTriggerVariable help file several time but it did not make sense to me...

where it say (thename, theoutput, thewildcards) is that what i actually put there? or is it some thing eles and if so how do I detrime what it will be?

after all that I know i will have to learn how the timer function works to complete this but I would like to get this adding to begin with. I figure one step at a time


Please any help would be appercated. I am not looking for some on to do it for me just to help me understand.

Kelly
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 07 Mar 2006 06:54 PM (UTC)
Message
Have you read this?

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6030


It gives detailed descriptions about using scripting, including getting numbers from triggers, and a discussion about variables.

- Nick Gammon

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

Posted by Kelli   USA  (7 posts)  Bio
Date Reply #2 on Fri 10 Mar 2006 02:50 AM (UTC)
Message
ok nick thank you for that other page it has help me to understand this a lot better but i am still doing some thing wrong. If any on can help I thank you. here is the error that mush gives me and the script as i have it now


Error number: -2146827278
Event: Execution of line 963 column 23
Description: Expected identifier
Line in error:
function gold ( test, ^You get (?p<cgold>.*?) gold coins from the perforated corpse of a (.*?)\.$, cgold) {
Called by: Immediate execution



function gold (test, ^You get (?p<cgold>.*?) gold coins from the perforated corpse of a (.*?)\.$, cgold) {
var ngold;
ngold = parseInt(world.GetVariable( "tgold" )) + parseInt(cgold);
world.SetVariable ("cgold", ngold);
}


tgold is setup and defined as 0 to start with and I have the trigger to call the script set as

^You get (?p<cgold>.*?) gold coins from the perforated corpse of a (.*?)\.$

well that is every thing. not sure how i messed up other then trying to attemped something i have no clue on what i am doing still.
Thanks for all the help
Top

Posted by Tsunami   USA  (204 posts)  Bio
Date Reply #3 on Fri 10 Mar 2006 04:17 AM (UTC)
Message
Um did you literally put ^You get (?p<cgold>.*?) gold coins from the perforated corpse of a (.*?)\.$ in the function header? that should be simply a variable.

function gold (test, line, cgold)

also note that cgold is an array which must be accessed not a single variable. cgold[1] should do it.
Top

Posted by Kelli   USA  (7 posts)  Bio
Date Reply #4 on Fri 10 Mar 2006 02:33 PM (UTC)
Message
ok so let me see if I am understanding this... in the header (which i am assuming is the line begining with function) I just need it in

function gold (test, line, cgold[1]) {

is that correct? I though I had to put the entire matching like that called the script in order to use the variable. in this case the amount of gold i got for killing a mob.


and every time i have cgold in the scipt it should be cgold[1] right?

I will try those changes and post the results. thank you for the help..
kelli
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #5 on Sat 11 Mar 2006 04:36 AM (UTC)

Amended on Sat 11 Mar 2006 04:37 AM (UTC) by Nick Gammon

Message
You seem to be confusing the trigger (which matches the text) with the function it calls.

I know you have posted in the Jscript section, but judging by your code you are not heavily committed to using JScript.

Things can be easier in Lua, which is now the recommended script language in MUSHclient.

Here is how you might do your example in Lua. The whole thing can be done in "send to script" without needing a separate script file:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="^You get (?P&lt;gold&gt;\d+) gold coins from the perforated corpse of a (?P&lt;mob&gt;.+)\.$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
mobs = mobs or {}  -- make mobs table if it doesn't exist

gold = %&lt;gold&gt;  -- gold from wildcard
mob = "%&lt;mob&gt;"  -- mob name from wildcard

total = (total or 0) + gold   -- count total gold
mobs [mob] = (mobs [mob] or 0) + gold  -- count gold from mob

-- show totals

ColourNote ("white", "blue", "Total gold so far = " .. total)
ColourNote ("white", "blue", "Total gold from " .. mob .. " = " .. mobs [mob])
</send>
  </trigger>
</triggers>




Example output:


You get 15 gold coins from the perforated corpse of a bear.
Total gold so far = 15
Total gold from bear = 15

You get 15 gold coins from the perforated corpse of a kobold.
Total gold so far = 30
Total gold from kobold = 15


The script uses a trigger to match on the message you receive, and in the script adds to a total amount, and also uses the Lua table concept to count totals per mob.

- Nick Gammon

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


21,512 views.

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.