Using script to practice/research skills

Posted by Brendolino on Wed 12 Dec 2007 01:29 AM — 7 posts, 31,109 views.

#0
I want to write a Lua script to take anything on my practice list under a certain percentage, and research it. I have triggers to keep the research continuing until it maxes, at which point I'll use the return message to view my prac list again. Here is a sample of the practice list:


construction   0%      data  15%     decrypt_file  86% 


there are more spaces between skills, but I had to knock some out to fit them in the messagebox. Basically, its a 3 wide mostly-right-justified list. Should I use variables and wildcards, or just hardcode every skill into the function? Examples would be excellent, I'm extremely novice at this.
Amended on Wed 12 Dec 2007 07:25 PM by Nick Gammon
USA #1
If you are just trying to make a trigger to pull out the data, you mostly just need something like this:

"%s*(w+(?:\s\w+)+)(%d+\%)(%s*(w+(?:\s\w+)+)(%d+\%)){0,2}"

Then just test the wildcards.. the odd ones will be the skill names, the even ones will be the rating of the skill preceding it. If the last few are nil, then you can just skip over them.

Somewhere in the forums, there is a good example of someone making up a set of values out of a large list of items grouped into three columns. It was for item trading, but it should work the same. Unfortunately, I can't seem to find it and I have to actually start work now. I'll check more on my lunch break.
#2
Alright, that was a bit too huge for me to diagnose myself,
but I created a trigger with that whole string as the <trigger:>, and a simple 'say %0' as the <send:> and nothing happened. I'm not sure if it makes a difference or not, but the message board's parsing changed my example. Here is a better, spelled out example.

<skill name><1 space><100%> <--the 1 space is dependant on the percentage in that skill. For a skill with 0%, it will be 3 spaces between the skill name and the first number of the percent: <skill name><3 spaces><0%>.

Now I'm absolutely new to Lua, and regexp, so I can't even begin to diagnose the problem with the regexp example you gave. I basically want to grab the first <skillname> for anything with a percentage of X% or less, anywhere on a line, and send a trigger to research it, or use a Lua script to send "research <skillname>".
Australia Forum Administrator #3
I amended your first post to put the [code] tag into it, to preserve spacing.

Regular expressions can be tricky to look at a complete example, but if you build them up yourself they can make more sense. See http://www.mushclient.com/regexp

In your case it sounds like you want a word with possibly underscores in it, so I would start with:


[A-Za-z_]+


That is, one or more of A-Z or underscore.

Then it sounds like you have at least one space, so let's add that:


[A-Za-z_]+\s


Then you have 3 digits or spaces (that is, leading spaces). So one approach would be:


[A-Za-z_]+\s[0-9 ]{3}


That looks for exactly 3 digits-or-spaces. Admittedly it would allow for imbedded spaces, but it is probably close enough.

Now add the percent:


[A-Za-z_]+\s[0-9 ]{3}\%


Now we need two groups (which are things in round brackets), one for the skill name and one for the percentage:


([A-Za-z_]+)\s([0-9 ]{3})\%


That gives us the first one. I don't know how many spaces between groups (it seemed to be 6), you can add that in, and a simple copy and paste would handle 3 of them in one line:


([A-Za-z_]+)\s([0-9 ]{3})\%\s{6}([A-Za-z_]+)\s([0-9 ]{3})\%\s{6}([A-Za-z_]+)\s([0-9 ]{3})\%


Put in ^ for start of line and $ for end of line and you are done:


^([A-Za-z_]+)\s([0-9 ]{3})\%\s{6}([A-Za-z_]+)\s([0-9 ]{3})\%\s{6}([A-Za-z_]+)\s([0-9 ]{3})\%$


In this example, %1 in the trigger is the first skill name, and %2 is the first percentage.

The finished trigger could look like this:


<triggers>
  <trigger
   enabled="y"
   match="^([A-Za-z_]+)\s([0-9 ]{3})\% {6}([A-Za-z_]+)\s([0-9 ]{3})\% {6}([A-Za-z_]+)\s([0-9 ]{3})\%$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

MIN_AMOUNT = 60

if %2 &lt; MIN_AMOUNT then
  Send ("research %1")
end -- if

if %4 &lt; MIN_AMOUNT then
  Send ("research %3")
end -- if

if %6 &lt; MIN_AMOUNT then
  Send ("research %5")
end -- if

</send>
  </trigger>
</triggers>


#4
Alright, in the event that the spaces between skills aren't necessarily 6, can I do: \s{[0-20 ]} instead of \s{6} ?


Anyhow, if examples are needed:

www.geocities.com/dalograk/example.html


That really gives the MUD away, though. >.>
Australia Forum Administrator #5
It would be \s{1,8} to be 1 to 8 spaces.
#6
Still not working for me. I'm probably jumping too far ahead of myself trying out a project like this before getting much regexp, or coding in general, experience. Thanks for the help, I'll just keep at it until I can figure it out.