diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index eb5306d..e1fc472 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -706,6 +706,7 @@ ElunaRegister PlayerMethods[] = { "LeaveBattleground", &LuaPlayer::LeaveBattleground }, // :LeaveBattleground([teleToEntryPoint]) - The player leaves the battleground // {"BindToInstance", &LuaPlayer::BindToInstance}, // :BindToInstance() - Binds the player to the current instance { "UnbindInstance", &LuaPlayer::UnbindInstance }, // :UnbindInstance(map, difficulty) - Unbinds the player from an instance + { "UnbindAllInstances", &LuaPlayer::UnbindAllInstances }, // :UnbindAllInstances() - Unbinds the player from all instances { "RemoveFromBattlegroundRaid", &LuaPlayer::RemoveFromBattlegroundRaid }, // :RemoveFromBattlegroundRaid() - Removes the player from a battleground or battlefield raid #if (!defined(TBC) && !defined(CLASSIC)) { "ResetAchievements", &LuaPlayer::ResetAchievements }, // :ResetAchievements() - Resets player�s achievements diff --git a/PlayerMethods.h b/PlayerMethods.h index 97b8d65..33262d1 100644 --- a/PlayerMethods.h +++ b/PlayerMethods.h @@ -2174,11 +2174,19 @@ namespace LuaPlayer return 0; } + /** + * Unbinds the [Player] from his instances except the one he currently is in. + * + * Difficulty is not used on classic. + * + * @param uint32 map = true + * @param uint32 difficulty = 0 + */ int UnbindInstance(Eluna* /*E*/, lua_State* L, Player* player) { uint32 map = Eluna::CHECKVAL(L, 2); #ifndef CLASSIC - uint32 difficulty = Eluna::CHECKVAL(L, 3); + uint32 difficulty = Eluna::CHECKVAL(L, 3, 0); if (difficulty < MAX_DIFFICULTY) player->UnbindInstance(map, (Difficulty)difficulty); @@ -2188,6 +2196,36 @@ namespace LuaPlayer return 0; } + /** + * Unbinds the [Player] from his instances except the one he currently is in. + */ + int UnbindAllInstances(Eluna* /*E*/, lua_State* L, Player* player) + { +#ifdef CLASSIC + Player::BoundInstancesMap& binds = player->GetBoundInstances(); + for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();) + { + if (itr->first != player->GetMapId()) + player->UnbindInstance(itr); + else + ++itr; + } +#else + for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) + { + Player::BoundInstancesMap& binds = player->GetBoundInstances(Difficulty(i)); + for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();) + { + if (itr->first != player->GetMapId()) + player->UnbindInstance(itr, Difficulty(i)); + else + ++itr; + } + } +#endif + return 0; + } + /** * Forces the [Player] to leave a [BattleGround] *