EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Development::Bots (https://www.eqemulator.org/forums/forumdisplay.php?f=676)
-   -   Bot Quests for the Bot Creation Limit (https://www.eqemulator.org/forums/showthread.php?t=36387)

zippzipp 02-01-2013 01:18 PM

Bot Quests for the Bot Creation Limit
 
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

ghanja 02-01-2013 01:51 PM

I'd make a diff/patch using TortoiseSVN. Otherwise you may get a slew of questions and/or complaints that 'this doesn't work' due to those that do not properly apply the changes as you have them written. Just a recommendation of course.

lerxst2112 02-01-2013 06:50 PM

Just a style thing, it would be better to use a reference rather than a pointer for your error message string.


All times are GMT -4. The time now is 06:14 PM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.