About gems see this How to get GEMS, Stuck in Sarven Desert
the while loop you have is some kind of while True loop
If you have 800 health -> 800>200 then 400>100 then… you die
while (hero.health > hero.health / 4)
replace with
hero.health > hero.maxHealth / 4: