PDA

View Full Version : stopwatch.lic



Alorn15
08-30-2009, 08:54 PM
This is a pretty simple StopWatch object for scripts to time hunts. Thought I may as well share it.

Output:
[platform: Last hunt: 2 min. 57.00 secs.]
[platform: Average hunt: 2 min. 44.00 secs.]
[platform: Total time running: 151 min. 11.00 secs.]


################
# STOPWATCH: For timing things
# Author: Azanoth
# SETUP:
# 1. Add '$LOAD_PATH << $script_dir' to your script
# 2. Add 'load "stopwatch.lic"' to your script
# 3. Create a StopWatch object - @watch = StopWatch.new
# 4. Call functions!
################
class StopWatch
@birthTime
@startTime
@log

def initialize
@birthTime = Time.now.to_i
@startTime = 0
@log = Array.new
end

def start()
@startTime = Time.now.to_i
end

def stop()
if(@startTime != 0)
@log.push(Time.now.to_i - @startTime)
end
@startTime = 0;

return Time.now.to_i
end

def lastTime()
if(@log.size > 0)
seconds = @log[@log.size - 1]
echo( sprintf("Last recording: %d min. ", seconds / 60) + sprintf("%0.2f secs.", seconds % 60) )
else
echo( sprintf("Last recording: No last hunt recorded") )
end

return @log[@log.size - 1]
end

def averageTime()
average = 0
if(@log.size > 0)
@log.each { |entry| average += entry }
average /= @log.size
echo( sprintf("Average recording: %d min. ", average / 60) + sprintf("%0.2f secs.", average % 60) )
else
echo( sprintf("Average recording: No hunts recorded") )
end

return average
end

def totalTime()
total = Time.now.to_i - @birthTime
echo( sprintf("Total time running: %d min. ", total / 60) + sprintf("%0.2f secs.", total % 60) )

return total
end
end

Each method return can essentially be ignored, as there is a built-in echo. If you prefer, the methods do return an integer representing seconds.

Deathravin
08-30-2009, 10:54 PM
LOL, nice. I have something very similar to this too.

Shows me how many of each critter I killed, how much mana per critter, xp/mana (based on general mob level), time per critter, etc etc etc.