Basically, I am just trying to create a procedure that will override the autoSell - instead of selling the items (sell = 1 in items_control) to NPC, this will trade them to a defined player. I'm no perl programmer but I do understand some of the program flow, so it led me to the following lines of code. I believe everything's working out smooth except for sendDealAddItem - the problem is it doesn't remove the items from the player inventory after adding them to the deal... any input will be greatly appreciated, thanks

Code: Select all
$args->{nextItem} = 0 unless $args->{nextItem};
for (my $i = $args->{nextItem}; $i < @{$char->inventory->getItems()}; $i++) {
my $item = $char->inventory->getItems()->[$i];
next if $item->{equipped};
my $control = items_control($item->{name});
if ($control->{sell} && $item->{amount} > $control->{keep}) {
if ($args->{lastIndex} == $item->{index} && timeOut($timeout{'ai_sellAuto_giveup'})) {
return;
} elsif ($args->{lastIndex} != $item->{index}) {
$timeout{ai_sellAuto_giveup}{time} = time;
}
undef $args->{done};
$args->{lastIndex} = $item->{index};
$messageSender->sendDealAddItem($item->{index}, $item->{amount} - $control->{keep});
$timeout{ai_dealAuto}{time} = time;
$args->{nextItem} = $i;
$args->{'dealAddItemCount'} += 1;
if ($args->{'dealAddItemCount'} == 10) {
$args->{'dealAddItemMore'} = 1 if ($i < @{$char->inventory->getItems()});
last;
}
#return;
}
}