Thread Tools Display Modes
04/09/14, 05:50 AM   #1
belialamiee
Join Date: Apr 2014
Posts: 2
Post ESO event registration

Hi Guys,

I am struggling with something that is probably fundamentally easy.

I have written a quick addon that prints xp to screen. at present it is triggering on update. obviously this is not optimal. So i want it to only update on xp gain.

But I can't seem to get the event to actually work.

here is my current code.

Code:
local curXP = GetUnitXP("Player")
local maxXP = GetUnitXPMax("Player")


function OnUpdate()
    MahaliaXpgain:SetText(string.format("XP: %d/%d", curXP, maxXP))

end

function UpdateXP()
curXP = GetUnitXP("Player")
maxXP = GetUnitXPMax("Player")
OnUpdate()
end

--this was bastardised from yout tutorial at http://wiki.esoui.com/AddOn_Quick_Questions#How_do_events_work.3F
function Mahalia_OnInitialized(self)
    --Register on the top level control...
    self:RegisterForEvent(EVENT_EXPERIENCE_GAINED, UpdateXP)
 
    --OR, register with a string unique to your add-on
    EVENT_MANAGER:RegisterForEvent("Mahalia", EVENT_EXPERIENCE_GAINED, UpdateXP)
end
I can have it trigger by using
Code:
<OnMouseDown>
                UpdateXP()
 </OnMouseDown>
But I can't just seem to get the event to trigger UpdateXP() even when it is was just d("print me") it woudn't trigger on xpgain

What am i doing wrong with event registration?
  Reply With Quote
04/09/14, 06:09 AM   #2
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
You have

EVENT_EXPERIENCE_GAIN (integer value, integer reason)
EVENT_EXPERIENCE_GAIN_DISCOVERY (string areaName, integer value)
EVENT_EXPERIENCE_UPDATE (string unitTag, integer currentExp, integer maxExp, integer reason)

The Update one occurs when someone levels in your vicinity.

The calling function you are using right but the function being used isn't being utilised properly.

Lua Code:
  1. local function UpdateXP(eventID,value,reason)
  2.      CHAT_SYSTEM:AddMessage(string.format("You have gained %d experience.",value))
  3. end
  4.  
  5. local function UpdateXPDiscovery(eventID,areaName,value)
  6.     CHAT_SYSTEM:AddMessage(string.format("You have gained %d experience through discovering %s",value,areaName))
  7. end
  8.  
  9. EVENT_MANAGER:RegisterForEvent("Mahalia", EVENT_EXPERIENCE_GAIN, UpdateXP)
  10. EVENT_MANAGER:RegisterForEvent("Mahalia", EVENT_EXPERIENCE_GAIN_DISCOVERY, UpdateXPDiscovery)

As you can see the eventID is needed in the function you use to process the event. Some events are still to have their parameters discovered but they always have the eventID as their first parameter.

I also notice that you had it as GAINED rather than GAIN. Quite understandable.
  Reply With Quote
04/09/14, 06:31 AM   #3
belialamiee
Join Date: Apr 2014
Posts: 2
Thank you so much

really appreciate your help

worked a charm
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » ESO event registration

Thread Tools
Display Modes

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