Sigh. I've been too lazy to do my own scripting, but I can't allow this madness to continue, so I'll come out of my semi-retirement to offer my viewpoint:
:)
Now, it doesn't seem like there is a need to remember the state of afflictions between MUSHclient sessions. I'm betting you won't be quitting the mud while you are afflicted with something. Given that, you don't need to use MUSHclient variables. Regular script variables should safice. I would build an array of all the afflictions, doing so as mainline code, outside any subroutines:
(In Visual Basic Scripting)
Dim BodyState(6,2)
BodyState(1,1) = "asthma"
BodyState(2,1) = "despair"
BodyState(3,1) = "gangreen"
BodyState(4,1) = "arthritis"
BodyState(5,1) = "stupidity"
BodyState(6,1) = "delusional"
The order of afflictions in the array indicates their priority, so if one affliction needs to be cured before another, then that first affliction should be above the second in the list.
Now, a subroutine to reset all Afflictions to cured:
Sub BodyState_Reset (AliasName, AliasLine, arrWildcards)
Dim x
For x = LBound(BodyState) to UBound(BodyState)
BodyState(x,2) = vbFalse
Next
World.Note "Afflictions reset."
End Sub
You can create an alias to call that subroutine, in case you are having some problems and just want to reset everything. You must call the routine once from the script when you first load the world, so put the following line in your mainline script, outside any subroutines (I would put it right under where I set up the array):
Call BodyState_Reset "Mainline", Empty, Empty
Now, the subroutines to call when you are inflicted and cured of afflictions. For afflictions, start all your trigger labels with "BA_" followed by the name of the affliction. (BA for Body Afflicted). For cures, start all your trigger labels with "BC_" followed by the name of the affliction. (BC for Body Cured):
Sub Body_Afflicted (TriggerName, TriggerLine, arrWildcards)
Dim x
TriggerName = World.Replace(TriggerName, "BA_", "", True)
For x = LBound(BodyState) to UBound(BodyState)
If BodyState(x,1) = TriggerName Then
BodyState(x,2) = vbTrue
World.Note BodyState(x,1) & ": Afflicted"
End If
Next
End Sub
It's important that you label your triggers correctly. Examples might be:
Trigger:why you ask does the world act so unfairly towards you
Label:BA_despair
Script:Body_Afflicted
Trigger:your breath becomes rasping
Label:BA_asthma
Script:Body_Afflicted
On to curing. First, the subroutine to call when you trigger that you have been cured:
Sub Body_Cured (TriggerName, TriggerLine, arrWildcards)
Dim x
TriggerName = World.Replace(TriggerName, "BC_", "", True)
For x = LBound(BodyState) to UBound(BodyState)
If BodyState(x,1) = TriggerName Then
BodyState(x,2) = vbFalse
World.Note BodyState(x,1) & ": Cured"
End If
Next
End Sub
It's important that you label your triggers correctly. An Example might be:
Trigger:you are cured of despair
Label: BC_despair
Script: Body_Cured
Now, all the monitoring is done, just to write the actual script to perform the required service:
Sub Body_Heal_Affliction (AliasName, AliasLine, arrWildcards)
Dim x
Dim SubtoCall
For x = LBound(BodyState) to UBound(BodyState)
If BodyState(x,2) Then
SubtoCall = "call Cure_" & BodyState(x,1) & " " & Chr(34) & "Body_Heal_Affliction" & Chr(34) & ", Empty, Empty"
ExecuteGlobal SubtoCall
Exit For
End If
Next
End Sub
Setting up the 'SubtoCall' is a bit complicated, but it allows for more flexibility. The last step is to create a subroutine for each affliction, which sends to the mud whatever you need to do to cure that particular affliction. For example:
Sub Cure_despair (AliasName, AliasLine, arrWildcards)
World.Note "Attempting to cure: despair"
World.LogSend "cast cure despair"
End Sub
The name of these subroutines is VERY important, since they are called by the routine "Body_Heal_Affliction". (Make sure each one starts with "Cure_" followed by the name of the affliction). The flexibilty comes in that you can create seperate aliases if you wish, for each particular affliction, and have them call the same routines.
Regarding that sub, "Body_Heal_Affliction", it will only make a call to cure one affliction at a time, based on the order they are placed in the array. If you want to cure them all at the same time (but still in the proper order), simply delete the line "Exit For".
As a final project, it would be real simple to write one more routine to display all the possible afflictions (in the array), and display a chart indicating your current state of health. I'll leave that to you. |