这个是一个WOW单机 Trinity的脚本代码。主要实现了给玩家治疗和加治疗BUFF的脚本。。
下面脚本里面我就做一些注释
#include "ScriptPCH.h"
#define GOSSIP_HEAL 1
#define GOSSIP_BUFF 2
#define BUFF_1 123 //定义治疗BUFF的技能ID 1
#define BUFF_2 342 //定义治疗BUFF的技能ID 2
#define BUFF_3 765 //定义治疗BUFF的技能ID 3
class BuffHealNPC : public CreatureScript
{
public: BuffHealNPC() : CreatureScript("BuffHealNPC") { }
bool OnGossipHello(Player* player, Creature* pCreature)
{
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Heal me for full HP", GOSSIP_SENDER_MAIN, GOSSIP_HEAL);//提示菜单栏,治疗我获得满血
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Buff me up", GOSSIP_SENDER_MAIN, GOSSIP_BUFF);//给我一个治疗的BUFF
player->PlayerTalkClass->SendGossipMenu(1, pCreature->GetGUID());
return true;
}
void ReturnToMainMenu(Player* player, Creature* creature)
{
player->PlayerTalkClass->ClearMenus();
OnGossipHello(player, creature);
}
char str[255];
bool OnGossipSelect(Player* player, Creature* creature, uint32 /*uiSender*/, uint32 uiAction)
{
player->PlayerTalkClass->ClearMenus();
switch (uiAction)
{
case GOSSIP_HEAL:
{
SpellInfo const* spell = sSpellMgr->GetSpellInfo(2061);
if(player->GetHealth() == player->GetMaxHealth())
{
sprintf(str, "You don't need any heal right now!"); //如果你的血是满血,就不需要治疗了
}
else
{
player->HealBySpell(player, spell, player->GetMaxHealth(), false);
sprintf(str, "You have been healed to your maxim health");//oK 这里治疗成功了HealBySpell,这个就是治疗函数咯!
}
player->MonsterWhisper(str, player->GetGUID(), true);
ReturnToMainMenu(player, creature);
break;
}
case GOSSIP_BUFF:
{
player->AddAura(BUFF_1, player);
player->AddAura(BUFF_2, player);
player->AddAura(BUFF_3, player);
sprintf(str, "You have been buffed!"); //这个就是第二个项目选择。。给玩家一个治疗BUFF
player->MonsterWhisper(str, player->GetGUID(), true);
ReturnToMainMenu(player, creature);
break;
}
}
return true;
}
};
void AddSC_BuffHealNPC()
{
new BuffHealNPC();
}
以上就是完整的脚本代码。自己加到代码库中,就可以使用了
回复下载完整代码
|