diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp index d88b0d53..bed9967c 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp @@ -960,7 +960,28 @@ PyObject* cyMisc::GetLocalPlayer() 0.0 ); } +///////////////////////////////////////////////////////////////////////////// +// +// Function : GetNPC +// PARAMETERS : npcID - is the ID of an NPC +// +// PURPOSE : Returns a pySceneobject of an NPC +// +PyObject* cyMisc::GetNPC(int npcID) +{ + plSceneObject *so = plSceneObject::ConvertNoRef(plNetClientMgr::GetInstance()->GetNPC(npcID)); + if ( so ) + return pySceneObject::New(so->GetKey()); + + char* errmsg = "NPC not found"; + PyErr_SetString(PyExc_NameError, errmsg); + PYTHON_RETURN_ERROR; +} +PyObject* cyMisc::GetNPCCount() +{ + return PyInt_FromLong(plNetClientMgr::GetInstance()->NPCKeys().size()); +} #if 1 #include "plStatusLog/plStatusLog.h" diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h index 4f9090ba..5ebfde6f 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h @@ -439,6 +439,16 @@ public: static uint32_t GetMaxListenListSize(); static float GetMaxListenDistSq(); + ///////////////////////////////////////////////////////////////////////////// + // + // Function : GetNPC + // PARAMETERS : npcID - is the ID of a NPC + // + // PURPOSE : Returns a pySceneobject of a NPC + // + static PyObject* GetNPC(int npcID); + static PyObject* GetNPCCount(); + ///////////////////////////////////////////////////////////////////////////// // // Function : SendRTChat diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp index 923ffc91..6275eccd 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp @@ -188,6 +188,23 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtGetClientIDFromAvatarKey, args, "Params: avata return PyInt_FromLong(cyMisc::GetClientIDFromAvatarKey(*key)); } +PYTHON_GLOBAL_METHOD_DEFINITION(PtGetNPCByID, args, "This will return the NPC with a specific ID") +{ + int npcID; + if (!PyArg_ParseTuple(args, "i", &npcID)) + { + PyErr_SetString(PyExc_TypeError, "PtGetNPCByID expects an integer"); + PYTHON_RETURN_ERROR; + } + + return cyMisc::GetNPC(npcID); +} + +PYTHON_GLOBAL_METHOD_DEFINITION_NOARGS(PtGetNPCCount, "Returns the number of NPCs in the current age") +{ + return cyMisc::GetNPCCount(); +} + PYTHON_GLOBAL_METHOD_DEFINITION_NOARGS(PtGetNumRemotePlayers, "Returns the number of remote players in this Age with you.") { return PyInt_FromLong(cyMisc::GetNumRemotePlayers()); @@ -507,6 +524,8 @@ void cyMisc::AddPlasmaMethods(std::vector &methods) PYTHON_GLOBAL_METHOD_NOARGS(methods, PtMaxListenDistSq); PYTHON_GLOBAL_METHOD(methods, PtGetAvatarKeyFromClientID); PYTHON_GLOBAL_METHOD(methods, PtGetClientIDFromAvatarKey); + PYTHON_GLOBAL_METHOD(methods, PtGetNPCByID); + PYTHON_GLOBAL_METHOD_NOARGS(methods, PtGetNPCCount); PYTHON_GLOBAL_METHOD_NOARGS(methods, PtGetNumRemotePlayers); PYTHON_GLOBAL_METHOD(methods, PtValidateKey);