To do this, You would need to Find code for Checking the Healthbar of a pet (Pixel Scanning through EUO), and then after that its pretty straight forward
set %Pet XXXXX ; Id for pet
While Penguins <> Leprachauns
{
Gosub Get_Health ; <- The code to actually check health you would have to get from someone else.
if %Pet_Hits < 80
{
Finditem (Heal Potion Type) C_ , #Backpackid
if #findcnt = 0
Halt
set #lobjectid #Findid
event macro 17 0
Target 30
set #ltargetid %Pet
set #ltargetkind 1
Event macro 22 0
wait 20
}
}