Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub EVENT_COMBINE {
- if (plugin::custom_combines($container_slot) != 0) {
- return 1; #did a custom combine?
- }
- }
- sub custom_combines {
- my $container_slot = $_[0];
- my $client = plugin::val('$client');
- my $bag = $client->GetItemAt($container_slot);
- my $bag_id = -1;
- my $prefix = "item";
- my $inventory = $client->GetInventory();
- my $required_bag_id = 17118;
- my $bag_slots = quest::getitemstat($required_bag_id, "bagslots");
- for $x ( 1 .. 10) {
- if ($container_slot == quest::getinventoryslotid("general$x")) {
- $bag_id = $x;
- last;
- }
- }
- if ($bag_id == -1) {
- return 0; #We aren't combing from inventory...
- } elsif ($client->GetItemIDAt($container_slot) != $required_bag_id) {
- return 0; #not the required bag_id for custom combines
- }
- my %recipes = (
- 1 => {
- "components" => [[66177,66176]],
- "products" => [[66175],[1]]
- },
- 2 => {
- "components" => [[1001,1002]],
- "products" => [43345,1]
- },
- 3 => {
- "components" => [[66175]],
- "products" => [[66177,66176],[1,1]],
- },
- 4 => {
- "components" => [[7254]],
- "products" => [[7256],[1]]
- },
- 5 => {
- "components" => [[7256]],
- "products" => [[7254],[1]]
- },
- 6 => {
- "components" => [17354],
- "products" => [[1001,9991],[2,20]]
- },
- 7 => {
- "components" => [[9991,9991,9991,9991]],
- "products" => [[1001 .. 1012],[1]] #Charges for large arrays can be ignored if you want them all to be 1~
- }
- );
- my @combined_items = ();
- my ($item0, $item1, $item2, $item3, $item4, $item5, $item6, $item7, $item8, $item9) = 0;
- if ($bag_id != -1) {
- for $y ( 0 .. $bag_slots-1) {
- my $cur_slot = quest::getinventoryslotid("general".$bag_id."bag.begin") + $y;
- ${$prefix . $y} = $client->GetItemAt($cur_slot);
- if (${$prefix . $y}) {
- push(@combined_items, ${$prefix . $y}->GetID());
- }
- }
- }
- @combined_items = sort {$a <=> $b} @combined_items; #Sort items by ID
- my @required_item = ();
- foreach my $val (values %recipes) {
- my @current = $val;
- #@required_item = ();
- @required_item = @{$current[0]{"components"}[0]};
- @required_item = sort {$a <=> $b} @required_item; #Sort items by ID
- if (@combined_items ~~ @required_item) {
- #Our arrays are a matchnow for fun part!
- #We can still fail if the item is lore and they have it...
- my @products = @{$current[0]{"products"}[0]};
- my @products_charges = @{$current[0]{"products"}[1]};
- foreach (@products) {
- my $loregroup = quest::getitemstat($_, "loregroup");
- my $max_slot_ignore = quest::getinventoryslotid("general".$bag_id."bag.end");
- my $low_slot_ignore =quest::getinventoryslotid("general".$bag_id."bag.begin");
- my $slot_found = $inventory->HasItemByLoreGroup($loregroup);
- if ($loregroup > 0 && $slot_found != -1 && !($slot_found<= $max_slot_ignore && $slot_found >= $low_slot_ignore)) { #Allow LOREGROUP items to create new versions of themselves
- $client->Message(13, "Results would end in Lore conflict with item " . quest::varlink($_) . "!");
- return -1;
- } elsif ($loregroup == -1 && plugin::check_hasitem($client, $_)) {
- $client->Message(13, "Results would end in Lore conflict with item " . quest::varlink($_) . "!");
- return -1;
- }
- }
- #clear the bag...
- for $j (0 .. $bag_slots-1) {
- my $cur_del = quest::getinventoryslotid("general".$bag_id."bag.begin") + $j;
- my $item_d = $client->GetItemAt($cur_del);
- if ($item_d) {
- $client->DeleteItemInInventory($cur_del, 0, 1);
- }
- }
- #Time to summon all the products!
- my $cur_stack = 0;
- foreach (@products) {
- my $sum_stackable = quest::getitemstat($_, "stackable");
- if ($sum_stackable) {
- quest::summonitem($_, $products_charges[$cur_stack]);
- $client->Message(335, "You fashioned the items into a new item " . quest::varlink($_) . "!");
- } else {
- if (!$products_charges[$cur_stack]) { #For large arrays of items that are all 1.. so you don't have to put 1s for all of them..
- $products_charges[$cur_stack] = 1;
- }
- for $s (1 .. $products_charges[$cur_stack]) {
- quest::summonitem($_, 1);
- }
- $client->Message(335, "You fashioned the items into a new item " . quest::varlink($_) . "!");
- }
- $cur_stack++;
- }
- return 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement