Openkore.com

OpenKore Forums
It is currently 18 Aug 2017, 10:21

All times are UTC - 5 hours [ DST ]





Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: [plugin] bulkbuyer - buy all items from npc in one deal.
PostPosted: 13 Feb 2017, 09:45 
Offline
Developers
Developers

Joined: 01 Nov 2008, 15:31
Posts: 285
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 21 times

_________________
Please use pin function for uploading your file contents!
Top
 Profile  
 
 Post subject: Re: [plugin] bulkbuyer - buy all items from npc in one deal.
PostPosted: 15 Jun 2017, 14:54 
Offline
Moderators
Moderators
User avatar

Joined: 16 Dec 2011, 02:53
Posts: 1137
Location: Brazil
It's a great developing.

_________________
"'There are three things all wise men fear: the sea in storm, a night with no moon, and the anger of a gentle man.'" :P

Click here and travel to a new world -> Newbies
Read before asking something.
How to connect to private servers


Top
 Profile  
 
 Post subject: Re: [plugin] bulkbuyer - buy all items from npc in one deal.
PostPosted: 09 Aug 2017, 09:53 
Offline
Human
Human

Joined: 11 Jun 2014, 12:13
Posts: 32
the plugin is work well but it has something wrong when i put it on my OK that i downloaded from github
the buy cannot count the least item on inventory
my config is buy fly wing min 0 max 100
but the kore still buy 100 fly wing when in my inventory still have some

before i use the plugin kore will count the item that want to buy in invetory the buy the rest not always buy for the max mount.
and something wrong inside the CoreLogic file, my kore cannot use item and when my config partyAutoShare is 1 it will be red console
Code:
Cannot setup the party.


Btw i put the code inside the CoreLogic manually too.
but still same. :D

that is my review sir Mortimal, nice work !!! :D

this is the last CoreLogic.pm i know from github that i use.
https://github.com/OpenKore/openkore/bl ... reLogic.pm


Top
 Profile  
 
 Post subject: Re: [plugin] bulkbuyer - buy all items from npc in one deal.
PostPosted: 11 Aug 2017, 23:49 
Offline
Developers
Developers

Joined: 01 Nov 2008, 15:31
Posts: 285
il check that when have some time.... i think i know the buggy part... just not playing now to do that fast

_________________
Please use pin function for uploading your file contents!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


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