-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZHunterButtonPet.lua
executable file
·192 lines (182 loc) · 7.53 KB
/
ZHunterButtonPet.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
ZHunterMod_Saved["ZHunterButtonPet"] = {}
ZHunterMod_Saved["ZHunterButtonPet"]["pet"] = {}
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["happiness"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["status"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["dead"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["spells"] = {ZHUNTER_PET_EYES, ZHUNTER_PET_DISMISS, ZHUNTER_PET_MEND,
ZHUNTER_PET_FEED, ZHUNTER_PET_CALL, ZHUNTER_PET_REVIVE}
ZHunterMod_Saved["ZHunterButtonPet"]["rows"] = 1
ZHunterMod_Saved["ZHunterButtonPet"]["count"] = 6
ZHunterMod_Saved["ZHunterButtonPet"]["horizontal"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["vertical"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["firstbutton"] = "RIGHT"
ZHunterMod_Saved["ZHunterButtonPet"]["tooltip"] = 1
ZHunterMod_Saved["ZHunterButtonPet"]["parent"] = {}
ZHunterMod_Saved["ZHunterButtonPet"]["parent"]["size"] = 36
ZHunterMod_Saved["ZHunterButtonPet"]["parent"]["hide"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["parent"]["circle"] = 1
ZHunterMod_Saved["ZHunterButtonPet"]["children"] = {}
ZHunterMod_Saved["ZHunterButtonPet"]["children"]["size"] = 36
ZHunterMod_Saved["ZHunterButtonPet"]["children"]["hideonclick"] = 1
function ZHunterButtonPet_OnLoad()
this:RegisterEvent("VARIABLES_LOADED")
end
function ZHunterButtonPet_OnEvent()
if event == "VARIABLES_LOADED" then
if UnitClass("player") ~= ZHUNTER_HUNTER then
ZHunterButtonPet:UnregisterAllEvents()
ZHunterButtonPet:Hide()
return
end
ZSpellButton_CreateChildren(ZHunterButtonPet, "ZHunterButtonPet", 11)
ZHunterButtonPet.found = ZSpellButton_SetButtons(ZHunterButtonPet, ZHunterMod_Saved["ZHunterButtonPet"]["spells"])
if ZHunterButtonPet.found > 0 and ZHunterButtonPet.found < ZHunterMod_Saved["ZHunterButtonPet"]["count"] then
ZHunterMod_Saved["ZHunterButtonPet"]["count"] = ZHunterButtonPet.found
end
ZHunterButtonPet.options = ZHunterButtonPetOptions
ZHunterButtonPet.beforeclick = ZHunterButtonPetAdjustment_BeforeClick
ZHunterButtonPetAdjustment = CreateFrame("Frame", "ZHunterButtonPetAdjustment")
ZHunterButtonPetAdjustment:RegisterEvent("UNIT_HEALTH")
ZHunterButtonPetAdjustment:RegisterEvent("UNIT_HAPPINESS")
ZHunterButtonPetAdjustment:RegisterEvent("UNIT_PET")
ZHunterButtonPetAdjustment:RegisterEvent("PLAYER_ENTERING_WORLD")
ZHunterButtonPetAdjustment:SetScript("OnEvent", ZHunterButtonPetAdjustment_OnEvent)
ZHunterButtonPet_Tooltip = CreateFrame("GameTooltip", "ZHunterButtonPet_Tooltip", nil, "GameTooltipTemplate")
ZHunterButtonPet_SetupOptions()
ZHunterButtonPet_SetupSizeAndPosition()
end
end
function ZHunterButtonPet_SetupSizeAndPosition()
ZSpellButton_SetSize(ZHunterButtonPet, ZHunterMod_Saved["ZHunterButtonPet"]["parent"]["size"])
ZSpellButton_SetSize(ZHunterButtonPet, ZHunterMod_Saved["ZHunterButtonPet"]["children"]["size"], 1)
ZSpellButton_SetExpandDirection(ZHunterButtonPet, ZHunterMod_Saved["ZHunterButtonPet"]["firstbutton"])
ZSpellButton_ArrangeChildren(ZHunterButtonPet, ZHunterMod_Saved["ZHunterButtonPet"]["rows"],
ZHunterMod_Saved["ZHunterButtonPet"]["count"], ZHunterMod_Saved["ZHunterButtonPet"]["horizontal"],
ZHunterMod_Saved["ZHunterButtonPet"]["vertical"])
end
function ZHunterButtonPet_Reset()
ZHunterMod_Saved["ZHunterButtonPet"] = {}
ZHunterMod_Saved["ZHunterButtonPet"]["pet"] = {}
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["happiness"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["status"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["dead"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["spells"] = {ZHUNTER_PET_EYES, ZHUNTER_PET_DISMISS, ZHUNTER_PET_MEND,
ZHUNTER_PET_FEED, ZHUNTER_PET_CALL, ZHUNTER_PET_REVIVE}
ZHunterMod_Saved["ZHunterButtonPet"]["rows"] = 1
ZHunterMod_Saved["ZHunterButtonPet"]["count"] = 6
ZHunterMod_Saved["ZHunterButtonPet"]["horizontal"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["vertical"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["firstbutton"] = "RIGHT"
ZHunterMod_Saved["ZHunterButtonPet"]["tooltip"] = 1
ZHunterMod_Saved["ZHunterButtonPet"]["parent"] = {}
ZHunterMod_Saved["ZHunterButtonPet"]["parent"]["size"] = 36
ZHunterMod_Saved["ZHunterButtonPet"]["parent"]["hide"] = nil
ZHunterMod_Saved["ZHunterButtonPet"]["parent"]["circle"] = 1
ZHunterMod_Saved["ZHunterButtonPet"]["children"] = {}
ZHunterMod_Saved["ZHunterButtonPet"]["children"]["size"] = 36
ZHunterMod_Saved["ZHunterButtonPet"]["children"]["hideonclick"] = 1
end
function IsPetDead()
return ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["dead"]
end
function ZHunterButtonPetAdjustment_BeforeClick()
if CursorHasItem() then
DropItemOnUnit("pet")
end
end
function ZHunterButtonPetAdjustment_OnEvent()
local health, happiness, status, dead
if arg1 == "pet" then
if event == "UNIT_HAPPINESS" then
happiness = GetPetHappiness()
if happiness == ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["happiness"] then
return
end
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["happiness"] = happiness
elseif event == "UNIT_HEALTH" then
health = UnitHealth("pet")
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["dead"] = nil
if health == 0 then
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["dead"] = 1
elseif health / UnitHealthMax("pet") > 0.75 then
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["status"] = 2
else
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["status"] = 1
end
end
elseif event == "UNIT_PET" and arg1 == "player" then
if not UnitExists("pet") then
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["status"] = nil
else
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["status"] = 2
if UnitHealth("pet") > 0 then
ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["dead"] = nil
end
end
end
local spells = {}
local name
local choice
for i=1, ZHunterButtonPet.count do
local button
button = getglobal(ZHunterButtonPet.name..i)
if button.id then
name = GetSpellName(button.id, "spell")
spells[name] = button
if not choice and (name == ZHUNTER_PET_DISMISS or name == ZHUNTER_PET_EYES) then
choice = button
end
end
end
status = ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["status"]
happiness = ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["happiness"]
dead = ZHunterMod_Saved["ZHunterButtonPet"]["pet"]["dead"]
local id = ZHunterButtonPet.id
name = nil
if dead then
name = ZHUNTER_PET_REVIVE
elseif not status then
name = ZHUNTER_PET_CALL
elseif status == 1 then
name = ZHUNTER_PET_MEND
elseif happiness ~= 3 then
name = ZHUNTER_PET_FEED
elseif choice then
id = choice.id
end
if name and spells[name] then
id = spells[name].id
end
ZHunterButtonPet.id = id
ZSpellButton_UpdateButton(ZHunterButtonPet)
ZSpellButton_UpdateCooldown(ZHunterButtonPet)
if GameTooltip:IsOwned(ZHunterButtonPet) then
ZSpellButtonParent_OnEnter(ZHunterButtonPet)
end
end
function ZHunterButtonPet_KeyBinding(index)
local button
if index then
button = getglobal("ZHunterButtonPet"..index)
else
button = ZHunterButtonPet
end
if button.id then
CastSpell(button.id, "spell")
if ZHunterButtonPet.hideonclick then
ZHunterButtonPet.children:Hide()
end
end
end
SLASH_ZHunterButtonPet1 = "/ZPet"
SlashCmdList["ZHunterButtonPet"] = function(msg)
if msg == "reset" then
ZHunterButtonPet_Reset()
ZHunterButtonPet:ClearAllPoints()
ZHunterButtonPet:SetPoint("CENTER", UIParent, "CENTER", 0, 60)
elseif msg == "options" then
ZHunterButtonPet.options:Show()
else
DEFAULT_CHAT_FRAME:AddMessage("Possible Commands: \"options\", \"reset\"", 0, 1, 1)
end
end