I am going to go on limb here and try to help.
It's a little bit hard to follow what is going on, but I think what is happening is that the function NPCInteraction2 is not doing what you expect.
Inside of it you are checking for an NPCID property of the NPCINTERACT family but the check is not against the instance of the family that was picked when the function was called. I will check with Ashley why is that, I have a feeling that is the expected behaviour, but I will ask him to be sure.
So what ends up happening is that all that state for showing a dialogue is being set on the wrong instance.
To get around that, I passed the UID of the picked instance in the call to NPCInteraction2 and inside of it I added an extra condition to Pick by comparison in addition to the NPCID condition. That way you can be sure that state is set in the correct instance.
Something similar then happens in the call to FormatDialogue, so to get around that I added a few arguments.
In the calls to DialogueLine, FormatDialogue and PickAnswer I pass in an additional argument with the IID of NPCINTERACT family. I did that so that I would be able to use that value in FormatDialogue to use the expressions NPCINTERACT(IID).itemname and NPCINTERACT(IID).interactname and ensure the function is using the correct instance values every time.
NOTE that UID and IID are different things.
All of this is quite hard to explain, but I think I covered everything.