I'm trying to make a trigger/script combo to track the used reagents in the mud I play. I've already worked something out to reliably count the reagents I have in my containers, and I'm trying to puzzle out how to make something that counts the reagents I use when I cast a spell. The problems I'm running into are as follows:
There are six basic reagents I use, Earth, Air, Water, Fire, Ethereal, and Gemstones. Each has its own unique text string to describe itself, such as "a mandrake leaf" for Earth, and "a pinch of sulfur" for fire, etc. Now, when I cast a spell successfully. I get a string like:
A mandrake leaf, and a feather from a roc flare brightly and vanish!
Some of the higher powered spells use more reagents, and sometimes, multiple reagents of the same type, as in this:
A sunstone, a mandrake leaf, a mandrake leaf, a mandrake leaf, and a feather from a roc flare brightly and vanish!
Also, there is no pre-defined order to what reagents are listed first, second, etc., so the above strings can be displayed in every permutation possible.
So, my problem is twofold; I need to count each different type of reagent used in the spell casting, and sometimes, multiples of the same type. I already have variables storing how many I have of each type of reagent from a script I made to count them, but I'm not sure how to subtract from those counts.
^A (silver runestone|sunstone|mandrake leaf|shimmering white fish scale|pinch of sulfur|feather from a roc) (flare|flares) brightly and (vanish|vanishes)\!$
Its labelled "ReagentUse", part of group "ReagentInventory" and the script of the same name. Regular Expression is checked.
It only matches a single reagent spell.
Here's the code snippet:
If strTriggerName = "ReagentUse" Then
If arrWildCards (1) = "silver runestone" then
Gemstone = Gemstone - 1
End If
If arrWildCards (1) = "sunstone" then
Ethereal = Ethereal - 1
End If
If arrWildCards (1) = "mandrake leaf" then
Earth = Earth - 1
End If
If arrWildCards (1) = "feather from a roc" then
Air = Air - 1
End If
If arrWildCards (1) = "shimmering white fish scale" then
Water = Water - 1
End If
If arrWildCards (1) = "pinch of sulfur" then
Fire = Fire - 1
End If
End If
I know thats not a good way to code it, but I'm really not that good with coding.
^A (.*) (flare|flares) brightly and (vanish|vanishes)\!$
Then use "split" to split up the reagents, like this:
dim reagents
reagents = split (wildcards (1), ",", -1, 1)
for each r in reagents
'
' prcess reagent "r"
'
' e.g.
'
if r = "a mandrake leaf" then
' blah
end if
next
That seems to work somewhat better. It picks up the first reagent used in the string, but disreguards all following strings. I tried fiddling with the split function a bit, like this:
but it doesn't seem to get rid of that pesky 'and' thats before the last reagent. I don't know why its not accounting for the second reagent, it should with the first delimiter
Well, I got it to work up to the second to last and last reagent. I inserted a "world.note r" to display each of the items in the array, and the last one is always of the following nature:
(reagent), and a (reagent)
I still havent gotten how to parse that last ', and a' yet.
[code]
If strTriggerName = "ReagentUse" Then
dim reagents, i, e, r, q, Final_Reagent, reagent
i = 0
reagents = split (arrWildCards (1), ", a ", -1, 1)
for each r in reagents
ReagentProcessing (reagents)
q = UBound(reagents)
If i = q then
Final_Reagent = split (reagents(q), ", and a ", -1, 1)
for each e in Final_Reagent
world.note e 'tells me if the split happened by displaying the final two reagents as seperate strings
ReagentProcessing (Final_Reagent)
next
end if
i = i + 1
next
End If
[/code]
And the function:
[code]
Function ReagentProcessing (reagent)
world.note "Test debug: " & reagent
If reagent = "mandrake leaf" Then
Earth = Earth - 1
World.Note "Earth"
End If
If reagent = "feather from a roc" Then
Air = Air - 1
World.Note "air"
End If
If reagent = "silver runestone" Then
Gemstone = Gemstone - 1
World.Note "gem"
End If
If reagent = "sunstone" Then
Ethereal = Ethereal - 1
World.Note "eth"
End If
If reagent = "pinch of sulfur" Then
Fire = Fire - 1
World.Note "fire"
End If
If reagent = "shimmering white fish scale" Then
Water = Water - 1
World.Note "Water"
End If
End Function
[/code]
It should be porting each iteration to the function, but it doesnt. The second split does seem to work. Am I doing something wrong with calling a function?
Far too complicated. You don't need multiple split statements, just one to split at the comma. Then deal with the extra "and" or "a". You can do the whole thing in a single trigger. Here is my suggestion ...
Just copy between the lines and paste into the trigger configuration screen.
<triggers>
<trigger
custom_colour="2"
enabled="y"
match="^(.*) (flare|flares) brightly and (vanish|vanishes)\!$"
regexp="y"
send_to="12"
sequence="100"
>
<send>dim reagents
reagents = split ("%1", ",", -1, 1)
for each r in reagents
'
' prcess reagent "r"
'
r = lcase (trim (r))
if left (r, 4) = "and " then r = trim (mid (r, 4))
select case r
case "a mandrake leaf"
SetVariable "earth", CInt (GetVariable ("earth")) - 1
case "a pinch of sulfur"
SetVariable "fire", CInt (GetVariable ("fire")) - 1
case "a feather from a roc"
SetVariable "air", CInt (GetVariable ("air")) - 1
case "a silver runestone"
SetVariable "gem", CInt (GetVariable ("gem")) - 1
case "a sunstone"
SetVariable "ethereal", CInt (GetVariable ("ethereal")) - 1
case "a shimmering white fish scale"
SetVariable "water", CInt (GetVariable ("water")) - 1
case else
Note "Reagent " & r & " not known."
end select
next
</send>
</trigger>
</triggers>
This will set the appropriate MUSHclient variable (check the values in the variables configuration tab). Then you could write an alias to display them, or have some other method to notify you of their current values.