Originally Posted by hisdad
The EVENT_ZONE_CHANGED seems useless, it's triggered going near a wayshrine and its naming doesn't seem consistant with GetMapName()
|
The EVENT_ZONE_CHANGED fires whenever the zone OR subzone changes. Wayshrine counts as a different subzone, and there are several others that fire off. If you're just interested in the main zone, just store that and see if it's changed since the last event to filter it out.
If you are interested in subzones, you could potentially filter out things like wayshrines. However, if someone's running around right along the border between 2 subzones you could have the event firing off a lot. You could filter out repeated changes by something like this:
Lua Code:
local lastTimestamp = 0
local lastZone = ""
local lastSubzone = ""
function onZoneChange()
lastTimestamp = GetTimeStamp()
end
local fuzzAmount= 5 --Number of seconds for zone to be stable
local lastZone = ""
local lastSubzone = ""
--Put this in a 1s or so OnUpdate
function runUpdate()
if lastTimestamp and GetDiffBetweenTimeStamps(GetTimeStamp(), lastTimestamp) > fuzzAmount then
local curZone, curSubzone = GetUnitZone("player")
if curZone ~= lastZone or curSubzone ~= lastSubzone then
--Fire your actual zone change event
end
end
end
Note that it does delay events by 5 seconds, but that's unavoidable if you want to avoid it firing every time you step across a boundry. The higher this 'fuzzAmount', the longer it takes to execute the event, but the fewer repeated fires you'll run across. (Note: it would be possible to fire immediately then block all updates for X seconds. This would need a corrective event update though if someone stepped back into the zone.)