修改玩家姓名的脚本代码:
diff -r a09fe1125922 src/bindings/scripts/scripts/examples/example_gossip_codebox.cpp
--- a/src/bindings/scripts/scripts/examples/example_gossip_codebox.cpp Wed Sep 30 04:26:35 2009 -0700
+++ b/src/bindings/scripts/scripts/examples/example_gossip_codebox.cpp Wed Sep 30 20:11:23 2009 +0200
@@ -31,7 +31,8 @@
SAY_NOT_INTERESTED = -1999922,
SAY_WRONG = -1999923,
- SAY_CORRECT = -1999924
+ SAY_CORRECT = -1999924,
+ SAY_BYE_BYE = -1999915
};
#define GOSSIP_ITEM_1 "A quiz: what's your name?"
@@ -97,3 +98,85 @@
newscript->pGossipSelectWithCode = &GossipSelectWithCode_example_gossip_codebox;
newscript->RegisterSelf();
}
+
+
+
+/* Begin custom code for the NPC Renamer */
+/*****************************************/
+/* ScriptData
+Author: 1RR3QU13T0 - ricci77
+SDName: npc_rename_script
+SD%Complete: 100
+SDComment: Npc that can change pg name after a login
+SDCategory: Script Examples
+EndScriptData */
+
+//This function is called when the player opens the gossip menubool
+bool GossipHello_custom_rename_codebox(Player *player, Creature *_Creature)
+{
+ player->ADD_GOSSIP_ITEM_EXTENDED(0, "Rename? Put yes or no in the box. If you choose yes, you need 500 gold.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1, "", 0, true);
+ player->ADD_GOSSIP_ITEM(0, "You're not interested.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
+ player->PlayerTalkClass->SendGossipMenu(907,_Creature->GetGUID());
+ return true;
+}
+
+//This function is called when the player clicks an option on the gossip menubool
+bool GossipSelect_custom_rename_codebox(Player *player, Creature *_Creature, uint32 sender, uint32 action )
+{
+ if(action == GOSSIP_ACTION_INFO_DEF+2)
+ {
+ DoScriptText(SAY_NOT_INTERESTED, _Creature);
+ player->CLOSE_GOSSIP_MENU();
+ }
+ return true;
+}
+
+bool GossipSelectWithCode_custom_rename_codebox( Player *player, Creature *_Creature, uint32 sender, uint32 action, const char* sCode )
+{
+ // "cost" is the amount of gold needed for renaming - set to 500g
+ uint32 cost = 5000000;
+ if(sender == GOSSIP_SENDER_MAIN)
+ {
+ if(action == GOSSIP_ACTION_INFO_DEF+1)
+ {
+ if(std::strcmp(sCode, "yes") ==0)
+ {
+ if (player->GetMoney() < cost)
+ {
+ player->SendBuyError( BUY_ERR_NOT_ENOUGHT_MONEY, 0, 0, 0);
+ player->CLOSE_GOSSIP_MENU();
+ }
+ else
+ {
+ DoScriptText(SAY_BYE_BYE, _Creature);
+ player->SetAtLoginFlag(AT_LOGIN_RENAME);
+ player->CLOSE_GOSSIP_MENU();
+ player->SetMoney( player->GetMoney() - cost );
+ }
+ }
+ else if (std::strcmp(sCode, "no") ==0)
+ {
+ DoScriptText(SAY_BYE_BYE, _Creature);
+ player->CLOSE_GOSSIP_MENU();
+ }
+ else
+ {
+ player->CLOSE_GOSSIP_MENU();
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+void AddSC_custom_rename_codebox()
+{
+ Script *newscript;
+
+ newscript = new Script;
+ newscript->Name="custom_rename_codebox";
+ newscript->pGossipHello = &GossipHello_custom_rename_codebox;
+ newscript->pGossipSelect = &GossipSelect_custom_rename_codebox;
+ newscript->pGossipSelectWithCode = &GossipSelectWithCode_custom_rename_codebox;
+ newscript->RegisterSelf();
+}
diff -r a09fe1125922 src/bindings/scripts/system/ScriptLoader.cpp
--- a/src/bindings/scripts/system/ScriptLoader.cpp Wed Sep 30 04:26:35 2009 -0700
+++ b/src/bindings/scripts/system/ScriptLoader.cpp Wed Sep 30 20:11:23 2009 +0200
@@ -11,6 +11,7 @@
extern void AddSC_example_escort();
extern void AddSC_example_gossip_codebox();
extern void AddSC_example_misc();
+extern void AddSC_custom_rename_codebox();
//world
extern void AddSC_areatrigger_scripts();
@@ -425,6 +426,7 @@
AddSC_example_escort();
AddSC_example_gossip_codebox();
AddSC_example_misc();
+ AddSC_custom_rename_codebox();
//world
AddSC_areatrigger_scripts();
相关报道: