Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-08-2004, 04:41 PM
smogo
Discordant
 
Join Date: Jan 2004
Location: 47
Posts: 339
Default hasitem available for perl quests

This is an implementation of the hasitem() for perl quests.

mOoni9 had started to work on it in another post, while the code here does not call C++ back, instead it does push the hasitem variable when an event is triggered, ala itemcount.

in PerlembParser::Event, creates a variable that the perl interpreter makes available to the perl script in the quest. This variable is created (and reset) for each event where a character is involved (including EVENT_SLAY, EVENT_DEATH, ...)

The variable is a hash of array references. It may seem complicated at first, but usage in perl is easy. It complies to .qst behavior in most (if not all) ways, and extends it.

The following code is to be added to embparser.cpp, in PerlembParser::Event, at line 189 for example (0.5.3dr3, feb 2004).
Code:
#define HASITEM_FIRST 0
#define HASITEM_LAST 29 // this includes worn plus 8 base slots
#define HASITEM_ISNULLITEM(item) ((item==-1) || (item==0))
  if(mob && mob->IsClient()){
    string hashname = packagename + std::string("::hasitem");
    LogFile->write(EQEMuLog::Debug, "starting hasitem, on : %s",hashname.c_str()
);

    //start with an empty hash
    perl->eval(std::string("%").append(hashname).append(" = ();").c_str());

    for(int slot=HASITEM_FIRST; slot<=HASITEM_LAST;slot++){
      char *hi_decl=NULL;
      int itemid=mob->CastToClient()->GetItemIDAt(slot);
      if(!HASITEM_ISNULLITEM(itemid)){
        MakeAnyLenString(&hi_decl, "push (@{$%s{%d}},%d);",hashname.c_str(),itemid,slot);
        LogFile->write(EQEMuLog::Debug, "declare hasitem : %s",hi_decl);
        perl->eval(hi_decl);
      }
    }

  }
This calls the GetItemIDAt of the character for all slots 0 to 29. To include the cursor, go up to 30. To also get what's inside containers, include higher numbers.

It builds a hash where item id is the key, and the value is a reference to an array containing the slots. This allows to test for existence (if the key exists), count number of slots occupied by this object type (size of array), and get the slots id from the array (for example to check if character is currently wielding a weapon, or just has it in his inventory).

Here is a sample perl quest, that leads to the screenshot.

Code:
sub EVENT_SAY{
  quest::say("i say 17005");  # there a glitch in NPCMessage's code

  #if($hasitem{9990}) { quest::say("you have item 9990");}
  #if($hasitem{9991}) { quest::say("you have item 9991");}
  #if($hasitem{9997}) { quest::say("you have item 9997");}
  #if($hasitem{17005}) { quest::say("you have item 17005");}


  if($text =~/Hail/i){
    quest::say("Hello $name, i'm an inspector, and can [inspect you] if you ask.");
    return 1;
  }

  if($text =~ /inspect me/i){
    quest::say("inspecting you");

    #test for a cloth cap
    if($hasitem{"1001"}){
        quest::say("you have at least one cloth cap");
    }
    #test and count them
    if($hasitem{"1001"}){
        quest::say("you have ". scalar @{$hasitem{1001}} ." slots holding a cloth cap");
    }
    #test and tell what slot their' at
    if($hasitem{"1001"}){
        quest::say("you are holding cloth caps in slots [".join(",", @{$hasitem{1001}})."].");
    }

    #dump full %hasitem content
    for $itemnum (keys %hasitem){
      quest::say("you are wielding / carrying item id $itemnum .");
      quest::say("in ". scalar @{$hasitem{$itemnum}} ." slot(s), [".join(",",@{$hasitem{$itemnum}})."].");
    }
    return 1;
  }

  return 0;
}
Any feedback is appreciated on this please
Reply With Quote
 


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 09:46 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