Thread Tools Display Modes
05-29-23, 05:50 AM   #1
Yukka
A Theradrim Guardian
 
Yukka's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2020
Posts: 60
I need your help to combine two addons please [solved]

Hello, I tried to combine these two addons but it seems I cant get it right... Can someone create one addon with these two addons please?

First addon plays a sound when the pet dies and the second addon play a sound when the pet life is about 35%. If possible I prefer when the addon play the sounds from the addon folder just like in the second addon. Thanks.

First addon:

Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterUnitEvent("UNIT_HEALTH", "pet")
  3. f:SetScript("OnEvent", function()
  4.   if not UnitExists("pet") or UnitHealth("pet") == 0 then
  5.     PlaySound(6595)
  6.   end
  7. end)

Second addon:

Lua Code:
  1. local _,PetHealthAlert=...
  2. local Frame=CreateFrame("ScrollingMessageFrame","!PHA",UIParent)   
  3. Frame.Threshold=35
  4. Frame.Warned=false
  5. -- Initialize
  6. function PetHealthAlert:Initialize()   
  7.     Frame:SetWidth(450)
  8.     Frame:SetHeight(200)
  9.     Frame:SetPoint("CENTER",UIParent,"CENTER",0,0) 
  10.     Frame:SetFont("Interface\\AddOns\\!PHA\\Res\\PHA_.TTF",30,"THICKOUTLINE")
  11.     Frame:SetShadowColor(0.00,0.00,0.00,0.75)
  12.     Frame:SetShadowOffset(3.00,-3.00)
  13.     Frame:SetJustifyH("CENTER")    
  14.     Frame:SetMaxLines(2)
  15.     --Frame:SetInsertMode("BOTTOM")
  16.     Frame:SetTimeVisible(2)
  17.     Frame:SetFadeDuration(1)       
  18.     HealthWatch:Update()
  19. end
  20. -- Update health warning
  21. function PetHealthAlert:Update()   
  22.     if(floor((UnitHealth("pet")/UnitHealthMax("pet"))*100)<=Frame.Threshold and Frame.Warned==false)then
  23.         PlaySoundFile("Interface\\AddOns\\!PHA\\Res\\PHA.ogg") 
  24.         Frame:AddMessage("- CRITICAL PET HEALTH -", 1, 0, 0, nil, 3)
  25.         Frame.Warned=true
  26.         return
  27.     end
  28.     if(floor((UnitHealth("pet")/UnitHealthMax("pet"))*100)>Frame.Threshold)then
  29.         Frame.Warned=false
  30.         return
  31.     end
  32. end
  33. -- Handle events
  34. function PetHealthAlert:OnEvent(Event,Arg1,...)
  35.     if(Event=="PLAYER_LOGIN")then
  36.         PetHealthAlert:Initialize()
  37.         return
  38.     end
  39.     if(Event=="UNIT_HEALTH" and Arg1=="pet")then
  40.         PetHealthAlert:Update()
  41.         return
  42.     end
  43. end
  44. Frame:SetScript("OnEvent",PetHealthAlert.OnEvent)
  45. Frame:RegisterEvent("PLAYER_LOGIN")
  46. Frame:RegisterEvent("UNIT_HEALTH")

Last edited by Yukka : 06-06-23 at 09:34 AM.
  Reply With Quote
05-29-23, 08:20 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
Here's what I've come up with along with some tweaks and optimizations.

Lua Code:
  1. local AddOnPath=("Interface\\AddOns\\%s\\"):format(...);--  Dynamically fetch our addon path
  2.  
  3. local Frame=CreateFrame("ScrollingMessageFrame",nil,UIParent)
  4. Frame:SetSize(450,200)
  5. Frame:SetPoint("CENTER")
  6. Frame:SetFont(AddOnPath.."Res\\PHA_.TTF",30,"THICKOUTLINE")
  7. Frame:SetShadowColor(0.00,0.00,0.00,0.75)
  8. Frame:SetShadowOffset(3.00,-3.00)
  9. Frame:SetJustifyH("CENTER")
  10. Frame:SetMaxLines(2)
  11. --Frame:SetInsertMode("BOTTOM")
  12. Frame:SetTimeVisible(2)
  13. Frame:SetFadeDuration(1)
  14.  
  15. Frame:RegisterEvent("PLAYER_LOGIN")
  16. Frame:RegisterUnitEvent("UNIT_PET","player")
  17. Frame:RegisterUnitEvent("UNIT_HEALTH","pet")
  18.  
  19. local LowHealthThreshold=0.35;
  20. local LastHealthValue=0;
  21. Frame:SetScript("OnEvent",function(self)
  22.     if UnitExists("pet") then-- Check if pet exists
  23.         local cur,max=UnitHealth("pet"),UnitHealthMax("pet");
  24.         if cur and max and max>0 then-- Check if we have health data
  25.             if cur<LastHealthValue then--   Has health decreased?
  26.                 if cur<=0 then--    Is pet dead?
  27.                     PlaySoundFile(AddOnPath.."Res\\PHA.ogg")
  28.                     self:AddMessage("- PET DEAD -", 1, 0, 0, nil, 3)
  29.                 elseif cur/max<=LowHealthThreshold then--   Is pet low health?
  30.                     PlaySoundFile(AddOnPath.."Res\\PHA.ogg")
  31.                     self:AddMessage("- CRITICAL PET HEALTH -", 1, 0.5, 0, nil, 3)
  32.                 end
  33.             end
  34.  
  35.             LastHealthValue=cur;--  Update tracking value
  36.         else LastHealthValue=0; end--   Reset to zero if health not available yet
  37.     else LastHealthValue=0; end--   Reset to zero if no pet
  38. end)
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
05-29-23, 09:15 AM   #3
Yukka
A Theradrim Guardian
 
