这个是一套NPC脚本的功能代码。主要实现购买头衔
下面是脚本代码,
/****************************************
* Created by: Rochet2 *
* Updated by: Asbert75 *
* With help from: *
* LilleCarl, Rochet2, Jamey *
* *----- Title Vendor -----* *
****************************************/
#include "ScriptPCH.h"
struct Rochet2
{
uint8 icon;
std::string name;
uint32 HK, titleID;
};
/********************************************************
Possible icons:
0, //white chat bubble
1, //brown bag
2, //flight
3, //book
4, //interaction wheel
5, //interaction wheel
6, //brown bag with yellow dot
7, //white chat bubble with black dots
8, //tabard
9, //two swords
10, //yellow dot
Example Gossip Option: {iconID (see above), "title name", honorable_kills_required (set to whatever you require the player to have to get this rank), titleID (from database)}
***********************************************************/
Rochet2 Titles [] =
{
{9, "Private", 50, 1 },
{9, "Corporal", 100, 2 },
{9, "Sergeant", 250, 3 },
{9, "Master Sergeant", 500, 4 },
{9, "Sergeant Major", 750, 5 },
{9, "Knight", 1000, 6 },
{9, "Knight-Lieutenant", 1500, 7 },
{9, "Knight-Captain", 2000, 8 },
{9, "Knight-Champion", 2500, 9 },
{9, "Lieutenant Commander", 3000, 10 },
{9, "Commander", 3500, 11 },
{9, "Marshal", 4000, 12 },
{9, "Field Marshal", 4500, 13 },
{9, "Grand Marshal", 5000, 14 },
{9, "Scout", 50, 15 },
{9, "Grunt", 100, 16 },
{9, "Sergeant", 250, 17 },
{9, "Senior Sergeant", 500, 18 },
{9, "First Sergeant", 750, 19 },
{9, "Stone Guard", 1000, 20 },
{9, "Blood Guard", 1500, 21 },
{9, "Legionnaire", 2000, 22 },
{9, "Centurion", 2500, 23 },
{9, "Champion", 3000, 24 },
{9, "Lieutenant General", 3500, 25 },
{9, "General", 4000, 26 },
{9, "Warlord", 4500, 27 },
{9, "High Warlord", 5000, 28 },
};
enum eEnums
{
Amount = sizeof Titles/sizeof(*Titles),
// npc_text ID
Greetings_A = 1,
Greetings_H = 2,
};
#define ERROR_HASTITLE "|cffff0000You already have this title|r" // Error message that shows up when a player already has the title
#define ERROR_CASH "|cffff0000You don't have enough honorable kills|r" // Error message if player does not have enough honorable kills
class Title_gossip_codebox : public CreatureScript
{
public:
Title_gossip_codebox()
: CreatureScript("Title_gossip_codebox")
{
}
bool OnGossipHello(Player* pPlayer, Creature* pCreature)
{
uint32 txt = Greetings_A;
uint32 i = 0;
uint32 m = Amount/2;
if(pPlayer->GetTeam() == HORDE)
{
txt = Greetings_H;
i = Amount/2;
m = Amount;
}
for (i; i<m; i++)
{
std::ostringstream ss;
ss << Titles.name << " - " << Titles.HK << " HKs";
std::string showcoolshit = ss.str();
ss.str(" ");
ss.clear();
ss << "Are you sure? You will be granted the title: " << Titles.name;
std::string showcoolshit2 = ss.str();
// ADD_GOSSIP_ITEM_EXTENDED Parameters: (icon, label, GOSSIP_SENDER_MAIN (Sender), Title ID ? (action - Sends info to OnGossipSelect), popup, coppercost, code (codebox))
pPlayer->ADD_GOSSIP_ITEM_EXTENDED(Titles.icon, showcoolshit.c_str(), GOSSIP_SENDER_MAIN, i, showcoolshit2, 0, false);
}
pPlayer->PlayerTalkClass->SendGossipMenu(txt, pCreature->GetGUID());
return true;
}
bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 /*uiSender*/, uint32 i)
{
pPlayer->PlayerTalkClass->ClearMenus(); // clear the menu
if (CharTitlesEntry const* Title = sCharTitlesStore.LookupEntry(Titles.titleID)) // Get title
{
if(pPlayer->HasTitle(Title)) // If has title
pPlayer->GetSession()->SendAreaTriggerMessage(ERROR_HASTITLE);
else if(Titles.HK > pPlayer->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS)) // If doesnt have enough honored kills
pPlayer->GetSession()->SendAreaTriggerMessage(ERROR_CASH);
else
{
pPlayer->SetTitle(Title);
pPlayer->SaveToDB();
}
OnGossipHello(pPlayer, pCreature);
}
return true;
}
};
void AddSC_Title_gossip_codebox()
{
new Title_gossip_codebox();
}
下载完整代码
|