Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------
- -- Initialization
- ------------------------------------------------------------------
- function get_sets()
- -- Table of entries
- rune_timers = T{}
- -- entry = rune, index, expires
- if player.main_job_level >= 65 then
- max_runes = 3
- elseif player.main_job_level >= 35 then
- max_runes = 2
- elseif player.main_job_level >= 5 then
- max_runes = 1
- else
- max_runes = 0
- end
- end
- ------------------------------------------------------------------
- -- Action events
- ------------------------------------------------------------------
- function aftercast(spell)
- if not spell.interrupted then
- if spell.type == 'Rune' then
- update_timers(spell)
- elseif spell.name == "Lunge" or spell.name == "Gambit" or spell.name == "Rayke" then
- reset_timers()
- elseif spell.name == "Swipe" then
- send_command(trim(1))
- end
- end
- end
- ------------------------------------------------------------------
- -- Timer manipulation
- ------------------------------------------------------------------
- -- Add a new run to the custom timers, and update index values for existing timers.
- function update_timers(spell)
- local expires_time = os.time() + 300
- local entry_index = rune_count(spell.name) + 1
- local entry = {rune=spell.name, index=entry_index, expires=expires_time}
- rune_timers:append(entry)
- local cmd_queue = create_timer(entry).. ';wait 0.05;'
- cmd_queue = cmd_queue .. trim()
- --add_to_chat(123,'cmd_queue='..cmd_queue)
- send_command(cmd_queue)
- end
- -- Get the command string to create a custom timer for the provided entry.
- function create_timer(entry)
- local timer_name = '"Rune: ' .. entry.rune .. '-' .. tostring(entry.index) .. '"'
- local duration = entry.expires - os.time()
- return 'timers c ' .. timer_name .. ' ' .. tostring(duration) .. ' down'
- end
- -- Get the command string to delete a custom timer for the provided entry.
- function delete_timer(entry)
- local timer_name = '"Rune: ' .. entry.rune .. '-' .. tostring(entry.index) .. '"'
- return 'timers d ' .. timer_name .. ''
- end
- -- Reset all timers
- function reset_timers()
- local cmd_queue = ''
- for index,entry in pairs(rune_timers) do
- cmd_queue = cmd_queue .. delete_timer(entry) .. ';wait 0.05;'
- end
- rune_timers:clear()
- send_command(cmd_queue)
- end
- -- Get a count of the number of runes of a given type
- function rune_count(rune)
- local count = 0
- for _,entry in pairs(rune_timers) do
- if entry.rune == rune then
- count = count + 1
- end
- end
- return count
- end
- -- Remove the oldest rune(s) from the table, until we're below the max_runes limit.
- -- If given a value n, remove n runes from the table.
- function trim(n)
- local cmd_queue = ''
- local to_remove = n or (rune_timers:length() - max_runes)
- while to_remove > 0 and rune_timers:length() > 0 do
- local oldest
- for index,entry in pairs(rune_timers) do
- if oldest == nil or entry.expires < rune_timers[oldest].expires then
- oldest = index
- end
- end
- cmd_queue = cmd_queue .. prune(rune_timers[oldest].rune)
- to_remove = to_remove - 1
- end
- return cmd_queue
- end
- -- Drop the index of all runes of a given type.
- -- If the index drops to 0, it is removed from the table.
- function prune(rune)
- local cmd_queue = ''
- for index,entry in pairs(rune_timers) do
- if entry.rune == rune then
- cmd_queue = cmd_queue .. delete_timer(entry) .. ';wait 0.05;'
- entry.index = entry.index - 1
- end
- end
- for index,entry in pairs(rune_timers) do
- if entry.rune == rune then
- if entry.index == 0 then
- rune_timers[index] = nil
- else
- cmd_queue = cmd_queue .. create_timer(entry) .. ';wait 0.05;'
- end
- end
- end
- return cmd_queue
- end
- ------------------------------------------------------------------
- -- Reset events
- ------------------------------------------------------------------
- windower.raw_register_event('zone change',reset_timers)
- windower.raw_register_event('logout',reset_timers)
- windower.raw_register_event('status change',function(new, old)
- if gearswap.res.statuses[new].english == 'Dead' then
- reset_timers()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement