Thread Tools Display Modes
01/07/16, 10:14 AM   #1
coolmodi
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 47
EVENT_EFFECT_CHANGED and unitIDs

Hey,

I have 2 questions:
  • The unitId and unitName of the mentioned event is always from the same unit, right?
  • Does anyone know when unitIDs change?


Edit: Ok, they definately change, just don't know on what condition(s) yet.

Last edited by coolmodi : 01/07/16 at 01:17 PM.
  Reply With Quote
01/07/16, 06:04 PM   #2
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by coolmodi View Post
Hey,

I have 2 questions:
  • The unitId and unitName of the mentioned event is always from the same unit, right?
  • Does anyone know when unitIDs change?


Edit: Ok, they definately change, just don't know on what condition(s) yet.
Yes they are from the same unit and:
Quote from: http://www.esoui.com/forums/showthread.php?p=21696#post21696
Originally Posted by ZOS_ChipHilseberg View Post
We've added a new function called GetAbilityIcon which takes the ability id and returns its icon path. We've also modified COMBAT_EVENT to pass numerical identifiers for the source and target so units with the same name can be separated. This ids are good for as long as the unit exists on the client. The same is true of EFFECT_UPDATED and its unit.
Although I have no idea what effect reloading the UI or zoning would have on the existence of a unit. Unfortunately there is no function to check and see if a unitId still exists.
  Reply With Quote
01/08/16, 10:09 AM   #3
coolmodi
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 47
Thanks! So they just change when going out of visual range I guess, and probably when zoning.

I'll just migrate the data from one unit ID to the other when it changes then, and delete the old entry. That way it should be possible to track players even in cyrodiil reliably.
  Reply With Quote
01/08/16, 06:50 PM   #4
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by coolmodi View Post
Thanks! So they just change when going out of visual range I guess, and probably when zoning.

I'll just migrate the data from one unit ID to the other when it changes then, and delete the old entry. That way it should be possible to track players even in cyrodiil reliably.
It sounds like you are going to run into one of the problems I ran into with BuffTracker.

Despite the wording of this post:
Originally Posted by ZOS_ChipHilseberg View Post
For the unique ID we're looking at providing a number to identify each instance with the same name. Players will always be 0 (since their name should be unique anyway) and non-players will have an arbitrary number that will be the same as long as that unit exists.
Players do not have a unitId of 0 and the unitTag is nil unless the event is firing for a unit you are currently targeting. Although the player names are unique that does us no good because there is no way to distinguish between players & other targets (except the users character).

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. 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.

This also means that if you want to track effects on mobs you have no choice but to also track effects on players (and vice-versa) since we can't tell them apart.

My best thought would be to save everything by UnitId and if a targets unitId changes just let it change and start saving new data for that target. Also record a timestamp in the saved effects data table each time the data is updated for any given unitId. Then set a RegisterForUpdate(...) and every once in a while check the timestamps for all of your saved effect data & if its xxx old (meaning it hasn't been updated in a while) assume its no longer valid and delete the data to keep the table clean. Although its not a good solution its the best I've come up with.

I added some things that might help a little to the wish list a while back. Maybe someday we'll get some functions to help with things like this: http://www.esoui.com/forums/showthread.php?t=5298
  Reply With Quote
01/08/16, 08:11 PM   #5
coolmodi
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 47
Originally Posted by circonian View Post
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:
  1. --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
  2. unitList = {                    
  3.    [unitId] = {name,player,group}
  4. }
  5. --this is the important thing, you need names as key with id as value too!!!
  6. nameIdPairs = {          
  7.    [name] = Id
  8. }
  9. --data saved to each unitId
  10. dataArray = {
  11.    [unitId] = dataForUnit
  12. }

Then some changed wip code from my addon:

Lua Code:
  1. --on every combat and effect event this is done, data collection into the "dataArray" is done somewhere else
  2. function GroupDamage:UpdateUnitList(unitId, unitName, unitType)
  3.     if unitName == "" and (unitType ~= 3 or unitType ~= 1) then return end
  4.     if self.unitList[unitId] == nil then
  5.         self.unitList[unitId] = {
  6.             ["name"] = "<placeholder>" .. unitId,
  7.             ["player"] = false,
  8.             ["group"] = false
  9.         }
  10.     end
  11.     if targetName ~= "" then
  12.         self.unitList[unitId]["name"] = zo_strformat("<<C:1>>", unitName)
  13.        
  14.         --magic starts here
  15.         --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
  16.         if unitName:match("%^")~=nil then
  17.             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?)
  18.            
  19.             --so now check if you already had that name with an id before and if the id for the name changed
  20.             if self.nameIdPairs[unitName] ~= nil and self.nameIdPairs[unitName] ~= unitId then
  21.                 --yes? you now have the old and new ID!
  22.                 self:MigrateToNewId(self.nameIdPairs[unitName], unitId)
  23.             end
  24.             self.nameIdPairs[unitName] = unitId --assign new id to the name
  25.            
  26.         end
  27.    
  28.    
  29.     end
  30.     if unitType == 3 or unitType == 1 then
  31.         self.unitList[unitId]["group"] = true
  32.     end
  33. end
  34.  
  35. function GroupDamage:MigrateToNewId(oldId, newId) --WIP
  36.     d("Id for player or named mob changed!")
  37.     d("Old name: " .. self.unitList[oldId]["name"] .. " with ID: " .. oldId)
  38.     d("New name: " .. self.unitList[newId]["name"] .. " with ID: " .. newId)
  39.     --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...
  40.     self.unitList[oldId] = nil   --also remove old from unitList
  41.     self.currentFightData["units"][oldId] = nil   --and also old data in the "dataArray"
  42. 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 View Post
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??

Last edited by coolmodi : 01/08/16 at 09:00 PM.
  Reply With Quote
01/08/16, 08:59 PM   #6
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by coolmodi View Post
Oh yes I can, at least if I'm not totally wrong and miss something really obvious
...
--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
Nice, if that's true then you are correct. I did not know that mob names do not contain a ^. If mobs don't have ^ then that would fix that problem and yes as long as its a player the names are unique.

Just fyi so you don't end up with a bug:
Lua Code:
  1. if unitName == "" and (unitType ~= 3 or unitType ~= 1) then return end
  2.  
  3. -- this doesn't do anything, its always true:
  4. -- and (unitType ~= 3 or unitType ~= 1)

Last edited by circonian : 01/08/16 at 09:04 PM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » EVENT_EFFECT_CHANGED and unitIDs


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off