View difference between Paste ID: MQudJrnD and z86eQKiF
SHOW: | | - or go back to the newest paste.
1-
#include "StdAfx.h"
1+
// Race change
2-
#include "Setup.h"
2+
// By Eatos
3-
#define NPC_ID 56099
3+
// Convert to trinitycore by Rochet2
4
// Original release thread: http://www.ac-web.org/forums/showthread.php?t=151878
5-
class RaceChanger : public GossipScript
5+
6
#include "ScriptPCH.h"
7
#include "GuildMgr.h"
8
#include "Chat.h"
9-
      void GossipHello(Object* pObject, Player * Plr, bool AutoSend)
9+
10-
      {
10+
class RaceChanger : public CreatureScript
11-
         GossipMenu *Menu;
11+
12-
         objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 40002, Plr);
12+
13-
         if(Plr->GetSession()->CanUseCommand('z'))
13+
    RaceChanger() : CreatureScript("RaceChanger") { }
14-
		{
14+
15-
		    Menu->AddItem( 0, "Change my Race", 1 );
15+
    bool OnGossipHello(Player* Plr, Creature* pObject)
16-
		}
16+
17-
		else
17+
        if(Plr->GetSession()->GetSecurity() != SEC_PLAYER)
18-
		{
18+
        {
19-
		    Menu->AddItem(0, "You can not use this right now!", 3);
19+
            Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Human", 0, 1 );
20-
		}
20+
            Plr->ADD_GOSSIP_ITEM( 0, "Change me Into NightElf", 0, 4 );
21-
		 
21+
            Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Dwarf", 0, 3 );
22-
        if(AutoSend)
22+
            Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Gnome", 0, 7 );
23-
            Menu->SendTo(Plr);
23+
            Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Draenei", 0, 11 );
24
            Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Orc", 0, 2 );
25
            Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Undead", 0, 5 );
26-
	void GossipSelectOption(Object* pObject, Player * Plr, uint32 Id, uint32 IntId, const char * Code)
26+
            Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Tauren", 0, 6 );
27-
   {
27+
            Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Troll", 0, 8 );
28-
		Creature * pCreature = (pObject->GetTypeId()==TYPEID_UNIT)?((Creature*)pObject):NULL;
28+
            Plr->ADD_GOSSIP_ITEM( 0, "Change me Into BloodElf", 0, 10 );
29-
		if(pCreature==NULL)
29+
        }
30-
			return;
30+
        else
31
        {
32-
		GossipMenu *Menu;
32+
            Plr->GetSession()->SendNotification("You can not use this right now");
33-
		switch(IntId)
33+
            return false;
34-
		{
34+
        }
35-
			case 1:
35+
        Plr->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, pObject->GetGUID());
36-
			{
36+
        return true;
37-
				objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 1, Plr);
37+
38-
				Menu->AddItem( 0, "Change me Into Human", 4 );
38+
39-
				Menu->AddItem( 0, "Change me Into NightElf", 5 );
39+
    bool OnGossipSelect(Player* Plr, Creature* pObject, uint32 Id, uint32 IntId)
40-
				Menu->AddItem( 0, "Change me Into Dwarf", 6 );
40+
41-
				Menu->AddItem( 0, "Change me Into Gnome", 7 );
41+
        // ChatHandler(Plr).PSendSysMessage("MUHAHAHA ...");
42-
				Menu->AddItem( 0, "Change me Into Draenei", 8 );
42+
43-
				Menu->AddItem( 0, "Change me Into Orc", 10 );
43+
        uint8 race, race_old, class_, gender;
44-
				Menu->AddItem( 0, "Change me Into Undead", 11 );
44+
        Powers powertype;
45-
				Menu->AddItem( 0, "Change me Into Tauren", 12 );
45+
        // TeamId team;
46-
				Menu->AddItem( 0, "Change me Into Troll", 13 );
46+
        race_old = race = IntId; // what are these for? Shouldnt they be different?
47-
				Menu->AddItem( 0, "Change me Into BloodElf", 14 );
47+
48-
				Menu->SendTo(Plr);
48+
        Plr->setFactionForRace(race);
49-
			}break;
