It would help if you'd say what's being done wrong, or not being done that should be.

Assuming it worked correctly before you mod'ed it, what parts did you change? And do you still have the original version which you can incrementally mod until it starts messing up?

But at a glance this looks wrong:

else {
%pirates.play = $iif($right($did,2) < 11,$right($did,1),$gettok($right($did,1),32))
%pirates.play = $+(%pirates.play)
}

The 1st command has wrong syntax, as $gettok should have 3 parameters. And hopefully you're planning on tokenizing more than just the right-most 1 character.

And the 2nd one is a do-nothing command that takes the existing variable and sets it to the same value.