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

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

Reply
 
Thread Tools Display Modes
  #1  
Old 04-04-2004, 09:58 AM
sheck
Fire Beetle
 
Join Date: Mar 2004
Posts: 10
Default getting item names

Is there a quest function that will return an item's name given it's id number? Not that it would be that difficult to write one, just wondering if one is already available...

Just an example, but rather than typing "rusty warhammer" I'd like to replace it with someFunction($item1), where someFunction fetches the item's name from the DB:
Code:
sub EVENT_ITEM{
	if($item1==6016){
		quest::say("Ooh, a rusty warhammer - here's your reward!");
		quest::givecash(5,0,0,0);
		quest::exp(100);
	}
	return 1;
}
Thanks,

Jason
Reply With Quote
  #2  
Old 04-05-2004, 06:23 AM
m0oni9
Hill Giant
 
Join Date: Dec 2003
Posts: 166
Default

The best way to accomplish this would be to call a function on the server, and have it returned to perl. I was working on a good way to do this, but it kind of petered out. The way I have things now, I can get something like this to work:

Code:
sub EVENT_ITEM{
   if($item1==6016){
      $iname = sc::getItemName($item1);
      quest::say("Ooh, $iname - here's your reward!");
   }
}
The only problem is that there is a module.pm file that needs to be present, and there really should be another way to do this. I made some progress (no shared library, no "use module"). Eglin mentioned looking at how pickle does this (never got around to this, sadly). I'm going to take another whack at this in the next day or two, and see if I can come up with anything.
Reply With Quote
  #3  
Old 04-06-2004, 04:17 PM
m0oni9
Hill Giant
 
Join Date: Dec 2003
Posts: 166
Default

This is more of a pre-submission. I think I have this worked out. I'll spare the details to create the code, and just give it to you. I've trimmed this down to the least amount of code to keep it workable, I think.. These changes all occur within the zone directory.

First, we are going to create a new file. Name it cperl.cpp, and paste into it the following:
Code:
#ifdef EMBPERL

#include "masterentity.h"

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "cperl.h"

extern Database database;

const char *getItemName(unsigned itemid)
{
  const Item_Struct* item = NULL;
  item = database.GetItem(itemid);

  if (item)
    return item->Name;
  else
    return NULL;
}

XS(XS_qc_getItemName); /* prototype to pass -Wmissing-prototypes */
XS(XS_qc_getItemName)
{
    dXSARGS;
    if (items != 1)
        Perl_croak(aTHX_ "Usage: quest::getItemName(itemid)");
    {
        unsigned        itemid = (unsigned)SvUV(ST(0));
        const char *    RETVAL;
        dXSTARG;
    RETVAL = getItemName(itemid);
        sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}


EXTERN_C XS(boot_qc); /* prototype to pass -Wmissing-prototypes */
EXTERN_C XS(boot_qc)
{
    dXSARGS;
    char* file = __FILE__;

    XS_VERSION_BOOTCHECK ;

        newXS("quest::getItemName", XS_qc_getItemName, file);

    XSRETURN_YES;
}

#endif // EMBPERL
Now, create a file named cperl.h. Paste this into it:

Code:
#ifndef CPERL_H
#define CPERL_H
const char *getItemName(unsigned itemid);
XS(XS_qc_getItemName); /* prototype to pass -Wmissing-prototypes */
EXTERN_C XS(boot_qc); /* prototype to pass -Wmissing-prototypes */
#endif // CPERL_H
Now, open up embperl.cpp. At about line 17, you will have:
Code:
#include "embperl.h"
Below this, insert:
Code:
#include "cperl.h"
At about line 30, you will see the following:
Code:
EXTERN_C void xs_init(pTHX) { char *file = __FILE__; newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); }
We're going to add a new line to it (and put in some line breaks for readability sake):
Code:
EXTERN_C void xs_init(pTHX) {
  char *file = __FILE__;
  newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
  newXS("quest::boot_qc", boot_qc, file);
}
Now, open up embparser.cpp. About line 380 you will have this:
Code:
perl->eval(
"{"
"package quest;"
"@cmd_queue = ();"
Between the "package" and "@cmd_queue" lines we want to paste in "&boot_qc;". It will look like this:
Code:
perl->eval(
"{"
"package quest;"
"&boot_qc;"
"@cmd_queue = ();"
Finally, we need to change makefile.perl -- I don't know what you windows users do to add a file to the project. At the veerrrryyy end of SF=.... (line 14) we are going to add cperl.o. It will then look like this:
Code:
../common/EMuShareMem.o ../common/EQEMuError.o beacon.o \
.obj/debug.o .obj/database.o .obj/Item.o .obj/misc.o \
doors.o command.o cperl.o
Note, if you don't have beacon.o in there, that's because I added it to my makefile so that it would compile. You should do the same if you don't have it included in the SF=... line. Recompile, and you should now be able to use your script:

Code:
sub EVENT_ITEM {
  quest::say("Ooh, a " . quest::getItemName($item1) . "! Here's your reward!");
  quest::givecash(5,0,0,0);
  quest::exp(100);
}
Have not been able to get anyone besides myself to test this code yet, so please let me know how you fare.

(last update 4/7/04)
Reply With Quote
  #4  
Old 04-25-2004, 01:22 AM
Scorpious2k's Avatar
Scorpious2k
Demi-God
 
Join Date: Mar 2003
Location: USA
Posts: 1,067
Default

I've put this on our server with the intention of moving it to cvs from there. This seems to be the answer to the one problem with perl - the inability to get dynamic values back from the server.

I think we have the start of a solution for that here. Thanks for the great work m0oni9!
__________________
Maybe I should try making one of these servers...
Reply With Quote
Reply


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 02:44 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