• 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] Whats Wrong ?

Status
Not open for further replies.

Xele

Enthusiast
hi guys

something within script doesnt work currently
arena spec npc will not show the games are currently active

trinitycore
Code:
enum NpcSpectatorAtions
{
    LISTGAMESL = 1000,
    LISTGAMESH = 1800,
    SELECTED   = 3000
};

const uint16 TopGamesRating = 1800;
const uint8  GamesOnPage    = 15;

class Npc_Arena_Spector : public CreatureScript
{
	public:
		Npc_Arena_Spector() : CreatureScript("Npc_Arena_Spector") { }

	bool OnGossipHello(Player* player, Creature* creature)
	{
		player->ADD_GOSSIP_ITEM(0, "Rating +1800", GOSSIP_SENDER_MAIN, LISTGAMESH);
		player->ADD_GOSSIP_ITEM(0, "Rating +1000", GOSSIP_SENDER_MAIN, LISTGAMESL);

		player->PlayerTalkClass->SendGossipMenu(68, creature->GetGUID());
		return true;
	}

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

		if (action >= LISTGAMESL && action < LISTGAMESH)
		{
			ShowPage(player, action - LISTGAMESL, false);
			player->PlayerTalkClass->SendGossipMenu(68, creature->GetGUID());
		}
		else if (action >= LISTGAMESH)
		{
			ShowPage(player, action - LISTGAMESH, true);
			player->PlayerTalkClass->SendGossipMenu(68, creature->GetGUID());
		}
		else
		{
			uint64 guid = action - SELECTED;

			if (Player* target = ObjectAccessor::FindPlayer(guid))
			{
				ChatHandler handler(player->GetSession());	
				std::string str = target->GetName();
				char* pTarget;
				std::strcpy (pTarget, str.c_str());
				Arena_Spector_Command::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 = "Pala ";    break;
			case CLASS_HUNTER:       sClass = "Hunt ";    break;
			case CLASS_ROGUE:        sClass = "Rogue ";   break;
			case CLASS_PRIEST:       sClass = "Priest ";  break;
			case CLASS_DEATH_KNIGHT: sClass = "DK ";      break;
			case CLASS_SHAMAN:       sClass = "Shama ";   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 highGames  = 0;
		uint16 lowGames   = 0;
		bool haveNextPage = false;

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

			BattlegroundContainer bgs = sBattlegroundMgr->GetBattlegroundsByType((BattlegroundTypeId)i);
			for (BattlegroundContainer::iterator itr = bgs.begin(); itr != bgs.end(); ++itr)
			{
				Battleground* arena = itr->second;

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

				uint16 mmr = arena->GetArenaMatchmakerRatingByIndex(0) + arena->GetArenaMatchmakerRatingByIndex(1);
				mmr /= 2;

				if (isTop && mmr >= TopGamesRating)
				{
					highGames++;

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

					if (highGames >= page * GamesOnPage)
						player->ADD_GOSSIP_ITEM(9, GetGamesStringData(arena, mmr), GOSSIP_SENDER_MAIN, SELECTED + GetFirstPlayerGuid(arena));
				}
				else if (!isTop && mmr < TopGamesRating)
				{
					lowGames++;

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

					if (lowGames >= page * GamesOnPage)
						player->ADD_GOSSIP_ITEM(9, GetGamesStringData(arena, mmr), GOSSIP_SENDER_MAIN, SELECTED + GetFirstPlayerGuid(arena));
				}
			}
		}

		if (page > 0)
			player->ADD_GOSSIP_ITEM(0, "Prev ...", GOSSIP_SENDER_MAIN, LISTGAMESL + page - 1);

		if (haveNextPage)
			player->ADD_GOSSIP_ITEM(0, "Next ...", GOSSIP_SENDER_MAIN, LISTGAMESL + page + 1);
	}
};
 

Tommy

Founder
I can't test it, don't have the Arena Spectator in my test project. I can't really pinpoint the problem though. +_+
 
Last edited:

Xele

Enthusiast
dont know, maybe 1 month or 2
this is just creature and command script, need more edit in player.cpp and other files,
if you want i can upload diff files
 

Tommy

Founder
dont know, maybe 1 month or 2
this is just creature and command script, need more edit in player.cpp and other files,
if you want i can upload diff files

Honestly, I don't want to mess my source up with an unknown patch that could ruin everything. I'm sure the EmuDevs staff or members can help you with this, sadly they are probably sleeping now. I'll look over the script to make sure something isn't wrong.
 

Tommy

Founder
I can't see anything wrong. I guess I can download a fresh TC and run the diff files on that source if you don't mind giving me the source. :D
 

Tommy

Founder
Okay, have you contacted the people who made this about your issue? It probably would have been faster than me helping you. :D

Anyway, make sure everything is setup correctly on your part (e.g: If the patch didn't mess anything up or error on a specific diff). Only thing I can think of is, it is their containers and code. I didn't code it, so it would take me awhile to go through everything, hence why I mentioned contacting them. Sorry I couldn't have been more of help to you. :(
 

Xele

Enthusiast
Okay, have you contacted the people who made this about your issue? It probably would have been faster than me helping you. :D

Anyway, make sure everything is setup correctly on your part (e.g: If the patch didn't mess anything up or error on a specific diff). Only thing I can think of is, it is their containers and code. I didn't code it, so it would take me awhile to go through everything, hence why I mentioned contacting them. Sorry I couldn't have been more of help to you. :(

really i don't know who made that, i'm sure everything is setup correctly on my source,
also script works with command, anyway u did help me alot thank
 
Status
Not open for further replies.
Top