Thanks for waiting lol
There are some syntax error in the new plugin but I get the idea
Brilliant that you thought of regex matching
I attach the modified version at the end
Now we have no problem getting our inventory index
But
$buyerID &
$buyingStoreID seem a little messy, causing the bot to disconnect when executing
sendBuyBulkBuyer
(It gets the right $buyerZenyLimit every time tho)
Note that the messy
$buyerID &
$buyingStoreID some time ""eat away" logging so you can't even see
SellToPlayer activated with in the first screenshot
Anyway I think we're getting close!
Plugin:
Code: Select all
package selltoplayer;
use strict;
use Plugins;
use Globals qw(%config $char $messageSender);
use Log qw(message);
use Misc qw(itemNameToID);
Plugins::register('selltoplayer', 'sells items to player buyer shop', \&Unload, \&Reload);
my $packetHook = Plugins::addHooks (
['packet_buying_store2', \&sellspecified, undef],
);
sub Reload {
message "selltoplayer plugin reloading, ", 'system';
Plugins::delHooks($packetHook);
}
sub Unload {
message "selltoplayer plugin unloading, ", 'system';
Plugins::delHooks($packetHook);
}
sub sellspecified {
my (undef, $args) = @_;
my ($buyerID, $buyingStoreID, $buyerZenyLimit, @itemList) = ($args->{buyerID}, $args->{buyingStoreID}, $args->{buyerZenyLimit}, @{$args->{itemList}});
message "BuyerID: ", 'info';
message "$buyerID", 'info';
message "\n", 'info';
message "BuyerZenyLimit: ", 'info';
message "$buyerZenyLimit", 'info';
message "\n", 'info';
message "BuyingStoreID: ", 'info';
message "$buyingStoreID", 'info';
message "\n\n", 'info';
message "SellToPlayer activated with: "."
Buyer ID - ".$buyerID.";
Buying store ID - ".$buyingStoreID.";
Buyer zeny limit - ".$buyerZenyLimit.".\n", 'info';
my $prefix;
for (my $i = 0; exists $config{$prefix = "sellToPlayer_$i"}; $i++) {
next unless my $item = $char->inventory->get($config{"${prefix}"})
&& !$config{"${prefix}_disabled"};
message "\nSellToPlayer cycling items.\n", 'info';
foreach my $itemInList (@itemList){
message "Buyer is buying: "."
Item name - ".$itemInList->{name}.";
Item ID - ".itemNameToID($itemInList->{name}).";
Amount - ".$itemInList->{amount}.";
Price - ". $itemInList->{price}.".\n", 'info';
my $itemGotByName = $char->inventory->getByName($config{"${prefix}"});
if ($itemGotByName =~ m/(.*)\s\(\d+\)/) {
$itemGotByName->{name} = $1
}
if ($itemGotByName =~ m/.*\s\((\d+)\)/) {
$itemGotByName->{ID} = $1
}
message "================\n", 'info';
message "Check selling item name: ". $itemGotByName->{name}."\n", 'info';
message "Check selling item inventory index: ".$itemGotByName->{ID}."\n", 'info';
message "Check selling item ID: ". $itemGotByName->{nameID}."\n", 'info';
message "Check selling item amount: ". $itemGotByName->{amount}."\n", 'info';
message "================\n\n", 'info';
next unless itemNameToID($itemInList->{name}) == $itemGotByName->{nameID};
next unless (!$config{"${prefix}_minPrice"} || $itemInList->{price} >= $config{"${prefix}_minPrice"});
my $maxSellAmount = $itemInList->{amount}>=$itemGotByName->{amount}?$itemGotByName->{amount}:$itemInList->{amount};
my $sellAmount = $maxSellAmount*$itemInList->{price} <= $buyerZenyLimit?$maxSellAmount:int($buyerZenyLimit/$itemInList->{price});
next if $sellAmount <= 0;
message "SellToPlayer sending sellpacket activated with:\n", 'info';
message "Item inventory index - ".$itemGotByName->{ID}."\n", 'info';
message "ID - ".$itemGotByName->{nameID}."\n", 'info';
message "Amount - ".$sellAmount."\n", 'info';
message "BuyerID - ", 'info';
message "$buyerID", 'info';
message "\nBuyingStoreID - ", 'info';
message "$buyingStoreID\n", 'info';
$messageSender->sendBuyBulkBuyer($buyerID, [{ID => $itemGotByName->{ID}, itemID => $itemGotByName->{nameID}, amount => $sellAmount}], $buyingStoreID);
}
}
}