From 3438061b55dda1874e4d8c6728293f0b61fdb278 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 4 Jul 2018 04:26:44 +0300 Subject: [PATCH] [Server] Add script function for getting a summoner's pid Additionally, fix typos in the comments for other script functions relating to summoners. --- apps/openmw-mp/Script/Functions/Objects.cpp | 8 ++++++++ apps/openmw-mp/Script/Functions/Objects.hpp | 21 +++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Objects.cpp b/apps/openmw-mp/Script/Functions/Objects.cpp index 2fa5a6852..f965f8a15 100644 --- a/apps/openmw-mp/Script/Functions/Objects.cpp +++ b/apps/openmw-mp/Script/Functions/Objects.cpp @@ -128,6 +128,14 @@ bool ObjectFunctions::DoesObjectHavePlayerSummoner(unsigned int i) noexcept return readObjectList->baseObjects.at(i).master.isPlayer; } +unsigned int ObjectFunctions::GetObjectSummonerPid(unsigned int i) noexcept +{ + Player *player = Players::getPlayer(readObjectList->baseObjects.at(i).master.guid); + + if (player != nullptr) + return player->getId(); +} + const char *ObjectFunctions::GetObjectSummonerRefId(unsigned int i) noexcept { return readObjectList->baseObjects.at(i).master.refId.c_str(); diff --git a/apps/openmw-mp/Script/Functions/Objects.hpp b/apps/openmw-mp/Script/Functions/Objects.hpp index 519bcc92c..d1037dc70 100644 --- a/apps/openmw-mp/Script/Functions/Objects.hpp +++ b/apps/openmw-mp/Script/Functions/Objects.hpp @@ -28,6 +28,7 @@ {"GetObjectSummonState", ObjectFunctions::GetObjectSummonState},\ {"GetObjectSummonDuration", ObjectFunctions::GetObjectSummonDuration},\ {"DoesObjectHavePlayerSummoner", ObjectFunctions::DoesObjectHavePlayerSummoner},\ + {"GetObjectSummonerPid", ObjectFunctions::GetObjectSummonerPid},\ {"GetObjectSummonerRefId", ObjectFunctions::GetObjectSummonerRefId},\ {"GetObjectSummonerRefNumIndex", ObjectFunctions::GetObjectSummonerRefNumIndex},\ {"GetObjectSummonerMpNum", ObjectFunctions::GetObjectSummonerMpNum},\ @@ -290,13 +291,21 @@ public: */ static bool DoesObjectHavePlayerSummoner(unsigned int i) noexcept; + /** + * \brief Get the player ID of the summoner of the object at a certain index in the read object + * list's object changes. + * + * \param i The index of the object. + * \return The player ID of the summoner. + */ + static unsigned int GetObjectSummonerPid(unsigned int i) noexcept; /** * \brief Get the refId of the summoner of the object at a certain index in the read object * list's object changes. * - * \param i The index of the summoner. - * \return The refNumIndex. + * \param i The index of the object. + * \return The refId of the summoner. */ static const char *GetObjectSummonerRefId(unsigned int i) noexcept; @@ -304,8 +313,8 @@ public: * \brief Get the refNumIndex of the summoner of the object at a certain index in the read object * list's object changes. * - * \param i The index of the summoner. - * \return The refNumIndex. + * \param i The index of the object. + * \return The refNumIndex of the summoner. */ static int GetObjectSummonerRefNumIndex(unsigned int i) noexcept; @@ -313,8 +322,8 @@ public: * \brief Get the mpNum of the summoner of the object at a certain index in the read object list's * object changes. * - * \param i The index of the summoner. - * \return The mpNum. + * \param i The index of the object. + * \return The mpNum of the summoner. */ static int GetObjectSummonerMpNum(unsigned int i) noexcept;