I've was thinking about how everyone on retail always knows who was the first guild to down a certain boss, so i decided to develop that capability for private servers, you have to add the bosses yourself though. As well, us Lunar Scripters kinda need a way to get out name out into the public. So please enjoy the script, and post back.
C++
Code:
#include "StdAfx.h"
#include "Setup.h"
#include <vector>
vector<string> * command(string str)
{
char * cstr, *p;
cstr = new char [str.size()+1];
strcpy (cstr, str.c_str());
vector<string> * strvec = new vector<string>();
p=strtok (cstr," ");
while (p!=NULL)
{
strvec->push_back(p);
p=strtok(NULL," ");
}
delete[] cstr;
return strvec;
}
void BossCommands(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
if(!pPlayer)
return;
string comm = (string)Message;
if(comm.at(0) == '#')
{
vector<string> * strs =command(comm);
string command = strs->at(0);
if(command == "#boss")
{
string arg = strs->at(1);
QueryResult * qres = WorldDatabase.Query("SELECT * FROM `firstbosskills` WHERE `entryid` = '%s'", arg);
if(!qres)
return;
Field * fields = qres->Fetch();
string cname = fields[1].GetString();
string gname = fields[2].GetString();
char * Message;
sprintf(Message,"%s was first killed by the guild %s",cname,gname);
pPlayer->BroadcastMessage(Message);
}
else if(command == "#addboss")
{
if(pPlayer->GetSession()->HasGMPermissions())
{
Creature * selected = pPlayer->GetMapMgr()->GetCreature(GET_LOWGUID_PART(pPlayer->GetSelection()));
if(selected != NULL)
{
uint32 arg = selected->GetEntry();
QueryResult * qres = WorldDatabase.Query("SELECT * FROM `bossids` WHERE `entry` = '%s'", arg);
if(!qres)
{
WorldDatabase.Query("INSERT INTO `bossids` VALUES(%u);",arg);
}
}
else if(strs->at(1) != "")
{
string arg = strs->at(1);
QueryResult * qres = WorldDatabase.Query("SELECT * FROM `bossids` WHERE `entry` = '%s'", arg);
if(!qres)
{
WorldDatabase.Query("INSERT INTO `bossids` VALUES(%s);",arg);
}
}
else
{
pPlayer->BroadcastMessage("Be sure to select an Npc or type an npc entry id");
}
}
else
{
pPlayer->BroadcastMessage("Command doesn't exist");
}
}
else if(command == "#bosslookup")
{
string arg = strs->at(1);
QueryResult * qres = WorldDatabase.Query("SELECT * FROM `firstbosskills` WHERE `creaturename` like '%s'", arg);
if(!qres)
return;
int count = qres->GetRowCount();
for(int i = 1; i >= count;i++)
{
Field * fields = qres->Fetch();
string cname = fields[1].GetString();
string id = fields[0].GetString();
char * Message;
sprintf(Message,"%s: %s",cname,id);
pPlayer->BroadcastMessage(Message);
qres->NextRow();
if(i > 15)
i = count + 1;
}
if(count > 15)
{
pPlayer->BroadcastMessage("Over 15 Results returned try to shorter the search query");
}
}
}
else
{
pPlayer->BroadcastMessage("Command doesn't exist");
}
}
class AddFirstKillAI : public CreatureAIScript
{
public:
AddFirstKillAI(Creature* cre) : CreatureAIScript(cre) {}
void OnDied(Unit * mKiller)
{
const char * gname = ((Player*)mKiller)->GetGuild()->GetGuildName();
const char * cname = ((Creature*)_unit)->GetCreatureInfo()->Name;
uint32 id = _unit->GetEntry();
QueryResult * qres = WorldDatabase.Query("SELECT * FROM `firstbosskills` WHERE `entryid` = '%u'", id);
if(!qres)
WorldDatabase.Execute("INSERT INTO `firstbosskills` VALUES(%u,%s,%s);",id,gname,cname);
}
void Destroy()
{
delete (AddFirstKillAI*)this;
}
static CreatureAIScript *Create(Creature * c) { return new AddFirstKillAI(c); }
};
void SetupFirstBossKill(ScriptMgr * mgr)
{
mgr->register_hook(SERVER_HOOK_EVENT_ON_CHAT, &BossCommands);
QueryResult * qres = WorldDatabase.Query("SELECT * FROM `bossids`;");
if(!qres)
return;
int count = qres->GetRowCount();
for(int i = 0;i >= count;i++)
{
Field * fields = qres->Fetch();
uint32 id = fields[0].GetUInt32();
mgr->register_creature_script(id, &AddFirstKillAI::Create);
qres->NextRow();
}
}
SQL
Code:
CREATE TABLE "bossids" (
"entry" int(10) unsigned default NULL
);
CREATE TABLE "firstbosskills" (
"entryid" int(10) unsigned default NULL,
"guildname" text,
"creaturename" text,
UNIQUE KEY "entryid" ("entryid")
);
#boss x - x is the entryid of the boss use this and it will look up the npc and find out who first killed it
#bosslookup x - x is the name of the npc no spaces can be used it will search and return entry ids
#addboss x - x is the entry id and this will add the npc to the database of first killed npcs, also alternatively you can select an npc and just type'#addboss' without any entry id and it will work
Lunar Scriptor Website
Enjoy leave feedback
-- Edit --
Thanks you AzolexX for alerting me the difference in Entry and Guid