• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Getting MMR

Status
Not open for further replies.

Xele

Enthusiast
hi there,

i wanna get 2 mmr from team 1 and team 2 within this script ...
any hint for how to get the second mmr for GetGamesStringData Function will help too much

Code:
class Arena_Spector_NPC : public CreatureScript
{
    public:
        Arena_Spector_NPC() : CreatureScript("Arena_Spector_NPC") { }

    bool OnGossipHello(Player* player, Creature* creature)
    {
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Games: 2v2", GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_LIST_GAMES);
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Games: 3v3", GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_LIST_TOP_GAMES);

        pPlayer->SEND_GOSSIP_MENU(68, creature->GetGUID());
        return true;
    }

    bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 action)
    {
        player->PlayerTalkClass->ClearMenus();

        if (action >= NPC_SPECTATOR_ACTION_LIST_GAMES && action < NPC_SPECTATOR_ACTION_LIST_TOP_GAMES)
        {
            ShowPage(player, action - NPC_SPECTATOR_ACTION_LIST_GAMES, false);
            player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
        }
        else if (action >= NPC_SPECTATOR_ACTION_LIST_TOP_GAMES && action < NPC_SPECTATOR_ACTION_SELECTED_PLAYER)
        {
            ShowPage(player, action - NPC_SPECTATOR_ACTION_LIST_TOP_GAMES, true);
            player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
        }
        else
        {
            uint64 guid = action - NPC_SPECTATOR_ACTION_SELECTED_PLAYER;

            if (Player* target = ObjectAccessor::FindPlayer(guid))
            {
                ChatHandler handler(player->GetSession());
                char const* pTarget = target->GetName().c_str();
                UsingGossip = 1;
                Arena_Spector_Commands::HandleSpectateCommand(&handler, pTarget);
            }
        }

        return true;
    }

    std::string GetClassNameById(uint8 id)
    {
        std::string sClass = "";

        switch (id)
        {
            case CLASS_WARRIOR:      sClass = "Warrior "; break;
            case CLASS_PALADIN:      sClass = "Paladin "; break;
            case CLASS_HUNTER:       sClass = "Hunter ";  break;
            case CLASS_ROGUE:        sClass = "Rogue ";   break;
            case CLASS_PRIEST:       sClass = "Priest ";  break;
            case CLASS_DEATH_KNIGHT: sClass = "D.K ";     break;
            case CLASS_SHAMAN:       sClass = "Shaman ";  break;
            case CLASS_MAGE:         sClass = "Mage ";    break;
            case CLASS_WARLOCK:      sClass = "Warlock "; break;
            case CLASS_DRUID:        sClass = "Druid ";   break;
        }

        return sClass;
    }

    std::string GetGamesStringData(Battleground* team, uint16 mmr)
    {
        std::string teamsMember[BG_TEAMS_COUNT];
        uint32 firstTeamId = 0;

        for (Battleground::BattlegroundPlayerMap::const_iterator itr = team->GetPlayers().begin(); itr != team->GetPlayers().end(); ++itr)
            if (Player* player = ObjectAccessor::FindPlayer(itr->first))
            {
                if (player->isSpectator())
                    continue;

                uint32 team = itr->second.Team;

                if (!firstTeamId)
                    firstTeamId = team;

                teamsMember[firstTeamId == team] += GetClassNameById(player->getClass());
            }

        std::string data = teamsMember[0] + "(";
        std::stringstream ss;
        ss << mmr;
        data += ss.str();
        data += ") -- " + teamsMember[1];

        return data;
    }

    uint64 GetFirstPlayerGuid(Battleground* team)
    {
        for (Battleground::BattlegroundPlayerMap::const_iterator itr = team->GetPlayers().begin(); itr != team->GetPlayers().end(); ++itr)
            if (Player* player = ObjectAccessor::FindPlayer(itr->first))
                return itr->first;

        return 0;
    }

    void ShowPage(Player* player, uint16 page, bool isTop)
    {
        uint16 TypeTwo = 0;
        uint16 TypeThree = 0;
        bool haveNextPage = false;

        for (uint8 i = 0; i <= MAX_BATTLEGROUND_TYPE_ID; ++i)
        {
            if (!sBattlegroundMgr->IsArenaType(BattlegroundTypeId(i)))
                continue;

            BattlegroundData* arenas = sBattlegroundMgr->GetAllBattlegroundsWithTypeId(BattlegroundTypeId(i));

            if (!arenas || arenas->m_Battlegrounds.empty())
                continue;

            for (BattlegroundContainer::const_iterator itr = arenas->m_Battlegrounds.begin(); itr != arenas->m_Battlegrounds.end(); ++itr)
            {
                Battleground* arena = itr->second;

                if (!arena->GetPlayersSize())
                    continue;

                uint16 mmrTwo = arena->GetArenaMatchmakerRatingByIndex(0);
                uint16 mmrThree = arena->GetArenaMatchmakerRatingByIndex(1);

                if (isTop && arena->GetArenaType() == ARENA_TYPE_3v3)
                {
                    TypeThree++;

                    if (TypeThree > (page + 1) * GamesOnPage)
                    {
                        haveNextPage = true;
                        break;
                    }

                    if (TypeThree >= page * GamesOnPage)
                        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, GetGamesStringData(arena, mmrThree), GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_SELECTED_PLAYER + GetFirstPlayerGuid(arena));
                }
                else if (!isTop && arena->GetArenaType() == ARENA_TYPE_2v2)
                {
                    TypeTwo++;

                    if (TypeTwo > (page + 1) * GamesOnPage)
                    {
                        haveNextPage = true;
                        break;
                    }

                    if (TypeTwo >= page * GamesOnPage)
                        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, GetGamesStringData(arena, mmrTwo), GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_SELECTED_PLAYER + GetFirstPlayerGuid(arena));
                }
            }
        }
    }
};
 

Tommy

Founder
I'd edit it, but I don't have spectator to do so. I find the Arena Spectator to be pointless, but that's just me..

Anyway, I can't test the script if I edited it to show more results you're asking for. I don't plan on adding arena spectator to my server because I don't want to spend the whole day doing that. Can you contact the person who made this script? Perhaps they could help..
 
Status
Not open for further replies.
Top