diff --git a/apps/openmw-mp/Script/Functions/Positions.cpp b/apps/openmw-mp/Script/Functions/Positions.cpp index cd2f26f5a..11c5d4f40 100644 --- a/apps/openmw-mp/Script/Functions/Positions.cpp +++ b/apps/openmw-mp/Script/Functions/Positions.cpp @@ -45,6 +45,30 @@ double PositionFunctions::GetPosZ(unsigned short pid) noexcept return player->position.pos[2]; } +double PositionFunctions::GetPreviousCellPosX(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0.0f); + + return player->previousCellPosition.pos[0]; +} + +double PositionFunctions::GetPreviousCellPosY(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0.0f); + + return player->previousCellPosition.pos[1]; +} + +double PositionFunctions::GetPreviousCellPosZ(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0.0f); + + return player->previousCellPosition.pos[2]; +} + void PositionFunctions::GetRot(unsigned short pid, float *x, float *y, float *z) noexcept { *x = 0.00; diff --git a/apps/openmw-mp/Script/Functions/Positions.hpp b/apps/openmw-mp/Script/Functions/Positions.hpp index 1924525e1..ae8b8a768 100644 --- a/apps/openmw-mp/Script/Functions/Positions.hpp +++ b/apps/openmw-mp/Script/Functions/Positions.hpp @@ -9,6 +9,10 @@ {"GetPosY", PositionFunctions::GetPosY},\ {"GetPosZ", PositionFunctions::GetPosZ},\ \ + {"GetPreviousCellPosX", PositionFunctions::GetPreviousCellPosX},\ + {"GetPreviousCellPosY", PositionFunctions::GetPreviousCellPosY},\ + {"GetPreviousCellPosZ", PositionFunctions::GetPreviousCellPosZ},\ + \ {"GetRot", PositionFunctions::GetRot},\ {"GetRotX", PositionFunctions::GetRotX},\ {"GetRotZ", PositionFunctions::GetRotZ},\ @@ -59,6 +63,30 @@ public: */ static double GetPosZ(unsigned short pid) noexcept; + /** + * \brief Get the X position of a player from before their latest cell change. + * + * \param pid The player ID. + * \return The X position. + */ + static double GetPreviousCellPosX(unsigned short pid) noexcept; + + /** + * \brief Get the Y position of a player from before their latest cell change. + * + * \param pid The player ID. + * \return The Y position. + */ + static double GetPreviousCellPosY(unsigned short pid) noexcept; + + /** + * \brief Get the Z position of a player from before their latest cell change. + * + * \param pid The player ID. + * \return The Z position. + */ + static double GetPreviousCellPosZ(unsigned short pid) noexcept; + /** * \brief Assign the player's rotational coordinate values to the variables passed as * parameters. diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index d09575267..f3c1ec6c6 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -375,6 +375,7 @@ void LocalPlayer::updateCell(bool forceUpdate) } cell = *ptrCell; + previousCellPosition = position; // Make sure the position is updated before a cell packet is sent, or else // cell change events in server scripts will have the wrong player position diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 4f4bdbd4b..1f971d285 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -235,6 +235,7 @@ namespace mwmp ESM::Position position; ESM::Position direction; + ESM::Position previousCellPosition; ESM::Cell cell; ESM::NPC npc; ESM::NpcStats npcStats; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerCellChange.cpp b/components/openmw-mp/Packets/Player/PacketPlayerCellChange.cpp index acc5415df..4bb05b1a8 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerCellChange.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerCellChange.cpp @@ -20,6 +20,8 @@ void mwmp::PacketPlayerCellChange::Packet(RakNet::BitStream *bs, bool send) RW(player->cell.mData, send, 1); RW(player->cell.mName, send, 1); + RW(player->previousCellPosition.pos, send, 1); + RW(player->isChangingRegion, send); if (player->isChangingRegion)