
how to create a timer countdown
#1

Posted 20 February 2015 - 05:12 PM
#2

Posted 20 February 2015 - 05:28 PM
It's supposed to be timers c name 600 down icon but looking at the code it seems that it's not actually implemented. If you could open an issue for this so we actually remember to do it, it would be appreciated.
#3

Posted 20 February 2015 - 05:37 PM
#4

Posted 20 February 2015 - 06:47 PM
As for Timers it's definitely not implemented and you can't do it. What you can do is change the settings entry "CustomLowToHigh", but it will be that for all custom timers created.
Lua doesn't have timers, so I don't understand your question.
#5

Posted 20 February 2015 - 07:15 PM
#6

Posted 20 February 2015 - 09:24 PM
How do you make a timer counting up? It's simple to adjust from there.
#7

Posted 21 February 2015 - 01:53 AM
#8

Posted 21 February 2015 - 04:47 AM
Um, actually no. The semantics of the value returned by os.time are implementation defined. To get the difference between two times you need to use the os.difftime function.
local start_time = os.time() local elapsed_time = os.difftime(os.time(), start_time)
To get the time remaining until some future event you can do this.
local end_time = os.time() + delay local time_remaining = os.difftime(end_time, os.time())
Edit: This is what I get for replying right before bed.
While the second snippet above will probably work, it is incorrect. The correct way to do it is to construct a table with the correct date and time of the future event and then pass that to os.time.
#9

Posted 21 February 2015 - 09:39 AM
Honestly, the easiest way would be to use the Timers plugin for that. I'm currently implementing the feature to set the counting direction and will push an update later today. But if you want just a draggable text box you can use what Iryoku said to calculate the remaining time and update a text box with it (for example in the pre-render event). Let me know if you want a code example for that.
#10

Posted 21 February 2015 - 06:02 PM
#11

Posted 21 February 2015 - 11:33 PM
That's actually a neat idea. I would love to display timers next to each item when you look into the treasure pool. For that to work I'd need to figure out how menus are being used, which I already looked into in the past. Alternatively one could make a treasure pool replacement that always shows items, current lot/lotter and time remaining, and so on.
You can use packets to find the right event. Every time a treasure pool packet comes in you can update the timer.
#12

Posted 21 February 2015 - 11:48 PM
#13

Posted 22 February 2015 - 12:26 AM
Could make it so that when you hover over any item, it shows an ordered list of lotters and their lots
#14

Posted 22 February 2015 - 12:36 AM
#15

Posted 22 February 2015 - 05:50 PM
require('maths') texts = require('texts') t = texts.new('${hours||%.2u:}${minutes||%.2u:}${seconds||%.2u}${milliseconds||.%.1u}') goal = 0 windower.register_event('prerender', function() local diff = goal - os.clock() if diff > 0 then t.hours = (diff / 3600):floor() t.minutes = ((diff / 60) % 60):floor() t.seconds = (diff % 60):floor() t.milliseconds = ((diff * 10) % 10):floor() t:show() elseif diff > -5 then if diff:floor() % 2 == 1 then t:color(153, 255, 102) else t:color(255, 255, 255) end else t:hide() end end) windower.register_event('addon command', function(seconds) goal = os.clock() + tonumber(seconds) end)
#16

Posted 22 February 2015 - 07:28 PM
#17

Posted 22 February 2015 - 10:40 PM
require('maths') texts = require('texts') config = require('config') packets = require('packets') res = require('resources') settings = config.load() clock = texts.new(settings) for i = 0, 9 do clock:appendline('${item' .. i .. '||%s - }${minutes' .. i .. '||%.2u:}${seconds' .. i .. '||%.2u}') end clock:show() goals = {} windower.register_event('prerender', function() for i = 0, 9 do local diff = 300 - os.difftime(os.time(), packet.Timestamp) if diff > 0 then clock['minutes' .. i] = ((diff / 60) % 60):floor() clock['seconds' .. i] = (diff % 60):floor() else clock['minutes' .. i] = nil clock['seconds' .. i] = nil end end end) windower.register_event('incoming chunk', function(id, data) -- Ignore all non-drop packets if id ~= 0x0D2 then return end local packet = packets.parse('incoming', data) -- Ignore gil drop if packet.Item == 0xFFFF then return end goals[packet.Index] = packet.Timestamp + 300 clock['item' .. packet.Index] = res.items[packet.Item].name end)
#18

Posted 22 February 2015 - 10:57 PM

#19

Posted 23 February 2015 - 06:42 AM

local diff = os.difftime(goals[i], os.time())
#20

Posted 23 February 2015 - 01:57 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users