Openkore.com

OpenKore Forums
It is currently 27 Mar 2017, 02:41

All times are UTC - 5 hours [ DST ]





Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: [plugin] bulkbuyer - buy all items from npc in one deal.
PostPosted: 13 Feb 2017, 09:45 
Offline
The Way Of Human
The Way Of Human

Joined: 01 Nov 2008, 15:31
Posts: 158
So i wrote this to buy items from same npc if is set in config. And i need testers :)

Make changes from manual in commented section:

From Gist

Code:
#########################################################################
# This software is open source, licensed under the GNU General Public
# License, version 2.
# Basically, this means that you're allowed to modify and distribute
# this software. However, if you distribute modified versions, you MUST
# also distribute the source code.
# See http://www.gnu.org/licenses/gpl.html for the full license.
#########################################################################
# list former for buying items bulk from same npc
# Mortimal 13.02.2017
#########################################################################
# Manual:
# Edit CoreLogic.pm -> sub processAutoBuy {...}
#
# Remove:
#
# $messageSender->sendBuyBulk([{itemID  => $args->{itemID}, amount => ($maxbuy > $needbuy) ? $needbuy : $maxbuy}]);
#
# Put instead:
#
# my @bulkitemlist;
# push (@bulkitemlist,{itemID  => $args->{itemID}, amount => ($maxbuy > $needbuy) ? $needbuy : $maxbuy});
# Plugins::callHook( 'buy_ready', { items => \@bulkitemlist , index => $args->{index}});
# $messageSender->sendBuyBulk(\@bulkitemlist);
#########################################################################


package bulkbuyer;

use Globals qw($char %config %items_lut);
use Plugins;
use Log qw(warning);
use Translation qw(T TF);

return unless
Plugins::register('bulkbuyer', 'Buying bulk from the same npc', \&on_unload);

my $hooks = Plugins::addHooks(
      ['buy_ready', \&onBuyReady],
   );

sub on_unload {
   Plugins::delHook($hooks);
}

sub onBuyReady{
   my $bulkhash = $_[1]->{items};
   my $exstitemid = $_[1]->{index};
   my $zenyleft = $char->{zeny} - (@$bulkhash[0]->{amount} * $config{"buyAuto_$exstitemid"."_price"});

   
   for (my $i = 1; exists $config{"buyAuto_$i"}; $i++)
   {
      
      my $item = $char->inventory->getByName($config{"buyAuto_$i"});
      if ($i != $exstitemid
         && $config{"buyAuto_$exstitemid"."_npc"} eq $config{"buyAuto_$i"."_npc"}
          && $config{"buyAuto_$i"."_minAmount"} ne ""
         && $config{"buyAuto_$i"."_maxAmount"} ne ""
         && $config{"buyAuto_$i"."_disabled"} != 1
         && !exists($bulkhash{index}->{$config{"buyAuto_$i"}})
         && (!$item
               || ($item->{amount} <= $config{"buyAuto_$i"."_minAmount"}
                  && $item->{amount} < $config{"buyAuto_$i"."_maxAmount"}
                  )
            )
         )
      {
         my $maxbuy = ($config{"buyAuto_$i"."_price"}) ? int($zenyleft/$config{"buyAuto_$i"."_price"}) : 30000;
         my $needbuy = $config{"buyAuto_$i"."_maxAmount"};
         $needbuy -= $item->{amount} if ($item);
         
         my $sendamount = ($maxbuy > $needbuy) ? $needbuy : $maxbuy;

         if ($sendamount > 0)
         {
            $zenyleft -= $sendamount * $config{"buyAuto_$i"."_price"};
            my $buyindex;
            my $counter = 0;
            if ($item)
            {
               $buyindex = $item->{index};
            } else
            {
               foreach (keys %items_lut)
               {
                  if (lc($items_lut{$_}) eq lc($config{"buyAuto_$i"}))
                  {
                     $buyindex = $_;
                     $counter++;
                  }
               }
            }
            
            if (!$buyindex)
            {
               warning TF("No item id '%s' exists in items.txt. Not buying.\n", $config{"buyAuto_$i"});
            } elsif ($counter > 1)
            {
               warning TF("More than one item id '%s' exists in items.txt. Not buying.\n", $config{"buyAuto_$i"});
            } else
            {
               push (@$bulkhash, {itemID  => $buyindex, amount => $sendamount});
            }
         } else
         {
            warning TF("No zeny to buy even 1 '%s'. Skiped.\n", $config{"buyAuto_$i"});
         }
      }
   }
   return 1;
}

return 1;

Without my plugin:
Image

With my plugin:
Image

This is magic it works 4 times faster :lol:

AHTUNG!
You need to change config/sys.txt to enable my plugin even if you copied by archive.


Attachments:
File comment: OR YOU CAN EXTRACT THIS TO YOUR OPENKORE FOLDER
plugin.zip [29.43 KiB]
Downloaded 5 times

_________________
Please use pin function for uploading your file contents!
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

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