Here's the code:
zone/bot.cpp
Code:
if(!strcasecmp(sep->arg[1], "archery")) {
if((c->GetTarget() == NULL) || (c->GetTarget() == c) || !c->GetTarget()->IsBot()) {
c->Message(15, "You must target a bot!");
return;
}
Mob *archerbot = c->GetTarget();
if((archerbot->GetClass()==WARRIOR)||(archerbot->GetClass()==PALADIN)||(archerbot->GetClass()==RANGER)||(archerbot->GetClass()==SHADOWKNIGHT)||(archerbot->GetClass()==ROGUE)) {
//const Item_Struct* botweapon = database.GetItem(archerbot->CastToBot()->GetItem(SLOT_RANGE));
const Item_Struct* botweapon = database.GetItem(archerbot->CastToBot()->GetItem(SLOT_RANGE)->item_id);
uint32 archeryMaterial;
uint32 archeryColor;
uint32 archeryBowID;
uint32 archeryAmmoID;
uint32 range = 0;
if(botweapon && (botweapon->ItemType == ItemTypeBow)) {
archeryMaterial = atoi(botweapon->IDFile+2);
archeryBowID = botweapon->ID;
archeryColor = botweapon->Color;
range =+ botweapon->Range;
botweapon = database.GetItem(archerbot->CastToNPC()->GetItem(SLOT_AMMO)->item_id);
if(!botweapon || (botweapon->ItemType != ItemTypeArrow)) {
archerbot->Say("I don't have any arrows.");
archerbot->CastToBot()->SetBotArcheryRange(0);
return;
}
range += botweapon->Range;
archeryAmmoID = botweapon->ID;
}
else {
archerbot->Say("I don't have a bow.");
archerbot->CastToBot()->SetBotArcheryRange(0);
return;
}
if(archerbot->CastToBot()->IsBotArcher()) {
archerbot->CastToBot()->SetBotArcher(false);
archerbot->Say("Using melee skills.");
archerbot->CastToBot()->BotAddEquipItem(SLOT_PRIMARY, archerbot->CastToBot()->GetBotItemBySlot(SLOT_PRIMARY, &TempErrorMessage));
if(!TempErrorMessage.empty()) {
c->Message(13, "Database Error: %s", TempErrorMessage.c_str());
return;
}
//archerbot->SendWearChange(MATERIAL_PRIMARY);
archerbot->CastToBot()->BotAddEquipItem(SLOT_SECONDARY, archerbot->CastToBot()->GetBotItemBySlot(SLOT_SECONDARY, &TempErrorMessage));
if(!TempErrorMessage.empty()) {
c->Message(13, "Database Error: %s", TempErrorMessage.c_str());
return;
}
//archerbot->SendWearChange(MATERIAL_SECONDARY);
archerbot->CastToBot()->SetBotArcheryRange(0);
}
else {
archerbot->CastToBot()->SetBotArcher(true);
archerbot->Say("Using archery skills.");
archerbot->CastToBot()->BotRemoveEquipItem(SLOT_PRIMARY);
//archerbot->SendWearChange(MATERIAL_PRIMARY);
archerbot->CastToBot()->BotRemoveEquipItem(SLOT_SECONDARY);
//archerbot->SendWearChange(MATERIAL_SECONDARY);
archerbot->CastToBot()->BotAddEquipItem(SLOT_SECONDARY, archeryBowID);
archerbot->CastToBot()->SendBotArcheryWearChange(MATERIAL_SECONDARY, archeryMaterial, archeryColor);
archerbot->CastToBot()->BotAddEquipItem(SLOT_PRIMARY, archeryAmmoID);
archerbot->CastToBot()->SetBotArcheryRange(range);
}
}
else {
archerbot->Say("I don't know how to use a bow.");
}
return;
}
Just scanning through, it looks like there
may be a spot or 2 that could end up with a null pointer, but adding some debugging code would help to verify.