Download
(4 Kb)
Download
Updated: 05/13/22 01:47 PM
Compatibility:
High Isle (8.0.0)
Ascending Tide (7.3.5)
Updated:05/13/22 01:47 PM
Created:07/21/21 08:24 PM
Monthly downloads:2,933
Total downloads:93,047
Favorites:32
MD5:
LibHandler  Popular! (More than 5000 hits)
Version: 0.0.3
by: zelenin [More]
Work In Progress (unstable API)

a collection of some handlers used in addon development

- conditional handler

The condition is checked every 1000 ms until it returns true. Then the task is executed

Code:
local condition = function()
    -- checking something
    return true
end

local task = function()
    -- do something
end

local timeout = 1000

LibHandler:Condition(condition, task, timeout)

- zone change handler

Handlers are executed when entering and exiting a certain zone.

Code:
local zoneId = 1263 -- Rockgrove
local enterHandler = function(oldZoneId, newZoneId)
    CHAT_ROUTER:AddSystemMessage(string.format("Entered %s zone from %s zone", GetZoneNameById(newZoneId), GetZoneNameById(oldZoneId)))
end
local exitHandler = function(oldZoneId, newZoneId)
    CHAT_ROUTER:AddSystemMessage(string.format("Left %s zone to %s zone", GetZoneNameById(oldZoneId), GetZoneNameById(newZoneId)))
end

LibHandler:ZoneChange(zoneId,enterHandler, exitHandler)
Code:
local mapId = 988
local enterHandler = function(oldMapId, newMapId)
    CHAT_ROUTER:AddSystemMessage(string.format("Entered %s from %s", GetMapNameById(newMapId), GetMapNameById(oldMapId)))
end
local exitHandler = function(oldMapId, newMapId)
    CHAT_ROUTER:AddSystemMessage(string.format("Left %s to %s", GetMapNameById(oldMapId), GetMapNameById(newMapId)))
end

LibHandler:MapChange(mapId ,enterHandler, exitHandler)

- limiters

Code:
local timeThreshold = 100 -- ms
--local repeatable = true -- executes the last task every 100 ms
local repeatable = false -- executes the last task if there is no new task for the last 100 ms

local limiter = LibHandler:Limiter(function(arg1, arg2, arg3, ..., argN)
    CHAT_ROUTER:AddSystemMessage(arg1)
end, timeThreshold, repeatable)

local limiterWithDependency = LibHandler:LimiterWithDependency(function(arg1, arg2, arg3, ..., argN)
    CHAT_ROUTER:AddSystemMessage(arg1)
end, timeThreshold, repeatable)

for i = 0, 10 do
    local timeout =i*40
    local arg1 = string.format("i: %d timeout: %d", i, timeout)
    local dependency = 1 -- any number, string or function returning number or string
    zo_callLater(function()
        limiter:Trigger(arg1, arg2, arg3, ..., argN)
        limiterWithDependency:Trigger(dependency, arg1, arg2, arg3, ..., argN)
    end, timeout)
end
0.0.3:
- MapChange fix

0.0.2:
- added MapChange handler

0.0.1:
- initial release
Archived Files (2)
File Name
Version
Size
Uploader
Date
0.0.2
4kB
zelenin
08/27/21 03:23 AM
0.0.1
3kB
zelenin
07/21/21 08:24 PM


There have been no comments posted to this file.
Be the first to add one.



Category Jump: