[General] Record and get player positions before their last cell change

0.6.1
David Cernat 8 years ago
parent fbec0d9443
commit 0e2038f045

@ -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;

@ -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.

@ -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

@ -235,6 +235,7 @@ namespace mwmp
ESM::Position position;
ESM::Position direction;
ESM::Position previousCellPosition;
ESM::Cell cell;
ESM::NPC npc;
ESM::NpcStats npcStats;

@ -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)

Loading…
Cancel
Save