Originally Posted by circonian
Since other targets/mobs do not have unique names you can not use the units name as a key for the data (not even for players because we can't distinguish between players & mobs to separate the two). It also means that if the unitId changes you can't migrate the data because you have no way of knowing what the original unitId was to find the correct data to migrate.
|
Oh yes I can, at least if I'm not totally wrong and miss something really obvious, my two addons here are the first thing I ever programmed that goes over the hello world crap I had to do for an uni course
Basic arrays needed, just to show the data structure
Lua Code:
--to have name and the info whether it's a player (or named mob but that's ok for migration purposes) and in group for each unitId
unitList = {
[unitId] = {name,player,group}
}
--this is the important thing, you need names as key with id as value too!!!
nameIdPairs = {
[name] = Id
}
--data saved to each unitId
dataArray = {
[unitId] = dataForUnit
}
Then some changed wip code from my addon:
Lua Code:
--on every combat and effect event this is done, data collection into the "dataArray" is done somewhere else
function GroupDamage:UpdateUnitList(unitId, unitName, unitType)
if unitName == "" and (unitType ~= 3 or unitType ~= 1) then return end
if self.unitList[unitId] == nil then
self.unitList[unitId] = {
["name"] = "<placeholder>" .. unitId,
["player"] = false,
["group"] = false
}
end
if targetName ~= "" then
self.unitList[unitId]["name"] = zo_strformat("<<C:1>>", unitName)
--magic starts here
--if a name contains a "^" it isn't a general mob, and in any case(?) at least unique, or unique enough to not make problems
if unitName:match("%^")~=nil then
self.unitList[unitId]["player"] = true --this is bull**** because of that, but it helps filtering out general mobs in my addon (do mobs have an x after f/m too?)
--so now check if you already had that name with an id before and if the id for the name changed
if self.nameIdPairs[unitName] ~= nil and self.nameIdPairs[unitName] ~= unitId then
--yes? you now have the old and new ID!
self:MigrateToNewId(self.nameIdPairs[unitName], unitId)
end
self.nameIdPairs[unitName] = unitId --assign new id to the name
end
end
if unitType == 3 or unitType == 1 then
self.unitList[unitId]["group"] = true
end
end
function GroupDamage:MigrateToNewId(oldId, newId) --WIP
d("Id for player or named mob changed!")
d("Old name: " .. self.unitList[oldId]["name"] .. " with ID: " .. oldId)
d("New name: " .. self.unitList[newId]["name"] .. " with ID: " .. newId)
--copy data from one unitId to the new unitId in "dataArray", or add it if it already exists, which is highly probable with combat event...
self.unitList[oldId] = nil --also remove old from unitList
self.currentFightData["units"][oldId] = nil --and also old data in the "dataArray"
end
This should work, I even tested it ingame, but with a much worse solution in terms of performance, hence the extra array with [name] = ID pairs, so I can just use ~= two times and don't have to loop through the unitList
Thanks to effect changed ALWAYS giving name and ID this should work pretty reliable too, as soon as someone comes in range it will fire even if they only have the ESO PLUS buff, or a food buff, really anything. In that moment I will have their new id, and the old one from the name+id pairs.
Originally Posted by circonian
Also migrating the data would probably be a bad idea. As an example: If a player went out of range & his unitId changed (or even if it didn't change) he was probably far enough out of range that when his effects changed the event did not fire for us so that effect data you have saved is probably no longer valid.
|
Doesn't affect me, I just need name and ID from it, my addon tracks damage and heal for every unit
But anyways, why would the effect data not be valid anymore? Doesn't it just provide begin and end time of buffs? That won't change only because they were out of range, so what isn't valid anymore?
Edit: And why are the code containers not as wide as quote containers here??