49+
        class_ = Plr->getClass();
50-
			
50+
        gender = Plr->getGender();
51-
			case 4: // Human
51+
        powertype = Plr->getPowerType();
52-
			{
52+
        // team = Plr->GetTeamId();
53-
				sChatHandler.SystemMessage(Plr->GetSession(), "MUHAHAHA ...");
53+
54-
				uint32 team = Plr->GetTeam();
54+
        const PlayerInfo* info = sObjectMgr->GetPlayerInfo(race, class_);
55
        if (!info)
56-
				race_old = race = 1;
56+
            return true;
57-
				class_ = Plr->getClass();
57+
58-
				gender = Plr->getGender();
58+
        Plr->SetFloatValue(OBJECT_FIELD_SCALE_X, ((race==RACE_TAUREN)?1.3f:1.0f));
59-
				powertype = Plr->GetPowerType();
59+
        // Plr->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, info->factiontemplate );	// handled by setFactionForRace
60-
				
60+
        Plr->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( race ) | ( class_ << 8 ) | ( gender << 16 ) | ( powertype << 24 ) ) );
61-
				Plr->SetTeam( team ? 0 : 1 );
61+
        Plr->SetUInt32Value(UNIT_FIELD_DISPLAYID, gender ? info->displayId_f : info->displayId_f );
62-
				PlayerCreateInfo *info = objmgr.GetPlayerCreateInfo(race, class_);
62+
        Plr->SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, gender ? info->displayId_f : info->displayId_f );
63-
				if (!info)
63+
64-
					break;
64+
        // Different races have different number of visuals
65
        Plr->SetUInt32Value(PLAYER_BYTES, ((urand(0,5))|(urand(0,5)<<8)|(urand(0,5)<<16)|(urand(0,5)<<24))); // urand were RandomUInt. Might not exist in Trinitycore. Not sure what it does either.
66-
				Plr->SetFloatValue(OBJECT_FIELD_SCALE_X, ((race==RACE_TAUREN)?1.3f:1.0f));
66+
        Plr->SetUInt32Value(PLAYER_BYTES_2, (( !gender ? 0 : urand(0,3) ) | (0x02 << 24))); // gender right?
67-
				Plr->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, info->factiontemplate );	
67+
        //Plr->SetUInt32Value(PLAYER_BYTES, ((skin) | (face << 8) | (hairStyle << 16) | (hairColor << 24)));
68-
				Plr->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( race ) | ( class_ << 8 ) | ( gender << 16 ) | ( powertype << 24 ) ) );
68+
        //Plr->SetUInt32Value(PLAYER_BYTES_2, (facialHair | (0x02 << 24)));
69-
				if(race != RACE_BLOODELF)
69+
70-
				{
70+
        Plr->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, 0xEEEEEEEE);
71-
					Plr->SetUInt32Value(UNIT_FIELD_DISPLAYID, info->displayId + gender );
71+
        //dump reputation data
72-
					Plr->SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, info->displayId + gender );
72+
        FactionStateList m_tempRepMap;
73-
				}
73+
        //store neutral
74-
				else
74+
        for(uint32 i = 0; i < sFactionStore.GetNumRows(); ++i)
75-
				{
75+
        {
76-
					Plr->SetUInt32Value(UNIT_FIELD_DISPLAYID, info->displayId - gender );
76+
            const FactionEntry * f = sFactionStore.LookupEntry(i);
77-
					Plr->SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, info->displayId - gender );
77+
            if(f == 0) continue;
78-
				}
