EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   Check if itemid exists, with Perl (https://www.eqemulator.org/forums/showthread.php?t=34188)

revloc02c 09-16-2011 10:35 PM

Check if itemid exists, with Perl
 
I made a quest where characters can create items that is similar to what Sonikboom did here. 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:)
Code:

bool IsValidItem(int32 itemid);
questmgr.cpp
Code:

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

perlparser.cpp
Code:

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
Code:

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.

Code:

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.


All times are GMT -4. The time now is 11:24 AM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.