Yukka's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2020
Posts: 60
Nice, thanks but it seems that the sound is playing everytime my pet takes a hit when its life is below 35%. What I wish is the sound playing just once when the life of my pet fall under 35%. Oh I forget to say that I dont need the text thing on the screen, I just need the sounds.

Last edited by Yukka : 05-29-23 at 09:23 AM.
  Reply With Quote
05-29-23, 04:33 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
Lua Code:
  1. local AddOnPath=("Interface\\AddOns\\%s\\"):format(...);--  Dynamically fetch our addon path
  2. local EventFrame=CreateFrame("Frame");
  3.  
  4. EventFrame:RegisterEvent("PLAYER_LOGIN");
  5. EventFrame:RegisterUnitEvent("UNIT_PET","player");
  6. EventFrame:RegisterUnitEvent("UNIT_HEALTH","pet");
  7.  
  8. local LowHealthThreshold=0.35;
  9. local LastHealthValue=0;
  10. EventFrame:SetScript("OnEvent",function(self)
  11.     if UnitExists("pet") then-- Check if pet exists
  12.         local cur,max=UnitHealth("pet"),UnitHealthMax("pet");
  13.         if cur and max and max>0 then-- Check if we have health data
  14.             if cur<=0 and LastHealthValue>0 then--  Is pet dead?
  15.                 PlaySoundFile(AddOnPath.."Res\\PHA.ogg");
  16.             elseif cur/max<=LowHealthThreshold and LastHealthValue/max>LowHealthThreshold then--    Is pet low health?
  17.                 PlaySoundFile(AddOnPath.."Res\\PHA.ogg");
  18.             end
  19.  
  20.             LastHealthValue=cur;--  Update tracking value
  21.         else LastHealthValue=0; end--   Reset to zero if health not available yet
  22.     else LastHealthValue=0; end--   Reset to zero if no pet
  23. end)
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
05-30-23, 06:43 AM   #5
Yukka
A Theradrim Guardian
 
Yukka's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2020
Posts: 60
This time it play the low life sound once, thats nice, but the death sound doesnt play when my pet dies
  Reply With Quote
05-31-23, 12:51 AM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
I'll have to poke around. The one you had before would send a false positive if the pet despawned due to range or pathing issues. If this doesn't bother you, I could put that back in the logic.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
06-01-23, 04:56 AM   #7
Yukka
A Theradrim Guardian
 
Yukka's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2020
Posts: 60
Sure, no worry
  Reply With Quote
06-06-23, 01:37 AM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
Lua Code:
  1. local AddOnPath=("Interface\\AddOns\\%s\\"):format(...);--  Dynamically fetch our addon path
  2. local EventFrame=CreateFrame("Frame");
  3.  
  4. EventFrame:RegisterEvent("PLAYER_LOGIN");
  5. EventFrame:RegisterUnitEvent("UNIT_PET","player");
  6. EventFrame:RegisterUnitEvent("UNIT_HEALTH","pet");
  7.  
  8. local LowHealthThreshold=0.35;
  9. local LastHealthValue=0;
  10. EventFrame:SetScript("OnEvent",function(self)
  11.     local cur,max; if UnitExists("pet") then--  Check if pet exists
  12.         cur,max=UnitHealth("pet"),UnitHealthMax("pet");
  13.     else cur,max=0,1; end-- Process no pet as dead
  14.  
  15.     if cur and max and max>0 then-- Check if we have health data
  16.         if cur<=0 and LastHealthValue>0 then--  Is pet dead?
  17.             PlaySoundFile(AddOnPath.."Res\\PHA.ogg");
  18.         elseif cur/max<=LowHealthThreshold and LastHealthValue/max>LowHealthThreshold then--    Is pet low health?
  19.             PlaySoundFile(AddOnPath.."Res\\PHA.ogg");
  20.         end
  21.  
  22.         LastHealthValue=cur;--  Update tracking value
  23.     else LastHealthValue=0; end--   Reset to zero if health not available yet
  24. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
06-06-23, 09:28 AM   #9
Yukka
A Theradrim Guardian
 
Yukka's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2020
Posts: 60
It works perfect! A huge thanks to you

EDIT: posted the addon here.

Last edited by Yukka : 06-06-23 at 10:58 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » I need your help to combine two addons please


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off