Thursday, April 12, 2012

What am I doing wrong?

[:1]I am trying to make my 1st addon. I am starting very simple, but have spent several hours failing. I do not want to give up, but am stuck.

What I want to do is make 3 states (different heights) for the default chat frame: Normal (for most zones), small (for when I am in combat), and large (for when I am in a city with trade).

What I tried to do was create functions for each state, but I cannot figure out how to call them. I will paste my code. Any help would be appreciated.


Code:
function ChatHeight_City()
DEFAULT_CHAT_FRAME:SetHeight(320,0);
end

function ChatHeight_Normal()
DEFAULT_CHAT_FRAME:SetHeight(120,0);
end

function ChatHeight_Combat()
DEFAULT_CHAT_FRAME:SetHeight(50,0);
end

if (UnitAffectingCombat("player") == 1) then
ChatHeight_Combat();
else
ChatHeight_Normal();
end

I didn't try to the 3rd state because I can't get the 1st two to work. I assume I would need an elseif statement, but am wondering if there is anyway to tell if a zone is a city (i.e. has the trade channel), or will I have to list each city?

Thanks again,

Cogs.|||Ok, I learned a little bit and got the 1st part working:


Code:
local CB = CreateFrame("Frame", "ChatterBox", UIParent) -- create the frame to receive events

function ChatHeight_Normal()
DEFAULT_CHAT_FRAME:SetHeight(120,0);
end

function ChatHeight_Combat()
DEFAULT_CHAT_FRAME:SetHeight(50,0);
end

function CB.OnEvent(self, event)
if event == "PLAYER_REGEN_DISABLED" then
ChatHeight_Combat()
else
ChatHeight_Normal()
end
end

CB:SetScript("OnEvent", CB.OnEvent)
CB:RegisterEvent("PLAYER_REGEN_ENABLED")
CB:RegisterEvent("PLAYER_REGEN_DISABLED")

So that leads me to the problem of checking to see if we are in a city. I can't find any information on this, so if anyone knows if this can be done, or how I might do it otherwise, pls let me know.|||API GetRealZoneText


Code:
local realZoneName = GetRealZoneText();
if (realZoneName == "Ironforge" or realZoneName == "Stormwind" or ...) then
[your code])
end

API EnumerateServerChannels
  1. It will always return true ("Trade") in a city, even if some1 /leave General.

  2. If ur outside a city it will return false ("LocalDefense").


Code:
if (select(2, EnumerateServerChannels())) == "Trade" then
[your code]
end
|||Was messing around with the second bit of code:


Code:
if (select(2, EnumerateServerChannels())) == "Trade" then
[your code]
end

but can't get it to work. Do I need both parts? Where do I put them. Sorry for all teh questions, but I have never coded anything before.

Also, I just realized that in a city when on the targeting dummy, both conditions will be present. Will this cause problems?|||Quote:








but can't get it to work. Do I need both parts?




no, I meant either 1 of them can be used ..


Quote:




Where do I put them.




I forgot to say that they need to react on a Map related event in order to work ..


Quote:




in a city when on the targeting dummy, both conditions will be present. Will this cause problems?




No, the map events fire only when u move between zones or when the zone "changes".

In this example: (Pastie)
  1. Even when your in a city and hit a dummy, the ChatFrame will change from big to normal size.

  2. When u change subzone in a city(map event fires) the chatframe will revert back to big size.


Code:
local CB = CreateFrame("Frame", "ChatterBox", UIParent) -- create the frame to receive events

function ChatHeight_City()
DEFAULT_CHAT_FRAME:SetHeight(320,0);
end

function ChatHeight_Normal()
DEFAULT_CHAT_FRAME:SetHeight(120,0);
end

function ChatHeight_Combat()
DEFAULT_CHAT_FRAME:SetHeight(50,0);
end

function CB.OnEvent(self, event)
if event == "PLAYER_REGEN_DISABLED" then
ChatHeight_Combat()
elseif event == "PLAYER_REGEN_ENABLED" then
ChatHeight_Normal()
end
if (event == "ZONE_CHANGED" or event == "ZONE_CHANGED_INDOORS" or event == "WORLD_MAP_UPDATE") then
if (select(2, EnumerateServerChannels())) == "Trade" then ChatHeight_City()
else ChatHeight_Normal()
end
end
end

CB:SetScript("OnEvent", CB.OnEvent)
CB:RegisterEvent("PLAYER_REGEN_ENABLED")
CB:RegisterEvent("PLAYER_REGEN_DISABLED")
CB:RegisterEvent("ZONE_CHANGED")
CB:RegisterEvent("ZONE_CHANGED_INDOORS")
CB:RegisterEvent("WORLD_MAP_UPDATE")
|||Thanks. I knew it was an event I needed to trigger that function because I could get it to work nicely by calling function with a script via a macro. I must have tried a million things.

- Cogs

No comments:

Post a Comment