Quantcast
WoWInterface - View Single Post - Detecting World PvP Zones
View Single Post
06-18-15, 02:19 PM   #20
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
Just went to Gurubashi Arena and ZONE_CHANGED triggers when you enter or leave the circular center area (the arena). In some points if you are very close to the edge you can cross the zone without going to the ground level but I don't think that is relevant.

UNIT_FACTION also triggers but when you leave the center area you still keep the FFA status for a while. Maybe you can use UnitIsPVPFreeForAll("player") when UNIT_FACTION triggers (arg1 being "player"), to check if you are or not in a FFA combat. That would avoid you to use ZONE_CHANGED.

I still prefer my solution (for world pvp) because BATTLEFIELD_MGR_* triggers only rarely and most of times will be relevant for your problem. For battlegrounds and arenas all you need to do is call IsInInstance() when PLAYER_ENTERING_WORLD triggers (I know you are already doing that). So apparently is totally possible to avoid using ZONE_CHANGED and ZONE_CHANGED_NEW_AREA.

Here my complete solution attempt:
Lua Code:
  1. local Ashran_instance_id = 1191
  2. local Ashran_battle_id = 24
  3.  
  4. local f = CreateFrame("Frame")
  5.  
  6. f:SetScript("OnEvent",function(self,event,...)
  7.     local pvp_old = f.pvp
  8.     if event=="PLAYER_ENTERING_WORLD" then
  9.         local _,instance_type = IsInInstance()
  10.         if instance_type=="pvp" or instance_type=="arena" then
  11.             f.instance = true
  12.         else
  13.             f.instance = false         
  14.             local _,_,_,_,_,_,_,instance_id = GetInstanceInfo()
  15.             if instance_id==Ashran_instance_id or IsInActiveWorldPVP() then
  16.                 f.world = true
  17.             else
  18.                 f.world = false
  19.             end
  20.         end
  21.     elseif event=="BATTLEFIELD_MGR_ENTERED" then
  22.         f.world = true
  23.     elseif event=="BATTLEFIELD_MGR_EJECTED" then
  24.         f.world = false
  25.     elseif event=="BATTLEFIELD_MGR_STATE_CHANGE" then
  26.         if ...~=Ashran_battle_id and IsInActiveWorldPVP()==false then
  27.             f.world = false
  28.         end
  29.     elseif event=="UNIT_FACTION" and ...=="player" then
  30.         if UnitIsPVPFreeForAll("player")==true then
  31.             f.ffa = true
  32.         else
  33.             f.ffa = false
  34.         end
  35.     end
  36.     f.pvp = f.instance or f.world or f.ffa or false
  37.     if f.pvp~=pvp_old then
  38.         print("pvp area:",f.pvp)
  39.     end
  40. end)
  41. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  42. f:RegisterEvent("BATTLEFIELD_MGR_ENTERED")
  43. f:RegisterEvent("BATTLEFIELD_MGR_EJECTED")
  44. f:RegisterEvent("BATTLEFIELD_MGR_STATE_CHANGE")
  45. f:RegisterEvent("UNIT_FACTION")
__________________
"In this world nothing can be said to be certain, except that fractional reserve banking is a Ponzi scheme and that you won't believe it." - Mandrill

Last edited by Banknorris : 06-19-15 at 06:37 AM.
  Reply With Quote