Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-16-2008, 07:57 AM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,449
Default quest::collectitems

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!
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 04:58 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3