Openkore.com

OpenKore Forums
It is currently 23 Sep 2018, 04:44

All times are UTC - 5 hours [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: How to get item ID from item name.
PostPosted: 30 May 2008, 11:05 
Offline
Human
Human
User avatar

Joined: 27 Apr 2008, 12:52
Posts: 46
Location: Russia
I need to get ID of item with some name (item not in inventory or storage, I have just name like Grape, Oridecon, Apple only). Help me please!


Top
 Profile  
 
 Post subject: Re: How to get item ID from item name.
PostPosted: 30 May 2008, 12:08 
Offline
Perl Monk
Perl Monk

Joined: 04 Apr 2008, 17:26
Posts: 811
Not sure if it works, but this should help you out. Creates a new variable that allows you to access item names by their ID. It simply reverses the %items_lut hash.
Code:
package itemrev;

use strict;
use Plugins;
use Globals qw(%items_lut);

Plugins::register('itemrev', 'Reverse item table.', \&onUnload);

my $hooks = Plugins::addHooks(
   ['start3', \&ItemRev, undef]
);

my %items_rev;

sub onLoad {
   return 1;
}

sub ItemRev {
   foreach (keys %items_lut) {
      $items_rev{$items_lut{$_}} = $_;
   }
}

sub onUnload {
   Plugins::delHooks($hooks);
}

1;

_________________
cs : ee : realist


Top
 Profile  
 
 Post subject: Re: How to get item ID from item name.
PostPosted: 30 May 2008, 12:36 
Offline
Human
Human
User avatar

Joined: 27 Apr 2008, 12:52
Posts: 46
Location: Russia
I wonder why there is no function like GetItemIdByName($itemname) :D :D


Top
 Profile  
 
 Post subject: Re: How to get item ID from item name.
PostPosted: 30 May 2008, 17:07 
Offline
Perl Monk
Perl Monk

Joined: 04 Apr 2008, 17:26
Posts: 811
The only reference I could find for items.txt (outside functions.pl) was this:
Code:
         # find the item ID if we don't know it yet
         if ($args->{itemID} eq "") {
            if ($args->{invIndex} && $char->inventory->get($args->{invIndex})) {
               # if we have the item in our inventory, we can quickly get the nameID
               $args->{itemID} = $char->inventory->get($args->{invIndex})->{nameID};
            } else {
               # scan the entire items.txt file (this is slow)
               foreach (keys %items_lut) {
                  if (lc($items_lut{$_}) eq lc($config{"buyAuto_$args->{index}"})) {
                     $args->{itemID} = $_;
                  }
               }
            }
            if ($args->{itemID} eq "") {
               # the specified item doesn't even exist
               # don't try this index again
               $args->{index_failed}{$args->{index}} = 1;
               debug "buyAuto index $args->{index} failed, item doesn't exist\n", "npc";
               return;
            }
         }

Which leads me to believe there's no function for it, or whoever wrote this didn't know if there was a function, either.

_________________
cs : ee : realist


Top
 Profile  
 
 Post subject: Re: How to get item ID from item name.
PostPosted: 30 May 2008, 20:07 
Offline
Perl Monk
Perl Monk

Joined: 04 Apr 2008, 03:08
Posts: 416
Code:
my $item = InventoryList::InventoryList->getByName("Fly Wing");
my $id = $item->{nameID};


easy, read the item.pm in actor::item for more info


Top
 Profile  
 
 Post subject: Re: How to get item ID from item name.
PostPosted: 31 May 2008, 07:30 
Offline
Human
Human
User avatar

Joined: 27 Apr 2008, 12:52
Posts: 46
Location: Russia
Bibian, I just write a test plugin and it does not work!
Quote:
package test;

use strict;
use Globals;
use Plugins;
use Log qw(message);
use Commands;
use InventoryList;

Plugins::register('itemid', 'show item id by its name', \&unload, \&unload);

my $command = Commands::register(
['itemid','show item id by its name',\&show]
);

sub unload {
Commands::unregister($command);
}

sub show {
my (undef, $args) = @_;
my @args = split(/ /, $args);
my $item = InventoryList::InventoryList->getByName($args[0]);
my $id = $item->{nameID};
message($args[0]." - ".$id."\n");
}

return 1;


Top
 Profile  
 
 Post subject: Re: How to get item ID from item name.
PostPosted: 31 May 2008, 08:12 
Offline
Human
Human
User avatar

Joined: 04 Apr 2008, 22:55
Posts: 37
Location: Thailand
Try this.

Code:
my $id = findKeyString2(\%items_lut, $args[0]);
if (ref($id) eq 'ARRAY') {
   message($args[0]." - ".$_."\n") foreach (@{$id});
} else {
   message($args[0]." - ".$id."\n");
}

sub findKeyString2 {
   my ($r_hash, $ID) = @_;
   my @ret;

   foreach (sort {$a <=> $b} keys %{$r_hash}) {
      push(@ret, $_) if ($ID eq $r_hash->{$_});
   }

   return ($#ret <= 0) ? $ret[0] : \@ret;
}

_________________
I may make you misunderstand. Because my English isn't good enough. So Sorry.
Image


Top
 Profile  
 
 Post subject: Re: How to get item ID from item name.
PostPosted: 31 May 2008, 08:47 
Offline
Human
Human
User avatar

Joined: 27 Apr 2008, 12:52
Posts: 46
Location: Russia
UltimaWeapon, thx.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group