copied some npc code from sdk