Thread Tools Display Modes
03/17/23, 09:58 AM   #1
Shuba00
 
Shuba00's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2023
Posts: 20
don't know how to detect zone change

Hello,
I'm new to lua, and I was trying to create an addon, nothing to much complicated.
i wanted to detect EVENT_ZONE_CHANGED, but can't detect anything.

EVENT_MANAGER:RegisterForEvent(NiceT.name, EVENT_EVENT_ZONE_CHANGED , NiceT.OnPlayerZoneChanged)
EVENT_MANAGER:RegisterForEvent(NiceT.name, EVENT_EVENT_ZONE_CHANGED , NiceT.OnPlayerZoneU)

I'm Using this two event manager, and can't see nothing in debug window(just made a little function that when it's called does just d("Hello1") or d("hello2")
  Reply With Quote
03/17/23, 10:01 AM   #2
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Originally Posted by Shuba00 View Post
Hello,
I'm new to lua, and I was trying to create an addon, nothing to much complicated.
i wanted to detect EVENT_ZONE_CHANGED, but can't detect anything.

EVENT_MANAGER:RegisterForEvent(NiceT.name, EVENT_EVENT_ZONE_CHANGED , NiceT.OnPlayerZoneChanged)
EVENT_MANAGER:RegisterForEvent(NiceT.name, EVENT_EVENT_ZONE_CHANGED , NiceT.OnPlayerZoneU)

I'm Using this two event manager, and can't see nothing in debug window(just made a little function that when it's called does just d("Hello1") or d("hello2")
EVENT_EVENT_ZONE_CHANGED -> EVENT_ZONE_CHANGED
  Reply With Quote
03/17/23, 10:05 AM   #3
Shuba00
 
Shuba00's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2023
Posts: 20
hey,
ty for the reply, but that was just an error copying here, in the addon is without "double" event_
  Reply With Quote
03/17/23, 10:32 AM   #4
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Originally Posted by Shuba00 View Post
hey,
ty for the reply, but that was just an error copying here, in the addon is without "double" event_
Show the code if you want some help then.
  Reply With Quote
03/17/23, 10:43 AM   #5
Shuba00
 
Shuba00's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2023
Posts: 20
Originally Posted by Masteroshi430 View Post
Show the code if you want some help then.
NiceT = {
}
NiceT.name = "NiceT"

function NiceT.Initialize()
d("Thanks for using NiceT!")
NiceT.ZN = GetUnitZone("player") --just trying
d(NiceT.ZN)
EVENT_MANAGER:RegisterForEvent(NiceT.name, EVENT_ZONE_CHANGED, NiceT.OnPlayerZoneChanged)
EVENT_MANAGER:RegisterForEvent(NiceT.name, EVENT_ZONE_UPDATE , NiceT.OnPlayerZoneU)
end
function NiceT.OnAddOnLoaded(event, addonName)
if addonName == NiceT.name then
NiceT.Initialize()
end
end




function NiceT.OnPlayerZoneChanged( eventCode, zoneName, subZoneName, newSubzone, zoneId, subZoneId)
d("HELLO2")
end
function NiceT.OnPlayerZoneU( eventCode, unitTag, newZoneName)
d("HELLO1")
end


EVENT_MANAGER:RegisterForEvent(NiceT.name, EVENT_ADD_ON_LOADED, NiceT.OnAddOnLoaded)
  Reply With Quote
03/17/23, 11:37 AM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,013
Event_zone_changed does not fire for all changed zones afaik, only if you are e.g. inside a city and step out to the worldmap again etc.

Try EVENT_PLAYER_ACTIVATED instead (fires after login, loading screens where you changed a zone etc.). You can do the zone check there, by using
API functions like

Lua Code:
  1. local zoneIndex = GetCurrentMapZoneIndex()
  2. --Either:
  3. local zoneName = zo_strformat(SI_UNIT_NAME, GetZoneNameByIndex(zoneIndex))
  4. --or if you also need the zoneId:
  5. local zoneId = GetZoneId(zoneIndex)
  6. local zoneName = zo_strformat(SI_UNIT_NAME, GetZoneNameById(zoneId))
  7.  
  8. --Parent zoneId is the id of the parent's zone, e.g. if you are inside a delve in Alik'r Desert the zoneId is the one of the delve and the parentZoneId is the one of the zone (e.g. Alik'r)
  9. loca parentZoneId = GetarentZoneId(zoneId)
etc.
  Reply With Quote
03/18/23, 06:54 AM   #7
Shuba00
 
Shuba00's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2023
Posts: 20
Originally Posted by Baertram View Post
Event_zone_changed does not fire for all changed zones afaik, only if you are e.g. inside a city and step out to the worldmap again etc.

Try EVENT_PLAYER_ACTIVATED instead (fires after login, loading screens where you changed a zone etc.). You can do the zone check there, by using
API functions like

Lua Code:
  1. local zoneIndex = GetCurrentMapZoneIndex()
  2. --Either:
  3. local zoneName = zo_strformat(SI_UNIT_NAME, GetZoneNameByIndex(zoneIndex))
  4. --or if you also need the zoneId:
  5. local zoneId = GetZoneId(zoneIndex)
  6. local zoneName = zo_strformat(SI_UNIT_NAME, GetZoneNameById(zoneId))
  7.  
  8. --Parent zoneId is the id of the parent's zone, e.g. if you are inside a delve in Alik'r Desert the zoneId is the one of the delve and the parentZoneId is the one of the zone (e.g. Alik'r)
  9. loca parentZoneId = GetarentZoneId(zoneId)
etc.

TY , this helped me a lot
  Reply With Quote
03/18/23, 04:59 PM   #8
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 666
ZOS has features that show in the UI such as when you are close to the Wayshrine it mentions which Wayshrine. Maybe you enter a city and it says the name of the city. However, when you exit a city it may trigger something for the UI but the zone's information is still for the city.

There are many places where you will not get accurate information because the developers made it do what they want. Because of that it doesn't really return what I might want for a mod like Lorebooks or for whatever you are doing.

So what's this for? Will you be adding map pins using LibMapPins? Depending on what you need I may have some other options.

Last edited by Sharlikran : 03/20/23 at 06:50 AM.
  Reply With Quote
03/20/23, 04:33 AM   #9
remosito
AddOn Author - Click to view addons
Join Date: Dec 2019
Posts: 30
Originally Posted by Baertram View Post
Event_zone_changed does not fire for all changed zones afaik, only if you are e.g. inside a city and step out to the worldmap again etc.

Try EVENT_PLAYER_ACTIVATED instead (fires after login, loading screens where you changed a zone etc.). You can do the zone check there, by using
API functions like

Lua Code:
  1. local zoneIndex = GetCurrentMapZoneIndex()
  2. --Either:
  3. local zoneName = zo_strformat(SI_UNIT_NAME, GetZoneNameByIndex(zoneIndex))
  4. --or if you also need the zoneId:
  5. local zoneId = GetZoneId(zoneIndex)
  6. local zoneName = zo_strformat(SI_UNIT_NAME, GetZoneNameById(zoneId))
  7.  
  8. --Parent zoneId is the id of the parent's zone, e.g. if you are inside a delve in Alik'r Desert the zoneId is the one of the delve and the parentZoneId is the one of the zone (e.g. Alik'r)
  9. loca parentZoneId = GetarentZoneId(zoneId)
etc.
wow...so glad I checked out this thread...had no idea playeractivated is after map zone changes too

thanks baertram
  Reply With Quote
03/21/23, 01:19 PM   #10
Shuba00
 
Shuba00's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2023
Posts: 20
Originally Posted by remosito View Post
wow...so glad I checked out this thread...had no idea playeractivated is after map zone changes too

thanks baertram
i used the function GetPlayerActiveSubzoneName() to get the name of the zone/subzone, and that worked for me
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » don't know how to detect zone change

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