diff --git a/zonetimer/manifest.xml b/zonetimer/manifest.xml new file mode 100644 index 00000000..93bab7b1 --- /dev/null +++ b/zonetimer/manifest.xml @@ -0,0 +1,10 @@ + + zonetimer + 1.0.0.0 + addon + + settings + world + packets + + diff --git a/zonetimer/readme.md b/zonetimer/readme.md new file mode 100644 index 00000000..b79d25d6 --- /dev/null +++ b/zonetimer/readme.md @@ -0,0 +1,17 @@ +**Author:** Krellion
+**v5 Migration:** Akaden
+**Version:** 1.0.0.0
+**Date:** April 29, 2020
+ +# Zone Timer # + +* Tracks how long you've been in the current zone. +* Ignores zone changes via tractor. + +---- + +**Main Command:** `/zonetimer` + +#### Commands: #### +* 1: /zonetimer pos x y - set the zonetimer window position +* 2: /zonetimer move - enable moving the zonetimer window with your mouse diff --git a/zonetimer/zonetimer.lua b/zonetimer/zonetimer.lua new file mode 100644 index 00000000..d9f791d6 --- /dev/null +++ b/zonetimer/zonetimer.lua @@ -0,0 +1,88 @@ +local settings = require('settings') +local ui = require('core.ui') +local command = require('core.command') +local os = require('os') +local string = require('string') +local world = require('world') +local packets = require('packets') + +local defaults = { + x = 400, + y = 0, + text_style = 'Roboto bold 12px stroke:"10% #000000BB" background:"#000000FF"', +} + +local options = settings.load(defaults) + +local start_time = os.time() + +local zone_timer = { + move = false, + state = { + title = 'Zone Timer', + style = 'chromeless', + x = options.x, + y = options.y, + width=80, + height=30, + resizable = false, + moveable = true, + closable = false, + }, +} + +world.zone_change:register(function() + if not zone_timer.tractor then + start_time = os.time() + end + + zone_timer.tractor = false +end) +packets.outgoing[0x01A]:register(function(packet, info) + if packet.action_category == 0x13 then + zone_timer.tractor = true + end +end) + +local zt = command.new('zonetimer') +zt:register('move', function(command) + local new_move = nil + if command == nil or command == '' then + new_move = not zone_timer.move + else + new_move = set('show','on','true','yes'):contains(command:lower()) + end + zone_timer.move = new_move + + zone_timer.state.style = zone_timer.move and 'normal' or 'chromeless' + + options.x = zone_timer.state.x + options.y = zone_timer.state.y + + settings.save() +end, '[visible:one_of(show,hide,on,off,true,false,yes,no)]') + +zt:register('pos', function(x, y) + zone_timer.state.x = x + zone_timer.state.y = y + + options.x = x + options.y = y + + settings.save() +end, ' ') + +ui.display(function() + local seconds = os.time() - start_time + if zone_timer.move then + zone_timer.state, zone_timer.closed = ui.window('zone_timer', zone_timer.state, function() + ui.location(0, 0) + + ui.text(string.format('['..os.date('!%H:%M:%S', seconds)..']{%s}', options.text_style)) + end) + else + ui.location(options.x, options.y) + + ui.text(string.format('['..os.date('!%H:%M:%S', seconds)..']{%s}', options.text_style)) + end +end) \ No newline at end of file