Advertisement
Paldail

WTF IS THIS

Nov 5th, 2021 (edited)
1,833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.27 KB | None | 0 0
  1. sub EVENT_COMBINE {
  2.     if (plugin::custom_combines($container_slot) != 0) {
  3.         return 1; #did a custom combine?
  4.     }  
  5. }
  6.  
  7. sub custom_combines {
  8.     my $container_slot = $_[0];
  9.     my $client = plugin::val('$client');
  10.     my $bag = $client->GetItemAt($container_slot);
  11.     my $bag_id = -1;
  12.     my $prefix = "item";
  13.     my $inventory = $client->GetInventory();
  14.     my $required_bag_id = 17118;
  15.     my $bag_slots = quest::getitemstat($required_bag_id, "bagslots");
  16.    
  17.     for $x ( 1 .. 10) {
  18.         if ($container_slot == quest::getinventoryslotid("general$x")) {
  19.             $bag_id = $x;
  20.             last;
  21.         }
  22.     }
  23.    
  24.     if ($bag_id == -1) {
  25.         return 0; #We aren't combing from inventory...
  26.     } elsif ($client->GetItemIDAt($container_slot) != $required_bag_id) {
  27.         return 0; #not the required bag_id for custom combines
  28.     }
  29.    
  30.    
  31.     my %recipes = (
  32.         1 => {
  33.             "components" => [[66177,66176]],
  34.             "products" => [[66175],[1]]
  35.         },
  36.         2 => {
  37.             "components" => [[1001,1002]],
  38.             "products" => [43345,1]
  39.         },
  40.         3 => {
  41.             "components" => [[66175]],
  42.             "products" => [[66177,66176],[1,1]],
  43.         },
  44.         4 => {
  45.             "components" => [[7254]],
  46.             "products" => [[7256],[1]]
  47.         },
  48.         5 => {
  49.             "components" => [[7256]],
  50.             "products" => [[7254],[1]]
  51.         },
  52.         6 => {
  53.             "components" => [17354],
  54.             "products" => [[1001,9991],[2,20]]
  55.         },
  56.         7 => {
  57.             "components" => [[9991,9991,9991,9991]],
  58.             "products" => [[1001 .. 1012],[1]]  #Charges for large arrays can be ignored if you want them all to be 1~
  59.         }
  60.     );
  61.     my @combined_items = ();
  62.     my ($item0, $item1, $item2, $item3, $item4, $item5, $item6, $item7, $item8, $item9) = 0;
  63.     if ($bag_id != -1) {
  64.         for $y ( 0 .. $bag_slots-1) {
  65.             my $cur_slot = quest::getinventoryslotid("general".$bag_id."bag.begin") + $y;
  66.             ${$prefix . $y} = $client->GetItemAt($cur_slot);
  67.             if (${$prefix . $y}) {
  68.                 push(@combined_items, ${$prefix . $y}->GetID());
  69.             }
  70.         }
  71.     }
  72.     @combined_items = sort {$a <=> $b} @combined_items; #Sort items by ID
  73.    
  74.     my @required_item = ();
  75.     foreach my $val (values %recipes) {
  76.         my @current = $val;
  77.         #@required_item = ();
  78.         @required_item =  @{$current[0]{"components"}[0]};
  79.         @required_item = sort {$a <=> $b} @required_item; #Sort items by ID
  80.        
  81.         if (@combined_items ~~ @required_item) {
  82.             #Our arrays are a matchnow for fun part!
  83.            
  84.             #We can still fail if the item is lore and they have it...
  85.             my @products =  @{$current[0]{"products"}[0]};
  86.             my @products_charges =  @{$current[0]{"products"}[1]};
  87.            
  88.             foreach (@products) {
  89.                 my $loregroup = quest::getitemstat($_, "loregroup");
  90.                 my $max_slot_ignore = quest::getinventoryslotid("general".$bag_id."bag.end");
  91.                 my $low_slot_ignore =quest::getinventoryslotid("general".$bag_id."bag.begin");
  92.                 my $slot_found = $inventory->HasItemByLoreGroup($loregroup);
  93.                 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
  94.                     $client->Message(13, "Results would end in Lore conflict with item " . quest::varlink($_) . "!");
  95.                     return -1;
  96.                 } elsif ($loregroup == -1 && plugin::check_hasitem($client, $_)) {
  97.                     $client->Message(13, "Results would end in Lore conflict with item " . quest::varlink($_) . "!");
  98.                     return -1;
  99.                 }
  100.             }
  101.             #clear the bag...
  102.             for $j (0 .. $bag_slots-1) {
  103.                 my $cur_del = quest::getinventoryslotid("general".$bag_id."bag.begin") + $j;
  104.                 my $item_d = $client->GetItemAt($cur_del);
  105.                 if ($item_d) {
  106.                     $client->DeleteItemInInventory($cur_del, 0, 1);
  107.                 }
  108.             }
  109.            
  110.             #Time to summon all the products!
  111.             my $cur_stack = 0;
  112.             foreach (@products) {
  113.                 my $sum_stackable = quest::getitemstat($_, "stackable");
  114.                 if ($sum_stackable) {
  115.                     quest::summonitem($_, $products_charges[$cur_stack]);
  116.                     $client->Message(335, "You fashioned the items into a new item " . quest::varlink($_) . "!");
  117.                 } else {
  118.                     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..
  119.                         $products_charges[$cur_stack] = 1;
  120.                     }
  121.                     for $s (1 .. $products_charges[$cur_stack]) {
  122.                         quest::summonitem($_, 1);
  123.                     }
  124.                     $client->Message(335, "You fashioned the items into a new item " . quest::varlink($_) . "!");
  125.                 }
  126.                 $cur_stack++;
  127.             }
  128.             return 1;
  129.         }
  130.     }
  131.  
  132.     return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement