To do what you're asking it's going to take a few steps.
First, you'll need a script file. If you don't have one yet, create a file with the .lua extension in your main MUSHclient folder. myscripts.lua, for example. Open that in a text editor so you can edit it. If you want to keep track of the level/rank of each skill then you'll need a variable to store the value of each. A table can be used to keep related variables in the same place. In this case, we'll name it skill_ranks, note the underscore connecting the words, and create the table.
The next step is the trigger. Assuming the names of all of your skills are only one word, you can create a new trigger in the config window and paste that message into the white Trigger box at the top. Next click the "Convert to Regular Expression" button just below it. This will allow you to make a more complex trigger. Then delete the word parry and replace it with (\w+). It will make the trigger match any word in that spot where parry was and store it in a temporary variable called a wildcard. You'll also need to replace those two (.*?) with \*. You're escaping the asterisk with the backslash, which tells the trigger that there is literally an asterisk in those places in the text and the asterisk shouldn't be seen as a special character. You should end up with this in the Trigger box:
^\*You think your (\w+) skill has improved\. \*$
If that space after the period is a typo then just delete it.
In the Send box of the trigger type
skill_ranks["%1"] = skill_ranks["%1"] + 1 or 1
Some people would recommend putting that inside of an if statement to make sure it's not empty or that it exists before doing math on it, but personally I would just have the trigger disabled until everything is finished, manually assign initial values to make sure the variables have them, and then enable it. You shouldn't have to worry about that unless you're doing something to increase your skill level while you're working on it, though. Everything surrounded by parentheses in the Trigger box will be stored in a wildcard beginning at 1. You can reference that wildcard using %1 and if it's a string you use "%1". %0 exists but it represents the entire line of text that was matched. In your case, the text you provided would cause %1 to be parry, which would make the code in the Send box the same as
skill_ranks["parry"] = skill_ranks["parry"] + 1 or 1
The "or 1" at the end is in case the variable isn't storing a number for some reason, causing the math to fail. It will assign the 1 to it as a fail safe, and you can correct it manually later.
Click on the Send to box and select Script to make the client send the text in the Send box to the script engine and not directly to the game you're playing.
You can optionally change the color of the text to make it easier to see when a skill has leveled up or simply to make sure the trigger is working. If it isn't, then the text won't be the color you selected. Click OK to save the trigger.
To save these values between sessions you'll need to use client variables, as opposed to the Lua variables we've been using up till now. You'll need a list of the names of all the skills that can be in that message where parry is.
In your script file, make a function where you'll tell the client to store the values in client variables when you disconnect from the MUD, like so:
function Disconnected()
SetVariable("parry_rank", skill_ranks.parry)
end
just add another SetVariable to the function for every skill that you want to keep track of.
Make another function that retrieves the level of each skill from the client variables when you connect and puts them into the Lua variables
function Connected()
skill_ranks.parry = tonumber(GetVariable("parry_rank"))
end
This gets the value stored in the parry_rank client variable and stores it in the parry key of the skill_ranks table where Lua can access it. Since client variables are stored as strings in MUSHclient, you need to use tonumber to convert the value of parry_rank into a number before assigning it to skill_ranks.parry, because you're going to do math on it later, i.e. adding 1 to it whenever the skill levels up.
Now open the World Configuration dialog, Alt+Enter by default, expand Scripting and click on the Scripts tab.in the Connected box type Connected, and in the Disconnect box type Disconnected. That should complete the data storage and retrieval part of it.
A simple way to make sure everything is working is to iterate over the skill_ranks table and print all of the keys and values. Put the code below in the Send box of an alias and in the Alias box, name it something like printskills, or whatever you want to type to see the levels of your skills. Don't forget to change the Send to drop-down box to Script and click OK.
for key, value in pairs(skill_ranks) do
print(key, value)
end
Since the key holding each value is the name of the skill you'll know which number goes to each skill.
I recommend adding one skill to those two functions at a time, then manually set the initial value of that skill before adding the next, until you get more practice with coding. so if your level in parry is currently 4, you would make the functions as shown above, and then in the command window where you type commands for the MUD type
So the next time your trigger matches that text for the parry skill it will add 1 to it and correctly be 5 total.
Creating a miniwindow to display that information is a bit more involved, so make sure at least this much is working before moving on to that. |