Fix targeting/distance issues in the SQL instead of Lua

Lua script cleaned up to reflect this. Note: there appears
to be a bug in core where TARGET_PLAYER_PARTY lets you target
yourself as long as you're in a party. Per teschnei that will be handled outside of the scope of this request.