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 ➜ VBscript ➜ Making an odd trigger/script combination.

Making an odd trigger/script combination.

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


Posted by Johnathan Allen   (49 posts)  Bio
Date Tue 19 Aug 2003 05:39 PM (UTC)
Message
Hi,

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.

Any help would be appreciated. :)
Top

Posted by Johnathan Allen   (49 posts)  Bio
Date Reply #1 on Tue 19 Aug 2003 05:59 PM (UTC)
Message
I'm using the following trigger:

^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.

Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #2 on Wed 20 Aug 2003 07:03 AM (UTC)
Message
I would do something like this:

Match:

^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



- Nick Gammon

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

Posted by Johnathan Allen   (49 posts)  Bio
Date Reply #3 on Wed 20 Aug 2003 07:49 AM (UTC)
Message
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:

reagents = split (arrWildCards (1), ", a" & ", and a", -1, 1)

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
", a"
.

Is there a better way to get rid of the 'and'?
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #4 on Wed 20 Aug 2003 07:57 AM (UTC)
Message
Check each one (or the last one if you want to be picky) and if it starts "and " just drop it.

- Nick Gammon

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

Posted by Johnathan Allen   (49 posts)  Bio
Date Reply #5 on Wed 20 Aug 2003 08:32 AM (UTC)
Message
I'm not sure how to check each one. It still only matches the first reagent no matter what I do to the split function arguments.
Top

Posted by Johnathan Allen   (49 posts)  Bio
Date Reply #6 on Wed 20 Aug 2003 09:31 AM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #7 on Wed 20 Aug 2003 08:39 PM (UTC)
Message
Are you splitting on just a comma? I don't see how you will get a comma in the last reagent if the split point is a comma.

I would split on a comma only, and then do this:

if left (r, 4) = "and " then
r = mid (r, 4)
end if


- Nick Gammon

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

Posted by Johnathan Allen   (49 posts)  Bio
Date Reply #8 on Wed 20 Aug 2003 10:18 PM (UTC)
Message
I tried that. Then I cobbled together this:

[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?
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #9 on Wed 20 Aug 2003 10:50 PM (UTC)

Amended on Wed 20 Aug 2003 10:51 PM (UTC) by Nick Gammon

Message
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 " &amp; r &amp; " 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.

- 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.


27,344 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.