function spawnpet(p: player, pet: text, equip: number):
set {_a} to nbt compound from "{NoGravity:1b,Small:1,Invisible:1,Invulnerable:1,NoBasePlate:1,DisabledSlots:2039583,Marker:1b}"
set {_n} to nbt compound from "{CustomNameVisible:1,}"
spawn armor stand {_equip} blocks behind {_p} with nbt {_a}
set {_as} to last spawned armor stand
set {_as}'s helmet to {petlist::%{_pet}%}
set name of {_as} to {petname::%{_pet}%}
add {_n} to nbt of {_as}
add {_as} to {petshown::%{_p}%::*}
while 1 is equal to 1:
set {_asl} to location {_equip} blocks behind {_p}
teleport {_as} to location at {_asl}
wait 1 tick
when the armor stands are teleported behind the player they are teleported behind the players head
set {_a} to nbt compound from "{NoGravity:1b,Small:1,Invisible:1,Invulnerable:1,NoBasePlate:1,DisabledSlots:2039583,Marker:1b}"
set {_n} to nbt compound from "{CustomNameVisible:1,}"
spawn armor stand {_equip} blocks behind {_p} with nbt {_a}
set {_as} to last spawned armor stand
set {_as}'s helmet to {petlist::%{_pet}%}
set name of {_as} to {petname::%{_pet}%}
add {_n} to nbt of {_as}
add {_as} to {petshown::%{_p}%::*}
while 1 is equal to 1:
set {_asl} to location {_equip} blocks behind {_p}
teleport {_as} to location at {_asl}
wait 1 tick
when the armor stands are teleported behind the player they are teleported behind the players head