Improved performance

Improved functions to check near npcs
Delete npc with a distance > 8000, add npcs with a distance < 7500
Improved AI in ScriptFunctions