change pid to idx in battle.html