Roundtime script

Share your scripts and packages with other Mudlet users.
Post Reply
JohnATallon
Posts: 1
Joined: Fri Apr 13, 2018 11:01 pm

Roundtime script

Post by JohnATallon »

These two scripts are for games that use stackable roundtime. I broke it into two triggers: one for the initial roundtime and one for when additional roundtime is added. Games that use roundtime can end up using excessively long timers so I set it up to do reminders for very long roundtimer events.

On line 12 the 0.5 seconds subtracted from the roundtime accounts for lag between server and client. Change it to suit your connection. In games that report current latency it should be easy to get the latency and replace the 0.5 with a lag variable.

Roundtime Trigger
Code: [show] | [select all] lua
--Trigger: ^Roundtime: (.*) seconds\.$
--or whatever works for your game
selectString(line,1)
fg("green")
bg("black")
deselect()
resetFormat()

roundtime_stopwatch_id = roundtime_stopwatch_id or createStopWatch() --Use the allocated one or make one if there isn't one yet. 
startStopWatch(roundtime_stopwatch_id) --This resets an ongoing timer to 0, too.
roundtime = tonumber(matches[2])
roundtimer_id = tempTimer(roundtime-0.5, function() fg("gold");
                print(roundtime .. " seconds roundtime elapsed.");
                resetFormat();
                playSoundFile([[C:\YoureTheManNowDog.wav]]);  --Replace with whatever you like. I suggest something short since some games like to abuse roundtimers and you may end up getting one every second or so.
                end)

if roundtime > 180 then 
   thirdtimer_id = tempTimer(roundtime/3, function() fg("gold");
                   print(roundtime/3 .. " seconds roundtime elapsed, one-third done.");
                   resetFormat();
                   end)
   halftimer_id = tempTimer(roundtime/2, function() fg("gold");
                  print(roundtime/2 .. " seconds roundtime elapsed, halfway done.");
                  resetFormat();
                  end)
   twothirdtimer_id = tempTimer(2*roundtime/3, function() fg("gold");
                      print(2*roundtime/3 .. " seconds roundtime elapsed, two-thirds done.");
                      resetFormat();
                      end)
elseif roundtime > 15 then 
   halftimer_id = tempTimer(roundtime/2, function() fg("gold");
                  print(roundtime/2 .. " seconds roundtime elapsed, halfway done.");
                  resetFormat(); 
                  end)
else
--do nothing
end
Additional Roundtime Trigger
Code: [show] | [select all] lua
--Additional Roundtime Trigger: ^Additional Roundtime: (.*) seconds\.$
--or whatever works for your game

selectString(line,1)
fg("green")
bg("black")
deselect()
resetFormat()

--fg("gold");print("Roundtime2.");resetFormat();
roundtime = roundtime - getStopWatchTime(roundtime_stopwatch_id) --The global roundtime variable should have been set in the Roundtime trigger or a previous iteration of this trigger. Subtract the current time elapsed on the stopwatch from it.
roundtime = roundtime + tonumber(matches[2]) --Add the roundtime variable to the amount of time being added.
killTimer(roundtimer_id) --So that no duplicates fire.
startStopWatch(roundtime_stopwatch_id) --This resets it to 0, too. Done because we may get more roundtime added later.
roundtimer_id = tempTimer(roundtime-0.5, function() fg("gold");
                print(roundtime .. " seconds roundtime elapsed.");
                resetFormat();
                playSoundFile([[C:\YoureTheManNowDog.wav]]);
                end)

if twothirdtimer_id and roundtime > 180 then 
   killTimer(twothirdtimer_id)
   killTimer(halftimer_id)
   killTimer(thirdtimer_id)
   thirdtimer_id = tempTimer(roundtime/3, function() fg("gold");
                   print(roundtime/3 .. " seconds roundtime elapsed, one-third done.");
                   resetFormat();
                   end)
   halftimer_id = tempTimer(roundtime/2, function() fg("gold");
                  print(roundtime/2 .. " seconds roundtime elapsed, halfway done.");
                  resetFormat();
                  end)
   twothirdtimer_id = tempTimer(2*roundtime/3, function() fg("gold");
                      print(2*roundtime/3 .. " seconds roundtime elapsed, two-thirds done.");
                      resetFormat();
                      end)
elseif halftimer_id and roundtime > 15 then 
   killTimer(halftimer_id) 
   halftimer_id = tempTimer(roundtime/2, function() fg("gold");
                  print(roundtime/2 .. " seconds roundtime elapsed, halfway done.");
                  resetFormat();
                  end)
else
   --Do nothing.
end

Post Reply