From 2f98f31af25d8d3333ed8e90cb8a9d4cd60d39e5 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 2 Sep 2021 15:44:11 +0200 Subject: [PATCH] [General] Use model variable already included in PlayerBaseInfo packets The variable has been included since TES3MP's earliest proof of concept, but never used for anything. It is now possible to get and set it, due to semi-popular demand. --- apps/openmw-mp/Script/Functions/Stats.cpp | 19 +++++++++++++++++++ apps/openmw-mp/Script/Functions/Stats.hpp | 19 +++++++++++++++++++ apps/openmw/mwmp/LocalPlayer.cpp | 1 + 3 files changed, 39 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 71e48196c..54d434086 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -104,6 +104,14 @@ int StatsFunctions::GetIsMale(unsigned short pid) noexcept return player->npc.isMale(); } +const char* StatsFunctions::GetModel(unsigned short pid) noexcept +{ + Player* player; + GET_PLAYER(pid, player, 0); + + return player->npc.mModel.c_str(); +} + const char *StatsFunctions::GetBirthsign(unsigned short pid) noexcept { Player *player; @@ -327,6 +335,17 @@ void StatsFunctions::SetIsMale(unsigned short pid, int state) noexcept player->npc.setIsMale(state > 0 ? true : false); } +void StatsFunctions::SetModel(unsigned short pid, const char *model) noexcept +{ + Player* player; + GET_PLAYER(pid, player, ); + + if (player->npc.mModel == model) + return; + + player->npc.mModel = model; +} + void StatsFunctions::SetBirthsign(unsigned short pid, const char *sign) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Stats.hpp b/apps/openmw-mp/Script/Functions/Stats.hpp index 78a626118..30cd260fa 100644 --- a/apps/openmw-mp/Script/Functions/Stats.hpp +++ b/apps/openmw-mp/Script/Functions/Stats.hpp @@ -14,6 +14,7 @@ {"GetHead", StatsFunctions::GetHead},\ {"GetHair", StatsFunctions::GetHairstyle},\ {"GetIsMale", StatsFunctions::GetIsMale},\ + {"GetModel", StatsFunctions::GetModel},\ {"GetBirthsign", StatsFunctions::GetBirthsign},\ \ {"GetLevel", StatsFunctions::GetLevel},\ @@ -45,6 +46,7 @@ {"SetHead", StatsFunctions::SetHead},\ {"SetHair", StatsFunctions::SetHairstyle},\ {"SetIsMale", StatsFunctions::SetIsMale},\ + {"SetModel", StatsFunctions::SetModel},\ {"SetBirthsign", StatsFunctions::SetBirthsign},\ {"SetResetStats", StatsFunctions::SetResetStats},\ \ @@ -181,6 +183,14 @@ public: */ static int GetIsMale(unsigned short pid) noexcept; + /** + * \brief Get the model of a player. + * + * \param pid The player ID. + * \return The model of the player. + */ + static const char* GetModel(unsigned short pid) noexcept; + /** * \brief Get the birthsign of a player. * @@ -383,6 +393,15 @@ public: */ static void SetIsMale(unsigned short pid, int state) noexcept; + /** + * \brief Set the model of a player. + * + * \param pid The player ID. + * \param name The new model of the player. + * \return void + */ + static void SetModel(unsigned short pid, const char *model) noexcept; + /** * \brief Set the birthsign of a player. * diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index f344ca1f8..99010da5f 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -939,6 +939,7 @@ void LocalPlayer::setCharacter() player.mRace = npc.mRace; player.mHead = npc.mHead; player.mHair = npc.mHair; + player.mModel = npc.mModel; player.setIsMale(npc.isMale()); world->createRecord(player);