12-25-2022, 03:18 PM
Hello just wanted to share some code i wrote last year.
Normal quest collect.
-Allows you to collect only 1 item of whatever is in the production list for the monster
Modified Code:
- allows you to collect up to 5 items of whatever is in the production list for the monster
-item count between 1-10 randomly each collect
Files you'll need to modify
-Config_Localize_USA.h
doFuncQuest.cpp
in Config_Localize_usa.h
at the end add this :
#define QUEST_COLLECT_MOD_10162021
in DoFuncQuest.cpp replace the function do_QuestCollect
void do_QuestCollect(CPC* ch, CNetMsg::SP& msg)
{
int nNPCIndex;
int nItemIndex = -1;
int nItemAmount = 1;
RefMsg(msg) >> nNPCIndex;
if (gserver->m_pulse - ch->m_nLastCollectRequest < PULSE_PRODUCE_DELAY - PULSE_HACK_ATTACK_THRESHOLD)
return ;
CNPC* pNPC = (CNPC*)ch->m_pArea->FindCharInCell(ch, nNPCIndex, MSG_CHAR_NPC);
if (!pNPC)
return ;
if (GetDistance(ch, pNPC) >= pNPC->m_proto->m_attackArea + 0.5)
return ;
#ifdef QUEST_COLLECT_MOD_10162021
bool isBoxCollectNpc = false;
if (pNPC->m_idNum == 1702 || pNPC->m_idNum == 1703 || pNPC->m_idNum == 1711)
isBoxCollectNpc = true;
#endif
if (ch->m_nCollectRequestNPCIndex != nNPCIndex)
ch->m_nCollectRequestCount = 0;
if( pNPC->m_proto->m_family > 0 )
FindFamilyInNear( ch, pNPC );
ch->m_nLastCollectRequest = gserver->m_pulse;
ch->m_nCollectRequestNPCIndex = nNPCIndex;
ch->m_nCollectRequestCount++;
if (ch->m_nCollectRequestCount >= 4)
{
ch->m_nLastCollectRequest = 0;
int nMaxRandom = MAX_NPC_PRODUCT - 1;
int itemIndexProduct[MAX_PRODUCTS_FROM_NPC];
while (nMaxRandom >= 0 )
{
int nProb = GetRandom(0, nMaxRandom);
if (pNPC->m_proto->m_product[nProb] <= 0)
nMaxRandom--;
else
{
nItemIndex = pNPC->m_proto->m_product[nProb];
break ;
}
}
CItem* pItem = NULL;
if (nItemIndex > 0)
{
#ifdef QUEST_COLLECT_MOD_10162021
if (isBoxCollectNpc)
{
for (int i = 0; i < MAX_PRODUCTS_FROM_NPC; i++)
{
itemIndexProduct[i] = pNPC->m_proto->m_product[i];
nItemAmount = GetRandom(1, 10);
pItem = gserver->m_itemProtoList.CreateItem(itemIndexProduct[i], -1, 0, 0, nItemAmount);
if(itemIndexProduct[i] == 0)
continue;
if (pItem)
{
if (pItem->m_itemProto->getItemIndex() != itemIndexProduct[i])
{
GAMELOG << init("Hack Character", ch) << "Invalid Item" << end;
return;
}
if (ch->m_inventory.addItem(pItem) == false)
{
GAMELOG << init("Create Item Fail", ch) << end;
delete pItem;
pItem = NULL;
nItemIndex = 0;
GAMELOG << init("QUEST COLLECT FAIL", ch)
<< "FULL INVEN"
<< end;
}
}
}
}
#endif
if (!isBoxCollectNpc)
pItem = gserver->m_itemProtoList.CreateItem(nItemIndex, -1, 0, 0, nItemAmount);
if (pItem && !isBoxCollectNpc)
{
if (ch->m_inventory.addItem(pItem) == false)
{
delete pItem;
pItem = NULL;
nItemIndex = 0;
GAMELOG << init("QUEST COLLECT FAIL" , ch)
<< "FULL INVEN"
<< end;
}
}
else
{
nItemIndex = 0;
}
}
else
{
nItemIndex = 0;
}
{
CNetMsg::SP rmsg(new CNetMsg);
QuestCollectMsg(rmsg, nNPCIndex, ch->m_index, nItemIndex);
pNPC->m_pArea->SendToCell(rmsg, pNPC, true);
}
DelAttackList(pNPC);
ch->m_pArea->CharFromCell(pNPC, true);
ch->m_pArea->DelNPC(pNPC);
pNPC = NULL;
}
else
{
CNetMsg::SP rmsg(new CNetMsg);
QuestCollectMsg(rmsg, nNPCIndex, ch->m_index, nItemIndex);
pNPC->m_pArea->SendToCell(rmsg, pNPC, true);
}
}
In the code you'll notice :
bool isBoxCollectNpc = false;
//replace where it says m_idNum == with your npc id
//replace here
if (pNPC->m_idNum == 1702 || pNPC->m_idNum == 1703 || pNPC->m_idNum == 1711)
isBoxCollectNpc = true;
you'll also notice item amount is random between 1,10 you can modify this to be different for each npc if you want or set your own custom range .
//modify the following value to get more or less items when collecting.
nItemAmount = GetRandom(1, 10);
Instead of only collecting 1 item from a monster you can do 5 items.
you'll have to set the flag of the npc to the following. add the Quest Collect flag
Youll see the Product 0-5 filled out you can add up to 5 items for the drop .
replace the id's with the item you want them to drop
Once you collect from one of the NPCs it will look like the following as example.
If you think this code is useful, give it a thumbs up.

