You could use the [petbattle] macro conditional that others of us requested for just this sort of thing -
Code:
local frame = CreateFrame("Frame", nil, UIParent, "SecureHandlerStateTemplate")
RegisterStateDriver(frame, "petbattle", "[petbattle] dostuff1; [nopetbattle] dostuff2")
frame:SetAttribute("_onstate-petbattle", [[
if (self:GetAttribute("state-petbattle") == "dostuff1") then
--do stuff
elseif (self:GetAttribute("state-petbattle") == "dostuff2") then
-- do stuff
end
]])