78+
            if( Plr->GetReputation(f->ID) &&
79-
				// Different races have different number of visuals
79+
                f->team != 67 && f->team != 469 && // ream = parentFaction ?
80-
				Plr->SetUInt32Value(PLAYER_BYTES, ((RandomUInt(5))|(RandomUInt(5)<<8)|(RandomUInt(5)<<16)|(RandomUInt(5)<<24)));
80+
                f->team != 892 && f->team != 891 && 
81-
				Plr->SetUInt32Value(PLAYER_BYTES_2, (( !gender ? 0 : RandomUInt(3) ) | (0x02 << 24)));
81+
                f->ID != 947 && f->ID != 946 && 
82-
				//Plr->SetUInt32Value(PLAYER_BYTES, ((skin) | (face << 8) | (hairStyle << 16) | (hairColor << 24)));
82+
                f->ID != 892 && f->ID != 891 &&
83-
				//Plr->SetUInt32Value(PLAYER_BYTES_2, (facialHair | (0x02 << 24)));
83+
                f->ID != 941 && f->ID != 978 && 
84-
				
84+
                f->ID != 922
85-
				Plr->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, 0xEEEEEEEE);
85+
                )
86-
				//dump reputation data
86+
            {
87-
				ReputationMap m_tempRepMap;
87+
                const ReputationMgr & repMgr = Plr->GetReputationMgr();
88-
				//store neutral
88+
                FactionState * rep = new FactionState;
89-
				for(uint32 i = 0; i < dbcFaction.GetNumRows(); ++i)
89+
                /*
90-
				{
90+
                rep->Flags = 0;
91-
					FactionDBC * f = dbcFaction.LookupRow(i);
91+
                rep->Standing = repMgr.GetReputation(f->ID);
92-
					if(f == 0) continue;
92+
                rep->base = repMgr.GetBaseReputation(f->ID);
93-
					if( Plr->GetStanding(f->ID) &&
93+
                */
94-
						f->parentFaction != 67 && f->parentFaction != 469 &&
94+
                FactionState newFaction;
95-
						f->parentFaction != 892 && f->parentFaction != 891 && 
95+
                newFaction.ID = f->ID;
96-
						f->ID != 947 && f->ID != 946 && 
96+
                newFaction.ReputationListID = f->reputationListID;
97-
						f->ID != 892 && f->ID != 891 &&
97+
                newFaction.Standing = repMgr.GetReputation(f->ID);
98-
						f->ID != 941 && f->ID != 978 && 
98+
                newFaction.Flags = 0;
99-
						f->ID != 922
99+
                newFaction.needSend = true;
100-
						)
100+
                newFaction.needSave = true;
101-
					{
101+
102-
						FactionReputation * rep = new FactionReputation;
102+
                m_tempRepMap[f->ID] = newFaction; // newFaction.ReputationListID or f->ID?
103-
						rep->flag = 0;
103+
            }
104-
						rep->standing = Plr->GetStanding(f->ID);
104+
        }
105-
						rep->baseStanding = Plr->GetBaseStanding(f->ID);
105+
106
        Plr->GetReputationMgr().SendInitialReputations(); // does this initialize the rep values?
107-
						m_tempRepMap[f->ID] = rep;
107+
108-
					}
108+
        for(FactionStateList::iterator itr = m_tempRepMap.begin(); itr != m_tempRepMap.end(); ++itr)
109-
				}
109+
        {
110-
				
110+
            Plr->SetReputation(itr->first, itr->second.Standing );
111-
				
111+
            //delete itr->second;
112-
				Plr->_InitialReputation();
112+
        }
113-
			
113+
114-
				for(ReputationMap::iterator itr = m_tempRepMap.begin(); itr != m_tempRepMap.end(); ++itr)
114+
        // Plr->(); // _RemoveLanguages See CharacterHandler.cpp 1736 line ?
115-
				{
115+
        // Seems like languages are handled automatically.
116-
					Plr->SetStanding(itr->first, itr->second->standing );
116+
117-
					//delete itr->second;
117+
        //remove racial spells along with all starting spells then add them for new race
118-
				}
118+
        const PlayerInfo* old_info = sObjectMgr->GetPlayerInfo(race_old, class_);
119
        if (!old_info)
120-
				Plr->_RemoveLanguages();
120+
            return true;
121-
				
121+
122-
				//remove racial spells along with all starting spells then add them for new race
122+
        for(PlayerCreateInfoSpells::const_iterator sp = old_info->spell.begin(); sp != old_info->spell.end(); sp++) // spell_list
123-
				PlayerCreateInfo * old_info = objmgr.GetPlayerCreateInfo(race_old, class_);
123+
            if (Plr->HasSpell(*sp)) Plr->removeSpell((*sp), false, false);
124-
				if (!old_info) break;
124+
125
        for(PlayerCreateInfoSpells::const_iterator sp = info->spell.begin(); sp != info->spell.end(); sp++)
126-
				for(std::set<uint32>::iterator sp = old_info->spell_list.begin(); sp!=old_info->spell_list.end(); sp++)
126+
            Plr->addSpell((*sp), true, true, true, false);
127-
					if (Plr->HasSpell(*sp)) Plr->removeSpell((*sp), false, false, 0);
127+
128
        // Shouldnt we also take into account if the faction changes?
129-
				for(std::set<uint32>::iterator sp = info->spell_list.begin(); sp!=info->spell_list.end(); sp++)
129+
        if (Plr->GetGuildId())
130-
					Plr->addSpell(*sp);
130+
        {
131
            Guild *pGuild = sGuildMgr->GetGuildById( Plr->GetGuildId() );
132-
				
132+
133-
				if (Plr->GetGuildId())
133+
            if(pGuild && pGuild->GetLeaderGUID() != Plr->GetGUID() )
134-
				{
134+
            {
135-
					Guild *pGuild = objmgr.GetGuild( Plr->GetGuildId() );
135+
                pGuild->DeleteMember(Plr->GetGUID());
136
                /*Plr->L SetGuildId(0);
137-
					if(pGuild && pGuild->GetGuildLeader() != Plr->GetGUID() )
137+
                Plr->SetGuildRank(0);
138-
					{
138+
                pGuild->RemoveGuildMember(Plr->m_playerInfo, NULL);
139-
						Plr->SetGuildId(0);
139+
140-
						Plr->SetGuildRank(0);
140+
                WorldPacket data(100);
141-
						pGuild->RemoveGuildMember(Plr->m_playerInfo, NULL);
141+
                data.Initialize(SMSG_GUILD_EVENT);
142
                data << uint8(GUILD_EVENT_LEFT);
143-
						WorldPacket data(100);
143+
                data << uint8(1);
144-
						data.Initialize(SMSG_GUILD_EVENT);
144+
                data << Plr->GetName();
145-
						data << uint8(GUILD_EVENT_LEFT);
145+
                pGuild->SendPacket(&data);
146-
						data << uint8(1);
146+
                */
147-
						data << Plr->GetName();
147+
            }
148-
						pGuild->SendPacket(&data);
148+
        }
149-
					}
149+
150-
				}
150+
        Plr->SaveToDB(false);
151
        // ChatHandler(Plr).PSendSysMessage("Signed in blood. There is no going back now ...");
152-
				
152+
        // ChatHandler(Plr).PSendSysMessage("Relog ...");
153
        //force relog
154-
				Plr->SaveToDB(false);
154+
        Plr->GetSession()->KickPlayer(); // instant kick, cant be bothered to make it delayed.
155-
				sChatHandler.SystemMessage(Plr->GetSession(), "Signed in blood. There is no going back now ...");
155+
        Plr->CLOSE_GOSSIP_MENU();
156-
				sChatHandler.SystemMessage(Plr->GetSession(), "Relog ...");
156+
        return true;
157-
				//force relog
157+
158-
				Plr->Kick(5000);
158+
159-
				Plr->Gossip_Complete();
159+
160-
			
160+
void AddSC_RaceChanger()
161-
			}break;
161+
162-
			
162+
    new RaceChanger();
163-
			case 5: // Nightelf
163+