LCKB
Add item with Server Sources - Printable Version

+- LCKB (https://lckb.dev/forum)
+-- Forum: ** OLD LCKB DATABASE ** (https://lckb.dev/forum/forumdisplay.php?fid=109)
+--- Forum: Guides & Help Section (https://lckb.dev/forum/forumdisplay.php?fid=193)
+---- Forum: Tutorials & Guides (https://lckb.dev/forum/forumdisplay.php?fid=124)
+----- Forum: Ep4 Guides (https://lckb.dev/forum/forumdisplay.php?fid=125)
+----- Thread: Add item with Server Sources (/showthread.php?tid=1170)



- Scura - 03-30-2021


Hi!

I wrote a simple bool function which allow you to add items with the gameserver! Not much difficult and maybe all of you already now ... but who cares, maybe someone will update it 

static bool MakeItems(CPC* pc, CItem* pItem)
{

// if pointers are null
if (pc == NULL || pItem == NULL)
{
delete pc;
delete pItem;
LOG_ERROR(" -> NULL POINTER DETECTED!!!!");
return false;
}

//if additem function encounter some problems, we are gonna catch it
if (pc->m_inventory.addItem(pItem) == false)
{
delete pc;
delete pItem;
LOG_ERROR(" -> ADD ITEM ERROR DETECTED!!!!");
return false;
}

//else all well, can return
return true;
}

 




- Scura - 03-30-2021


Ofc make sure to check if inventory space is enought before call it. 

if(pc->m_inventory.getEmptyCount() < n) /* where n is the number of the items that you are gonna add */
{
CNetMsg::SP rmsg(new CNetMsg);
SysFullInventoryMsg(rmsg, 0);
SEND_Q(rmsg, pc->m_desc);
return false;
}

NB: that function will not check stackable items, you can always recode the function getEmptyCount where the function will get the number of the items that you are trying to create and check in the "pc inventory" if there are other stackable items in the inventory.

You can easy check for items in the inventory with that function:

//that should work ONLY with stackable items instead ...
if (pc->m_inventory.FindByDBIndex(x) != NULL)
{
bool MakeItems(CPC* pc, CItem* pItem)
}
else if(pc->m_inventory.getEmptyCount() < n) /* where n is the number of the items that you are gonna add */
{
CNetMsg::SP rmsg(new CNetMsg);
SysFullInventoryMsg(rmsg, 0);
SEND_Q(rmsg, pc->m_desc);
return false;
{
else
{
bool MakeItems(CPC* pc, CItem* pItem)
}

pretty [CeNsOrEd] code i know, but that's whould works

With that you should allow the players to gain the rewards even if the inventory is full, by allowing the function "additems" to perform the addition even if the pc have the inventory full.