Your first question was a bit too vague to help with. But this question is specific enough for some guidance.
1 minute ago, Sylon87 said:
what i'm wondering in is witch is the best way to build a system where every player/npc will now witch character is the nearest one
Here's an algorithm assuming each actor (NPC or player) knows where its position is.
// loop through each actor: currentActor (I assume you have a list of these)
// for each actor, loop through all the other actors: otherActors
// compute the distance and store it in the currentActor
That's the basics to get that working. Once you have that working you can worry about optimizations. Like realizing once you've computed the distance from currentActor to otherActor you also know the distance from otherActor to currentActor. That means your outer loop goes from 0...n, but your inner loop can go from currentActor's index to n.