Timers that include downtime.

Posted by Magnum on Tue 13 Aug 2002 10:32 PM — 3 posts, 16,921 views.

Canada #0
Well, I'm faced with an interesting challenge...:

The MUD I play does not offer any sort of timed ignore or channel tune built in, so I am faced with building my own.

This was a low priority item on my to-do list, but the higher in level I get, the more I get leech nagged, so the priority for this project has been moved up dramatically.

The main challenge is this: I want to have an action take place after a variable amount of time has passed, but time spend offline, or even while MUSHclient is not loaded should count.

For example:

I set a 6 hour ignore on "LeechBoy".
3 hours later I log off, close MUSHclient, turn off my computer.
12 hours later I load MUSHclient, connect to MUD.
MUSHclient notices target time has passed, issues commands.

I don't believe I could do that simply with the current functionality of the timer tools. I would likely need write script that involved:

On Ignore/Tune
Store target to variable
Store endtime for target to variable

On TargetTime
Perform delayed action.
Delete target variable, Target Endtime variable

On Connect
Recalculate all end time variables.
Act on elapsed TargetTimes
Rebuild MUSHclient Ignore/Tune timers.

I always try and consider the overhead in any scripts I write, and the thing I don't like about this one is that each player/channel on temp. ignore requires 1 timer and 2 variables.

If the functionality was built right into mushclient then I would simply build 1 timer per player/channel:

calculate endtime
build timer with "send" as "unignore -targetname" or "tune in channel"

I assume I would set a flag in the addtimer which would indicate the timer should count realtime, (but not fire while disconnected).

Hmm... As you can tell, I'm sort of doing the brainstorming on the fly, as I write this. Seems to be a good way for me to "plan" my scripts before writing them.

Any suggestions appreciated. :)
Amended on Tue 13 Aug 2002 11:44 PM by Magnum
#1
Sounds like an interesting challenge.

Here's a few things that I thought of when reading the post.

world.GetTimerInfo(strName, 13)

This returns the number of seconds until the timer will fire.

You can insert code in your onDisconnect to get this data and store it into a specially formatted variable, include the number of seconds remaining and the command you want to perform after this count.

Use specific prefixes(plugin?) on timers to be able to find them easily. You should just be able to use an incremental counter to number them: chat_ignore_1, chat_ignore_2, etc.

counter = 1
Do While (world.IsTimer("chat_ignore_" & counter) <> 0)
  counter = counter + 1
Loop

' create timer


On your disconnect, something like:

astrTimerList = world.GetTimerList
strData = ""
For Each strTimerName In astTimerList
  If (Left(strTimerName, 12) = "chat_ignore_") Then
    strData = strData & world.GetTimerInfo(strTimerName, 13) & " " & world.GetTimerInfo(strTimerName, 4) & vbCrLf
    world.DeleteTimer strTimerName
  End If
Next

world.SetVariable "chat_ignore_storage", strData


On your reconnect, something like:

If (world.GetVariable("chat_ignore_storage") <> "") Then
  strData = world.GetVariable("chat_ignore_storage")
  astrData = Split(strData, vbCrLf)
  counter = 1
  For Each strData In astrData
    lngSeconds = CLng(Mid(strData, 1, InStr(1, strData, " ", 1) - 1))
    strCommand = Mid(strData, InStr(1, strData, " ", 1) + 1, 1000)
    world.AddTimer "chat_ignore_" & counter, 0, 0, lngSeconds, strCommand, eEnabled+eOneShot+eTemporary
    counter = counter + 1
  Next
End If


This should keep your timers active only when you are active on the mud.

Note: This code should be tested extensively, I just pulled it out of thin air. I have a strange tendency to visualize code when I see problems, so I just visualized it straight to here.
Canada #2
No problem, I'm skilled enough I could probably debug any errors.

After I posted, I thought the same thing, that I could probably reverse-engineer the timers to build variables with real-life time periods (Probably in the same format as the VBS Now() function.

I could use the timer name to indicate "PC" or "CH" for example, for player or channel, then pull the target back by parsing the "Send" box info for each trigger, and then pulling the time remaining, and calculating a real life date. I could throw them all into a variable like this:

TimerTotal = 2
Timer1 = "2002-08-15 4:22:34 AM,PC_leechboy"
Timer2 = "2002-08-14 6:44:02 AM,CH_newbie"

Actually, to make the parsing easier, and the code more flexable, I would just include the target name in the timer name, like I did as the second argument in those variables.

I'm not gonna start writing this till later in the week, then I will take more than a glancing look at your code, V. Thanks for the input. :)