Concerning the cure spells causing damage to undead, you could set a new attribute- say, "anti-undead"- and assign it to all cure spells. Then you assign the element efficiency of "anti-undead" on your undeads to "F". This way, the cure to the party heals HP and the cures to undead cause HP loss. I'm using a different system in my own project, since I chose not to use a targeting script like the one you have, but I just tested it out and it seems to work. Whatcha think?