For comparison's sake, I'll offer you a large chunk of code from one of my own plugins. (The Plugin is unreleased, still needs much work, and I barely script lately).
On my mud, instead of 'spell points' [SP], we have 'concentration points' [CP].
On my mud, healer characters can choose a "heal all" spell which sends a wave of healing to the entire mud. For fun, I decided to script a thank-you informing the healer of how many HP's they healed. I use the "thank" emote which will accept an argument for additional text to add to the emote.
Thanking the healer is actually a bit tricky, because: If I am in combat, the heal the world message comes between two health bars, with the added hit points being in the health bar after the heal all line, but if I am not in combat, a health bar is presented first, and then the heal all line is presented. In order to offer an accurate message to the healer, I track the most recent health bar indicating my current health, plus the previous two health bars. (I can turn autothanks on/off via an alias).
In direct regards to what you are doing, I also have the ability to display the difference between health bars. I call this "Tickinfo". I have an alias to turn "Tickinfo" on/off via an alias, or I can just use the alias "Tick" to present the information just once.
Since the health bar is slighly different while in combat (It has an additional "OPPONENT: Perfect Health" added to it), I can detect whether I am in combat or not. This can be useful, so I track this information as well.
The script includes calls to another plugin of mine, "StatLine", which is used to present information on the status line in MUSHclient. (That one is available at my website).
Some of the triggers have &Prompt; at the beginning of them. This is a special substring meant to capture my prompt, in case it is displayed on the same line as the text I want to trigger on. The actual expression for matching my prompt is declared in an ENTITY value at the beginning of the plugin:
<!DOCTYPE muclient [
<!ENTITY NoteColour "#FF64B9" >
<!ENTITY NamePrefix "AOD_MON:" >
<!ENTITY Prompt "(?:> )*" >
]>
I find that a very useful means of offering flexability in plugins. Someone with a different prompt only need change that one value, and all the triggers in my plugin should still work.
Finally, there may be subroutines and functions called in this quoted script, which have not been quoted. (Like my "Padleft" function for example).
<!-- ===== Monitor Health Status =================================== -->
<triggers>
<trigger
enabled="y"
match="^&Prompt;HP\: \[(.*?)\/(.*?)\] CONC\: \[(.*?)\/(.*?)\]$"
name="MONITOR_Health_Status"
regexp="y"
script="Get_Health_Status"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="^&Prompt;HP\: \[(.*?)\/(.*?)\] CONC\: \[(.*?)\/(.*?)\] OPPONENT\: (.*?)$"
name="MONITOR_Health_Status_InCombat"
regexp="y"
script="Get_Health_Status"
sequence="100"
>
</trigger>
</triggers>
<aliases>
<alias
name="MON_TickInfo"
script="Toggle_TickInfo"
match="^TickInfo(?:[ ]+(.*))?$"
enabled="y"
regexp="y"
ignore_case="y"
>
</alias>
<alias
name="Display_TickInfo"
script="Display_TickInfo"
match="^tick$"
enabled="y"
regexp="y"
ignore_case="y"
>
</alias>
</aliases>
<script>
<![CDATA[
Dim HPc_Full, HPc_Current, HPc_Percent, CPc_Full, CPc_Current, CPc_Percent
Dim HPp_Full, HPp_Current, HPp_Percent, CPp_Full, CPp_Current, CPp_Percent
Dim HPp2_Full, HPp2_Current, HPp2_Percent, CPp2_Full, CPp2_Current, CPp2_Percent
Sub InCombat_False (TriggerName, TriggerLine, arrWildcards)
World.SetVariable "InCombat", vbsFalse
World.SetVariable "InCombatStatus", "Peace."
World.CallPlugin "5c582b1da52fd6a9d5d912a8", "AddString", "19_InCombatStatus" & _
Chr(10) & World.GetVariable("InCombatStatus")
If ThankHealer Then Send_Thank_Healer
End Sub
Sub InCombat_True (TriggerName, TriggerLine, arrWildcards)
World.SetVariable "InCombat", vbsTrue
World.SetVariable "InCombatStatus", "Combat!"
World.CallPlugin "5c582b1da52fd6a9d5d912a8", "AddString", "19_InCombatStatus" & _
Chr(10) & World.GetVariable("InCombatStatus")
If ThankHealer Then Send_Thank_Healer_InCombat
End Sub
Sub Get_Health_Status (TriggerName, TriggerLine, arrWildcards)
Dim StatusLineText
HPp2_Current = HPp_Current
HPp2_Full = HPp_Full
HPp2_Percent = HPp_Percent
CPp2_Current = CPp_Current
CPp2_Full = CPp_Full
CPp2_Percent = CPp_Percent
HPp_Current = HPc_Current
HPp_Full = HPc_Full
HPp_Percent = HPc_Percent
CPp_Current = CPc_Current
CPp_Full = CPc_Full
CPp_Percent = CPc_Percent
HPc_Current = CStr(CInt(arrWildcards(1)))
HPc_Full = CStr(arrWildcards(2))
HPc_Percent = CStr(Round(((CInt(HPc_Current) / CInt(HPc_Full)) * 100)))
CPc_Current = CStr(arrWildcards(3))
CPc_Full = CStr(arrWildcards(4))
CPc_Percent = CStr(Round(((CInt(CPc_Current) / CInt(CPc_Full)) * 100)))
If World.GetVariable("TickInfo") Then Display_TickInfo "Get_Health_Status", TriggerLine, arrWildcards
StatusLineText = "HP: " & HPc_Percent & "% CP: " & CPc_Percent & "%"
World.CallPlugin "5c582b1da52fd6a9d5d912a8", "AddString", "12_HealthStatus" & _
Chr(10) & StatusLineText
If CStr(arrWildcards(5)) <> Empty Then
InCombat_True "Get_Health_Status", TriggerLine, arrWildcards
Else
InCombat_False "Get_Health_Status", TriggerLine, arrWildcards
End If
End Sub
Sub Display_TickInfo (AliasName, AliasLine, arrWildcards)
World.ColourNote NoteColour, "", "HP: " & _
PadLeft(CStr(CInt(HPc_Current) - CInt(HPp_Current)), Len(HPc_Current) + 1) & _
PadLeft("CONC: ", Len(HPc_Full) + 10) & _
PadLeft(CStr(CInt(CPc_Current) - CInt(CPp_Current)), Len(CPc_Current) + 1)
End Sub
Sub TickInfo_On
World.SetVariable "TickInfo", True
World.SetVariable "TickInfoStatus", "TickInfo: On"
World.ColourNote NoteColour, "", World.GetVariable("TickInfoStatus")
End Sub
Sub TickInfo_Off
World.SetVariable "TickInfo", False
World.SetVariable "TickInfoStatus", "TickInfo: Off"
World.ColourNote NoteColour, "", World.GetVariable("TickInfoStatus")
End Sub
Sub Toggle_TickInfo (AliasName, AliasLine, arrWildcards)
Dim Argument
Argument = Trim(LCase(arrWildcards(1)))
If (Argument = "on") or (Argument = "yes") or (Argument = "true") Then Argument = "y"
If (Argument = "off") or (Argument = "no") or (Argument = "false") Then Argument = "n"
If Argument = "y" Then
TickInfo_On
ElseIf Argument = "n" Then
TickInfo_Off
Else
If World.GetVariable("TickInfo") Then
TickInfo_Off
Else
TickInfo_On
End If
End If
End Sub
]]>
</script>
<!-- ===== Thank Healer ============================================ -->
<aliases>
<alias
name="MON_AutoThank"
script="Toggle_AutoThank"
match="^(?:athank|autothank)(?:[ ]+(.*))?$"
enabled="y"
regexp="y"
ignore_case="y"
>
</alias>
</aliases>
<triggers>
<trigger
enabled="y"
match="^&Prompt;(\w*) lets (?:his|her) healing powers flow through the world\.$"
name="MONITOR_Heal_The_World"
regexp="y"
script="Set_Healer_To_Thank"
sequence="100"
>
</trigger>
</triggers>
<script>
<![CDATA[
Dim ThankHealer, ThankHealerName
Sub Set_Healer_OptOut
End Sub
Sub Set_Healer_To_Thank (TriggerName, TriggerLine, arrWildcards)
ThankHealerName = CStr(arrWildcards(1))
ThankHealer = vbsTrue
If CInt(HPp_Percent) = 100 Then ThankHealer = vbsFalse
End Sub
Sub Send_Thank_Healer
Dim Message
ThankHealer = vbsFalse
If World.GetVariable("AutoThank") Then
' Message = " HP: [" & HPp2_Current & "/" & HPp2_Full & "] - to -> HP: [" & HPp_Current & "/" & HPp_Full & "]"
Message = " for " & CStr(HPp_Current - HPp2_Current) & " HP's worth of healing"
World.LogSend "thank " & ThankHealerName & Message
End If
End Sub
Sub Send_Thank_Healer_InCombat
Dim Message
ThankHealer = vbsFalse
If World.GetVariable("AutoThank") Then
' Message = " HP: [" & HPp_Current & "/" & HPp_Full & "] - to -> HP: [" & HPc_Current & "/" & HPc_Full & "]"
Message = " for " & CStr(HPc_Current - HPp_Current) & " HP's worth of healing"
World.LogSend "thank " & ThankHealerName & Message
End If
End Sub
Sub AutoThank_On
World.SetVariable "AutoThank", True
World.SetVariable "AutoThankStatus", "AutoThank: On"
World.ColourNote NoteColour, "", World.GetVariable("AutoThankStatus")
End Sub
Sub AutoThank_Off
World.SetVariable "AutoThank", False
World.SetVariable "AutoThankStatus", "AutoThank: Off"
World.ColourNote NoteColour, "", World.GetVariable("AutoThankStatus")
End Sub
Sub Toggle_AutoThank (AliasName, AliasLine, arrWildcards)
Dim Argument
Argument = Trim(LCase(arrWildcards(1)))
If (Argument = "on") or (Argument = "yes") or (Argument = "true") Then Argument = "y"
If (Argument = "off") or (Argument = "no") or (Argument = "false") Then Argument = "n"
If Argument = "y" Then
AutoThank_On
ElseIf Argument = "n" Then
AutoThank_Off
Else
If World.GetVariable("AutoThank") Then
AutoThank_Off
Else
AutoThank_On
End If
End If
End Sub
]]>
</script>
Oh, the empty sub "Set_Healer_OptOut" is just a reminder that I intend to write additional code to restrict thanking certain healers who do not wish to be thanked (they find it too spammy).
Argh, the forum software removed a \ character here and there, particularly in the quoted triggers, escaping square brackets. I have tried to fix them. |