Quantcast
Download
(2 Kb)
Download
Updated: 10/21/20 02:04 PM
Compatibility:
Markarth (6.2.5)
Stonethorn (6.1.5)
Updated:10/21/20 02:04 PM
Created:10/21/20 02:04 PM
Monthly downloads:2,668
Total downloads:4,071
Favorites:6
MD5:
6.2.5
LibUnitTracker
Version: 0.0.1
by: zelenin [More]
Library for tracking units in a combat.

Usage:

Install dependency:
- LibDelayedHandler

Add dependency to manifest:


Code:
## DependsOn: LibUnitTracker
Code:
local unitTracker = LibUnitTracker:New()
-- subscribe to events
unitTracker:Start()

EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_COMBAT_EVENT, function(eventCode, result, isError, abilityName, abilityGraphic, abilityActionSlotType, sourceName, sourceType, targetName, targetType, hitValue, powerType, damageType, log, sourceUnitId, targetUnitId, abilityId, overflow)
    local characterName = targetName
    if characterName == "" then
        characterName = unitTracker:GetUnitNameByUnitId(targetUnitId)
    end   
    local displayName = unitTracker:GetDisplayNameByUnitName(characterName)
    ...
end)

EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_PLAYER_COMBAT_STATE, function(eventCode, inCombat)
    if not inCombat then
        -- unsubscribe from events
        unitTracker:Stop()
    end
end)
You can save and restore unit data for own purposes (to save combat logs for example):

Code:
local unitData = unitTracker:GetUnitData()

self.saveData.unitData = unitData
...

local unitData = self.saveData.unitData
local unitTracker = LibUnitTracker:New(unitData)
...
local displayName = unitTracker:GetDisplayNameByUnitName(characterName)
Note:
UnitIds are unique only for one combat and are cleared in the begginning of the next combat.


API:
Code:
LibUnitTracker:Start()

LibUnitTracker:Stop()

LibUnitTracker:GetUnitData()

LibUnitTracker:GetUnitNameByUnitId(unitId)

LibUnitTracker:GetDisplayNameByUnitName(unitName)

LibUnitTracker:GetDisplayNameByUnitId(unitId)

LibUnitTracker:GetUnitByUnitTag(unitTag)

LibUnitTracker:GetGroup()
Unit:
Code:
{
    index = index,
    tag = unitTag,
    rawName = GetRawUnitName(unitTag),
    name = ZO_CachedStrFormat(SI_UNIT_NAME, GetRawUnitName(unitTag)),
    displayName = GetUnitDisplayName(unitTag),
    classId = GetUnitClassId(unitTag),
    gender = GetUnitGender(unitTag),
    level = GetUnitLevel(unitTag),
    championPoints = GetUnitChampionPoints(unitTag),
    alliance = GetUnitAlliance(unitTag),
    raceId = GetUnitRaceId(unitTag),
    isOnline = IsUnitOnline(unitTag),
    isLeader = IsUnitGroupLeader(unitTag),
    isPlayer = AreUnitsEqual(unitTag, "player"),
}
0.0.1:
- initial release
There have been no comments posted to this file.
Be the first to add one.



Category Jump: