PDA

View Full Version : Profession Teleporter



ImperialDev
05-09-2014, 10:21 PM
H! Emu Devies,
This is my first C++ Script, Umm Idk Its Exist or NOT in But I Made it!

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

bool OnGossipHello(Player* player, Creature* creature)
{
if (player->IsInCombat()) // Check If Player Is In Combat!
{
player->GetSession()->SendNotification("Ummm Sorry! You Are In Combat!");
player->CLOSE_GOSSIP_MENU();
return false;
}

player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Alchemy:30|t Alchemy Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_BlackSmithing:30|t Blacksmithing Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\INV_Misc_Food_17:30|t Cooking Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 3);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Engraving:30|t Enchanting Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 4);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Engineering:30|t Engineering Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 5);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Achievement_BG_winSOA_underXmi nutes:30|t First Aid Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 6);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Fishing:30|t Fishing Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 7);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Herbalism:30|t Herbalism Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 8);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\INV_Inscription_Tradeskill01:3 0|t Inscription Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 9);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\INV_Misc_Gem_01:30|t Jewelcrafting Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 10);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_LeatherWorking:30|t Leatherworking Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 11);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Mining:30|t Mining Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 12);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\INV_Chest_Leather_17B:30|t Skinning Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 13);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Tailoring:30|t Tailoring Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 14);
player->SEND_GOSSIP_MENU(1, creature->GetGUID());

return true;
}

bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 actions)
{
player->PlayerTalkClass->ClearMenus();
switch (actions)
{
case GOSSIP_ACTION_INFO_DEF + 1:
player->TeleportTo(571, 5897.17f, 710.857f, 642.047f, 4.05559f);
break;
case GOSSIP_ACTION_INFO_DEF + 2:
player->TeleportTo(571, 5897.31f, 687.73f, 642.226f, 5.48005f);
break;
case GOSSIP_ACTION_INFO_DEF + 3:
if (player->GetTeam() == HORDE)
player->TeleportTo(571, 5856.23f, 469.502f, 639.796f, 2.56461f);
else
player->TeleportTo(571, 5704.55f, 715.124f, 642.475f, 2.55934f);
break;
case GOSSIP_ACTION_INFO_DEF + 4:
player->TeleportTo(571, 5831.55f, 715.347f, 640.949f, 0.884089f);
break;
case GOSSIP_ACTION_INFO_DEF + 5:
player->TeleportTo(571, 5912.26f, 728.859f, 641.194f, 6.22951f);
break;
case GOSSIP_ACTION_INFO_DEF + 6:
player->TeleportTo(571, 5866.21f, 735.482f, 639.531f, 2.00328f);
break;
case GOSSIP_ACTION_INFO_DEF + 7:
player->TeleportTo(571, 5702.65f, 616.026f, 646.733f, 5.79517f);
break;
case GOSSIP_ACTION_INFO_DEF + 8:
player->TeleportTo(571, 5870.35f, 684.824f, 643.31f, 0.84559f);
break;
case GOSSIP_ACTION_INFO_DEF + 9:
player->TeleportTo(571, 5854.94f, 695.134f, 641.949f, 0.963398f);
break;
case GOSSIP_ACTION_INFO_DEF + 10:
player->TeleportTo(571, 5872.45f, 727.237f, 643.212f, 4.9862f);
break;
case GOSSIP_ACTION_INFO_DEF + 11:
player->TeleportTo(571, 5905.92f, 754.916f, 641.073f, 1.27871f);
break;
case GOSSIP_ACTION_INFO_DEF + 12:
player->TeleportTo(571, 5922.1f, 711.743f ,642.515f, 6.18113f);
break;
case GOSSIP_ACTION_INFO_DEF + 13:
player->TeleportTo(571, 5908.69f, 757.053f, 641.081f, 1.45068f);
break;
case GOSSIP_ACTION_INFO_DEF + 14:
player->TeleportTo(571, 5880.02f, 748.165f, 640.372f, 1.83633f);
break;
}
player->CLOSE_GOSSIP_MENU();

return true;
}
};

void AddSC_Profession_Teleporter()
{
new Profession_Teleporter();
}

Tommy
05-09-2014, 11:45 PM
Very nice for a first. However, let me give you some future advice.

You don't need to include 'ScriptPCH.h'. It's pretty much already handled via CMake and other sources.
Code could have better indentation. It's pretty messy.
Capitalizing variables such as 'Player* Player' and 'Creature* Creature' isn't what you should be doing in my opinion. Surprisingly enough I'm surprised it won't throw an error due to your variables having the same name as the class names. It would be best to do 'Player* player' and 'Creature* creature'.
Brackets look much better if you unify them. Example:

Before:


{}


After:


{ }


Code such as 'player->PlayerTalkClass->SendCloseGossip();' can be replaced with the more simple define directive: 'player->CLOSE_GOSSIP_MENU();'

Not sure what the intent is here:



virtual bool OnGossipSelect


The 'virtual' isn't needed.

The 'sender' parameter can be commented out as it is rarely/never used:



bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 action)


The code checking 'sender' can be removed too.

The if statement checking if a player is Horde or Alliance can be changed from:



if (player->GetTeam() == HORDE)
{
player->TeleportTo(571, 5856.23f, 469.502f, 639.796f, 2.56461f);
return false;
} // Check Player is Horde Or Aliance And TP Near NPC!
else
{
player->TeleportTo(571, 5704.55f, 715.124f, 642.475f, 2.55934f);
return false;
}


to:



if (player->GetTeam() == HORDE)
player->TeleportTo(571, 5856.23f, 469.502f, 639.796f, 2.56461f);
else
player->TeleportTo(571, 5704.55f, 715.124f, 642.475f, 2.55934f);


In any if statement like this, there is no need to call 'return false' at any point. The else can skip Horde if the player is Alliance.
Lastly, your cases are pretty messy in my perspective.


Cleaned outcome:



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

bool OnGossipHello(Player* player, Creature* creature)
{
if (player->IsInCombat()) // Check If Player Is In Combat!
{
player->GetSession()->SendNotification("Ummm Sorry! You Are In Combat!");
player->CLOSE_GOSSIP_MENU();
return false;
}

player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Alchemy:30|t Alchemy Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_BlackSmithing:30|t Blacksmithing Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\INV_Misc_Food_17:30|t Cooking Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 3);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Engraving:30|t Enchanting Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 4);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Engineering:30|t Engineering Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 5);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Achievement_BG_winSOA_underXmi nutes:30|t First Aid Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 6);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Fishing:30|t Fishing Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 7);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Herbalism:30|t Herbalism Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 8);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\INV_Inscription_Tradeskill01:3 0|t Inscription Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 9);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\INV_Misc_Gem_01:30|t Jewelcrafting Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 10);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_LeatherWorking:30|t Leatherworking Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 11);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Mining:30|t Mining Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 12);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\INV_Chest_Leather_17B:30|t Skinning Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 13);
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\Trade_Tailoring:30|t Tailoring Trainer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 14);
player->SEND_GOSSIP_MENU(1, creature->GetGUID());

return true;
}

bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 actions)
{
player->PlayerTalkClass->ClearMenus();
switch (actions)
{
case GOSSIP_ACTION_INFO_DEF + 1:
player->TeleportTo(571, 5897.17f, 710.857f, 642.047f, 4.05559f);
break;
case GOSSIP_ACTION_INFO_DEF + 2:
player->TeleportTo(571, 5897.31f, 687.73f, 642.226f, 5.48005f);
break;
case GOSSIP_ACTION_INFO_DEF + 3:
if (player->GetTeam() == HORDE)
player->TeleportTo(571, 5856.23f, 469.502f, 639.796f, 2.56461f);
else
player->TeleportTo(571, 5704.55f, 715.124f, 642.475f, 2.55934f);
break;
case GOSSIP_ACTION_INFO_DEF + 4:
player->TeleportTo(571, 5831.55f, 715.347f, 640.949f, 0.884089f);
break;
case GOSSIP_ACTION_INFO_DEF + 5:
player->TeleportTo(571, 5912.26f, 728.859f, 641.194f, 6.22951f);
break;
case GOSSIP_ACTION_INFO_DEF + 6:
player->TeleportTo(571, 5866.21f, 735.482f, 639.531f, 2.00328f);
break;
case GOSSIP_ACTION_INFO_DEF + 7:
player->TeleportTo(571, 5702.65f, 616.026f, 646.733f, 5.79517f);
break;
case GOSSIP_ACTION_INFO_DEF + 8:
player->TeleportTo(571, 5870.35f, 684.824f, 643.31f, 0.84559f);
break;
case GOSSIP_ACTION_INFO_DEF + 9:
player->TeleportTo(571, 5854.94f, 695.134f, 641.949f, 0.963398f);
break;
case GOSSIP_ACTION_INFO_DEF + 10:
player->TeleportTo(571, 5872.45f, 727.237f, 643.212f, 4.9862f);
break;
case GOSSIP_ACTION_INFO_DEF + 11:
player->TeleportTo(571, 5905.92f, 754.916f, 641.073f, 1.27871f);
break;
case GOSSIP_ACTION_INFO_DEF + 12:
player->TeleportTo(571, 5922.1f, 711.743f ,642.515f, 6.18113f);
break;
case GOSSIP_ACTION_INFO_DEF + 13:
player->TeleportTo(571, 5908.69f, 757.053f, 641.081f, 1.45068f);
break;
case GOSSIP_ACTION_INFO_DEF + 14:
player->TeleportTo(571, 5880.02f, 748.165f, 640.372f, 1.83633f);
break;
}
player->CLOSE_GOSSIP_MENU();

return true;
}
};

void AddSC_Profession_Teleporter()
{
new Profession_Teleporter();
}


Nice job regardless. :P

ImperialDev
05-10-2014, 09:55 AM
Lots Of Thanks Tommy!

Skream
09-18-2016, 11:46 PM
for 4.3.4 you do not have?