diff --git a/apps/openmw-mp/Cell.cpp b/apps/openmw-mp/Cell.cpp index c46130b8e..de726e0bf 100644 --- a/apps/openmw-mp/Cell.cpp +++ b/apps/openmw-mp/Cell.cpp @@ -127,6 +127,32 @@ mwmp::BaseActor *Cell::getActor(int refNumIndex, int mpNum) return 0; } +void Cell::removeActors(const mwmp::BaseActorList *newActorList) +{ + for (std::vector::iterator it = cellActorList.baseActors.begin(); it != cellActorList.baseActors.end();) + { + int refNumIndex = (*it).refNumIndex; + int mpNum = (*it).mpNum; + + bool foundActor = false; + + for (unsigned int i = 0; i < newActorList->count; i++) + { + mwmp::BaseActor newActor = newActorList->baseActors.at(i); + + if (newActor.refNumIndex == refNumIndex && newActor.mpNum == mpNum) + { + it = cellActorList.baseActors.erase(it); + foundActor = true; + break; + } + } + + if (!foundActor) + it++; + } +} + mwmp::BaseActorList *Cell::getActorList() { return &cellActorList; diff --git a/apps/openmw-mp/Cell.hpp b/apps/openmw-mp/Cell.hpp index d2d34d96b..7b0e8c7a3 100644 --- a/apps/openmw-mp/Cell.hpp +++ b/apps/openmw-mp/Cell.hpp @@ -33,6 +33,7 @@ public: void readActorList(unsigned char packetID, const mwmp::BaseActorList *newActorList); bool containsActor(int refNumIndex, int mpNum); mwmp::BaseActor *getActor(int refNumIndex, int mpNum); + void removeActors(const mwmp::BaseActorList *newActorList); mwmp::BaseActorList *getActorList(); TPlayers getPlayers() const; diff --git a/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp b/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp index e3f02128c..57c1255f0 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp @@ -15,10 +15,17 @@ namespace mwmp void Do(ActorPacket &packet, Player &player, BaseActorList &actorList) override { - // Send this to everyone - packet.Send(true); + Cell *serverCell = CellController::get()->getCell(&actorList.cell); - Script::Call(player.getId(), actorList.cell.getDescription().c_str()); + if (serverCell != nullptr) + { + serverCell->removeActors(&actorList); + + Script::Call(player.getId(), actorList.cell.getDescription().c_str()); + + // Send this to everyone + packet.Send(true); + } } }; }