This has been an interesting challenge. I assumed that you would probably want to cast the spell on more than one person at once - which made it trickier - hence the complexity of the result.
What I have done below is three parts:
Trigger to match when spell is cast
You need to go into World configuration -> Appearance -> Triggers and add a trigger:
Match on: Valhart puts a protective spell on (.+)
Enabled: checked
Regular expression: checked
Change colour to: (your choice of colour)
Label: CastSpell
Script: OnSpell
This trigger will fire when it sees the appropriate string, and calls the script function "OnSpell" (below). This script adds a one-shot timer set to go off in 14 minutes 30 seconds (which is when you want the warning message).
The script also remembers the name of the person who you cast the spell on (passed down as a wildcard) and the current time. These two things are put into variables, where the variable name has a unique number appended to make sure that we don't have a clash of variable names.
eg.
Timer name:
SpellTimer_32
Variables:
SpellTimer_Name_32 = Gandalf
SpellTimer_Time_32 = 31/07/01 9:30:21
(in this case 32 was the unique number).
Timer script
We now need a script to be called when the timer expires, this is called "OnSpellTimer".
- It works out from the timer name what the unique number was (32 in the above example).
- It then scans the variable list to find the matching variable names, and extracts out the name of the person the spell was protecting.
- It then displays the message "say IW spell left for Gandalf 30 seconds!!"
- It then deletes the two variables set up by the trigger
Query script
To handle your last requirement we have a third script routine "OnSpellQuery" - called from an alias "report iw".
This script scans all variables to find the appropriate ones, and displays all outstanding spells and times to go in seconds, eg.
IW spell left for Nick is 877 secs
IW spell left for Fred is 880 secs
IW spell left for John is 883 secs
I have done this as a "world.note" which only shows you the information. To change it so that everyone sees it you would change it to "world.send" and put "say" in front of the message.
To call this from an alias you would add an alias, like this:
Match on: report iw
Enabled: checked
Label: Report
Script: OnSpellQuery
Because of the design of this, you won't see the last 30 seconds of the spell, because the timer expires after 14 minutes 30 seconds, but presumably that isn't a big deal.
The script follows (VBscript):
sub OnSpell (strTriggerName, strTriggerLine, aryWildcards)
dim who
dim number
' who did we cast the spell on?
who = aryWildcards (1)
' get a unique number
number = world.GetUniqueNumber
' Flags:
' 1 = enabled
' 4 = one shot (once only)
' 1024 = replace any of same name
' add a timer to go off in 14 minutes 30 seconds
world.AddTimer "SpellTimer_" & number, 0, 14, 30, "", _
1 + 4 + 1024, "OnSpellTimer"
' remember when we cast the spell
world.setvariable "SpellTimer_Time_" & number, Now
world.setvariable "SpellTimer_Name_" & number, who
end sub
sub OnSpellTimer (strTimerName)
dim splitname
dim mylist
dim number
dim i
dim character
splitname = split (strTimerName, "_")
number = CInt (splitname (1)) ' find our unique number
mylist = world.GetVariableList
' scan variables list to find timer number
if not IsEmpty (mylist) then
for i = lbound (mylist) to ubound (mylist)
splitname = split (mylist (i), "_")
if ubound (splitname) = 2 then
if splitname (0) = "spelltimer" and splitname (1) = "name" then
if CInt (splitname (2)) = number then
' work out character name
character = world.GetVariable (mylist (i))
' tell them time is up
world.send "say IW spell left for " & character & " 30 seconds!!"
' delete associated variables
world.deletevariable splitname (0) & "_Name_" & splitname (2)
world.deletevariable splitname (0) & "_Time_" & splitname (2)
end if
end if ' found a spelltimer variable
end if ' split into 3 pieces
next ' end of loop
End If ' have any variables
end sub
sub OnSpellQuery (thename, theoutput, thewildcards)
dim mylist
dim i
dim splitname
dim starttime
dim timeleft
dim character
mylist = world.GetVariableList
if not IsEmpty (mylist) then
for i = lbound (mylist) to ubound (mylist)
splitname = split (mylist (i), "_")
if ubound (splitname) = 2 then
if splitname (0) = "spelltimer" and splitname (1) = "name" then
starttime = CDate (world.GetVariable _
(splitname (0) & "_Time_" & splitname (2)))
character = world.GetVariable (mylist (i))
timeleft = 900 + DateDiff("s", Now, starttime)
if timeleft < 0 then
world.note "IW spell for " & character & " has expired"
else
world.note "IW spell left for " & character & " is " _
& timeleft & " secs"
end if
end if ' found a spelltimer variable
end if ' split into 3 pieces
next ' end of loop
End If ' have any variables
end sub