PDA

View Full Version : Check if itemid exists, with Perl


revloc02c
09-16-2011, 10:35 PM
I made a quest where characters can create items that is similar to what Sonikboom did here (http://www.eqemulator.org/forums/showthread.php?t=33666). Items cannot be redeemed until the server resets which he says he does every night. His script then checks to see if a day has passed before he redeems the new item.

Is there a way in Perl to check to see if an item exists? If it does summon it, and if not tell the character they'll have to wait until server resets.

Tabasco
09-17-2011, 01:00 AM
I don't see any existing function that will do what you want.
With DBI installed you could query the tiems table, but that doesn't guarantee that the item actually exists in the shared memory block.

You could try this though:

questmgr.h (somewhere under public:)

bool IsValidItem(int32 itemid);

questmgr.cpp

bool QuestManager::IsValidItem(int32 itemid)
{
return(database.GetItem(itemid));
}

perlparser.cpp

XS(XS__IsValidItem);
XS(XS__IsValidItem)
{
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: IsValidItem(itemid)");

int32 itemid = (int32)SvUV(ST(0));
bool RETVAL;
dXSTARG;


RETVAL = quest_manager.IsValidItem(itemid);
XSprePUSH; PUSHu((IV)RETVAL);

XSRETURN(1);
}

Then add to the boot_quest function in perlparser.cpp

newXS(strcpy(buf, "IsValidItem"), XS__IsValidItem, file);


I can test it fully in the morning, but for now I can at least tell you that it compiles.

trevius
09-17-2011, 02:20 AM
I think something like this may work for you. You can look to see if the variable below is 0 or if it is not equal to the item ID you are feeding the command.


my $ItemID = 1001; # Set item id to verify here
my $VerifiedID = $client->GetItemStat($ItemID, "id");
if (!$VerifiedID)
{
quest::say("This item does not yet exist.");
}
else
{
quest::say("This item exists.");
}

Haven't actually tested this, but I think it will work.

revloc02c
09-17-2011, 10:58 AM
Perfect Trev, it works.

That's just the kind of trick I was trying to find. Thank you.