public INPC FindNPCByBaseId(int baseId, bool nearest = false) { allNpcList.Clear(); npcList.Clear(); EntityManager.Instance().FindAllEntity <INPC>(ref allNpcList); for (int i = 0; i < allNpcList.Count; ++i) { INPC npc = allNpcList[i]; if (npc.GetProp((int)EntityProp.BaseID) == baseId && !npc.IsDead()) { if (!nearest) { return(npc); } else { npcList.Add(npc); } } } if (m_ClientGlobal.MainPlayer == null) { return(null); } Vector3 pos = m_ClientGlobal.MainPlayer.GetPos(); INPC getNpc = null; float fMinDis = 5000000.0f; for (int i = 0; i < npcList.Count; i++) { float sqrlen = (npcList[i].GetPos() - pos).sqrMagnitude; if (sqrlen < fMinDis) { fMinDis = sqrlen; getNpc = npcList[i]; } } return(getNpc); }