all credit for this goes to aza77, i'm just post it before it gets lost:
questmgr.cpp
Code:
int QuestManager::collectitems_processSlot(sint16 slot_id, uint32 item_id,
bool remove)
{
ItemInst *item;
int quantity = 0;
item = initiator->GetInv().GetItem(slot_id);
// If we have found matching item, add quantity
if (item && item->GetID() == item_id)
{
// If item is stackable, add its charges (quantity)
if (item->IsStackable())
{
quantity = item->GetCharges();
}
else
{
quantity = 1;
}
// Remove item from inventory
if (remove)
{
initiator->DeleteItemInInventory(slot_id, 0, true);
}
}
return quantity;
}
// Returns number of item_id that exist in inventory
// If remove is true, items are removed as they are counted.
int QuestManager::collectitems(uint32 item_id, bool remove)
{
int quantity = 0;
int slot_id;
for (slot_id = 22; slot_id <= 29; ++slot_id)
{
quantity += collectitems_processSlot(slot_id, item_id, remove);
}
for (slot_id = 251; slot_id <= 330; ++slot_id)
{
quantity += collectitems_processSlot(slot_id, item_id, remove);
}
return quantity;
}
questmgr.h non-protected area:
Code:
int collectitems(uint32 item_id, bool remove);
int collectitems_processSlot(sint16 slot_id, uint32 item_id, bool remove);
perlparser.cpp
Code:
XS(XS__collectitems);
XS(XS__collectitems)
{
dXSARGS;
if (items != 2)
Perl_croak(aTHX_ "Usage: collectitems(item_id, remove?)");
uint32 item_id = (int)SvIV(ST(0));
bool remove = ((int)SvIV(ST(1))) == 0?false:true;
int quantity =
quest_manager.collectitems(item_id, remove);
XSRETURN_IV(quantity);
}
let me know if i'm missing anything. I think I got it all, though..
example of how it would work in a script:
Code:
sub EVENT_SAY {
my $itemstotake = quest::collectitems(1337, 0);
my $credittostore = $qglobals{credit} ? $qglobals{credit} : 0;
if($text=~/hail/i)
{
$credittostore += $itemstotake;
quest::collectitems(1337, 1);
quest::setglobal("credit", $credittostore, 5, "F");
quest::say("Ha! I will take all those items off you now, and tell you how many I have taken, while storing it in a global that adds items to itself! All at once! Muhahaha!");
quest::say("You now have $credittostore items!");
}
}
hopefully that's not too confusing on how to use it.
the script basically takes items from your character, or counts how many you have if you specify 0 on the remove flag. pretty neat command.
have fun!