Hi guys here is something I implemented on my server it moves the bot creation limit to be optionally controlled by a bot creation quest much like the bot spawn quest.
Add the following to bot.h
Code:
// bot.h
static uint32 AllowedBotCreates(uint32 botOwnerCharacterID, std::string* errorMessage);
Replace this in bot.cpp:
Code:
// bot.cpp
// REPLACE:
int32 MaxBotCreate = RuleI(Bots, CreateBotCount);
if(CreatedBotCount(c->CharacterID(), &TempErrorMessage) >= MaxBotCreate) {
c->Message(0, "You cannot create more than %i bots.", MaxBotCreate);
return;
}
With this: in bot.cpp
Code:
// WITH THIS:
int createBotCount = CreatedBotCount(c->CharacterID(), &TempErrorMessage);
if(RuleB(Bots, BotCreateQuest)) {
const int allowedBots = AllowedBotCreates(c->CharacterID(), &TempErrorMessage);
if(!TempErrorMessage.empty()) {
c->Message(13, "Database Error: %s", TempErrorMessage.c_str());
return;
}
if(allowedBots == 0) {
c->Message(0, "You cannot create any bots.");
return;
}
if(createBotCount >= allowedBots) {
c->Message(0, "You cannot create more than %i bots.", createBotCount);
return;
}
} else {
int32 MaxBotCreate = RuleI(Bots, CreateBotCount);
if(createBotCount >= MaxBotCreate) {
c->Message(0, "You cannot create more than %i bots.", MaxBotCreate);
return;
}
}
Add this to bots.cpp
Code:
// bots.cpp
uint32 Bot::AllowedBotCreates(uint32 botOwnerCharacterID, std::string* errorMessage) {
uint32 Result = 0;
if(botOwnerCharacterID > 0) {
char ErrBuf[MYSQL_ERRMSG_SIZE];
char* Query = 0;
MYSQL_RES* DatasetResult;
MYSQL_ROW DataRow;
if(database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT value FROM quest_globals WHERE name='bot_create_limit' and charid=%i", botOwnerCharacterID), ErrBuf, &DatasetResult)) {
if(mysql_num_rows(DatasetResult) == 1) {
DataRow = mysql_fetch_row(DatasetResult);
if(DataRow)
Result = atoi(DataRow[0]);
}
mysql_free_result(DatasetResult);
}
else
*errorMessage = std::string(ErrBuf);
safe_delete_array(Query);
}
return Result;
}
ADD this to ruletypes.h in the #ifdef BOTS section
Code:
// ruletypes.h
RULE_BOOL ( Bots, BotCreateQuest, false)
ADD this to questmgr.h in the #ifdef BOTS section
Code:
// questmgr.h
bool botcreatequest();
ADD this to questmgr.cpp
Code:
// questmgr.cpp
bool QuestManager::botcreatequest()
{
return RuleB(Bots, BotCreateQuest);
}
ADD this to the QuestManager::createBot function in questmgr.cpp
Code:
// questmgr.cpp
if(RuleB(Bots, BotCreateQuest)){
MaxBotCreate = Bot::AllowedBotCreates(initiator->CharacterID(), &TempErrorMessage);
}
There you have it. You also need to add a Rule to the db
Code:
INSERT INTO `peqdb`.`rule_values` (`ruleset_id`, `rule_name`, `rule_value`, `notes`) VALUES ('1', 'Bots:BotCreateQuest', 'true', '');
Now bot creation can be controlled on a per character basis with the qglobal bot_create_limit