Paldail

Summon Into Inventory

Oct 6th, 2021 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 7.13 KB | None | 0 0
  1. sub summon_into_inventory {
  2.     my $client = $_[0];
  3.     my $itemid = $_[1];
  4.     my $amount = $_[2];
  5.    
  6.     my $aug1 = $_[3] ? $_[3] : 0;
  7.     my $aug2 = $_[4] ? $_[4] : 0;
  8.     my $aug3 = $_[5] ? $_[5] : 0;
  9.     my $aug4 = $_[6] ? $_[6] : 0;
  10.     my $aug5 = $_[7] ? $_[7] : 0;
  11.    
  12.     my $stackable = $client->GetItemStat($itemid, "stackable");
  13.     my $stack_size = $client->GetItemStat($itemid, "stacksize");
  14.     my $max_charges = $client->GetItemStat($itemid, "maxcharges");
  15.     my $item_charges = 0;
  16.    
  17.     my @slots = (quest::getinventoryslotid("general.begin") .. quest::getinventoryslotid("general.end"),
  18.                 quest::getinventoryslotid("generalbags.begin") .. quest::getinventoryslotid("generalbags.end"));
  19.    
  20.     #If stackable.. lets find spots where it will fit current stacks already in place...
  21.     if($stackable) {
  22.         foreach $slot (@slots) {
  23.             if ($client->GetItemIDAt($slot) == $itemid) {
  24.                 #stackable items must remove charges...
  25.                     $item_charges = $client->GetItemAt($slot)->GetCharges();
  26.                     if ($item_charges < $stack_size) {
  27.                         my $stack_diff = $stack_size - $item_charges; #How many can fit in this current stack...
  28.                         my $added_amount = 0;
  29.                        
  30.                         if ($amount > $stack_diff) {
  31.                             $added_amount = $stack_diff;
  32.                         } else {
  33.                             $added_amount = $amount;
  34.                         }
  35.                         #SummonItem(THIS, item_id, charges=0, attune=0, aug1=0, aug2=0, aug3=0, aug4=0, aug5=0, slot_id=30)
  36.                         $client->SummonItem($itemid, $item_charges + $added_amount, 0, 0, 0, 0, 0, 0, $slot);
  37.                         $amount -= $added_amount;
  38.                     }
  39.             }
  40.             if($amount <= 0) { #We finished brah
  41.                 return;
  42.             }
  43.         }
  44.     }
  45.    
  46.     #Now we place the rest of the items into open slots..
  47.     my $bag_begin = quest::getinventoryslotid("general1bag.begin"); #very first bag slot
  48.     my $first_bag = quest::getinventoryslotid("general.begin");
  49.     my %first_slot = (
  50.         $first_bag => $bag_begin,
  51.         $first_bag+1 => $bag_begin+10,
  52.         $first_bag+2 => $bag_begin+20,
  53.         $first_bag+3 => $bag_begin+30,
  54.         $first_bag+4 => $bag_begin+40,
  55.         $first_bag+5 => $bag_begin+50,
  56.         $first_bag+6 => $bag_begin+60,
  57.         $first_bag+7 => $bag_begin+70,
  58.         $first_bag+8 => $bag_begin+80,
  59.         $first_bag+9 => $bag_begin+90
  60.         );
  61.    
  62.     foreach $slot (@slots) {
  63.         my $check_bag = 0;
  64.         #Slots 251 -330 require a bag in the correct slot..
  65.         #quest::getinventoryslotid("general.begin") .. quest::getinventoryslotid("general.end"),
  66.                 #quest::getinventoryslotid("generalbags.begin") .. quest::getinventoryslotid("generalbags.end")
  67.         if ($slot >= quest::getinventoryslotid("general1bag.begin") && $slot <= quest::getinventoryslotid("general1bag.end")) {
  68.             $check_bag = quest::getinventoryslotid("general.begin");
  69.         } elsif ($slot >= quest::getinventoryslotid("general2bag.begin") && $slot <= quest::getinventoryslotid("general2bag.end")) {
  70.             $check_bag = quest::getinventoryslotid("general.begin")+1;
  71.         } elsif ($slot >= quest::getinventoryslotid("general3bag.begin") && $slot <= quest::getinventoryslotid("general3bag.end")) {
  72.             $check_bag = quest::getinventoryslotid("general.begin")+2;
  73.         } elsif ($slot >= quest::getinventoryslotid("general4bag.begin") && $slot <= quest::getinventoryslotid("general4bag.end")) {
  74.             $check_bag = quest::getinventoryslotid("general.begin")+3;
  75.         } elsif ($slot >= quest::getinventoryslotid("general5bag.begin") && $slot <= quest::getinventoryslotid("general5bag.end")) {
  76.             $check_bag = quest::getinventoryslotid("general.begin")+4;
  77.         } elsif ($slot >= quest::getinventoryslotid("general6bag.begin") && $slot <= quest::getinventoryslotid("general6bag.end")) {
  78.             $check_bag = quest::getinventoryslotid("general.begin")+5;
  79.         } elsif ($slot >= quest::getinventoryslotid("general7bag.begin") && $slot <= quest::getinventoryslotid("general7bag.end")) {
  80.             $check_bag = quest::getinventoryslotid("general.begin")+6;
  81.         } elsif ($slot >= quest::getinventoryslotid("general8bag.begin") && $slot <= quest::getinventoryslotid("general8bag.end")) {
  82.             $check_bag = quest::getinventoryslotid("general.begin")+7;
  83.         } elsif ($slot >= quest::getinventoryslotid("general9bag.begin") && $slot <= quest::getinventoryslotid("general9bag.end")) {
  84.             $check_bag = quest::getinventoryslotid("general.begin")+8;
  85.         } elsif ($slot >= quest::getinventoryslotid("general10bag.begin") && $slot <= quest::getinventoryslotid("general10bag.end")) {
  86.             $check_bag = quest::getinventoryslotid("general.begin")+9;
  87.         }
  88.        
  89.         if ($check_bag > 0) {
  90.             #$client->Message(335, "Test - $check_bag - ". $client->GetItemIDAt($check_bag));
  91.             if ($client->GetItemIDAt($check_bag) == -1) {
  92.                 #$client->Message(335, "No Bag here skipping... $check_bag");
  93.                 next;
  94.             } else {
  95.                 #There is an item here.. check if its a bag..
  96.                 my $bag_slots = $client->GetItemStat($client->GetItemIDAt($check_bag), "bagslots");
  97.                 if ($bag_slots > 0) {
  98.                     #This is a bag.. zomg.. see if the slot is valid..
  99.                     #my $max_slot = (($check_bag * 10) + 30) + $bag_slots;
  100.                     my $max_slot = $first_slot{$check_bag}+$bag_slots;
  101.                    
  102.                     #$client->Message(335, "$slot > $max_slot");
  103.                    
  104.                     if ($slot >= $max_slot) {
  105.                         #$client->Message(335, "$slot not valid!");
  106.                         next; #This slot is not valid with this bag size...
  107.                     } else {
  108.                         #We are in a valid slot... check bag size...
  109.                         my $bag_size = $client->GetItemStat($client->GetItemIDAt($check_bag), "bagsize");
  110.                         my $item_size = $client->GetItemStat($itemid, "size");
  111.                         if ($item_size > $bag_size) {
  112.                             next; #This slit is not valid.. as this bag is too small
  113.                         }
  114.                     }
  115.                 } else {
  116.                     #$client->Message(335, "$slot---> not a bag");
  117.                     next; #This item is not a bag.. do not check this slot..
  118.                 }
  119.             }
  120.         }
  121.        
  122.         if ($client->GetItemIDAt($slot) == -1) {
  123.             if ($stackable) {
  124.                 if ($stack_size > $amount) {
  125.                     $client->SummonItem($itemid, $amount, 0, 0, 0, 0, 0, 0, $slot);
  126.                     $amount = 0;
  127.                 } elsif ($amount >= $stack_size) {
  128.                     #$client->Message(335, "$slot is valid!");
  129.                     $client->SummonItem($itemid, $stack_size, 0, 0, 0, 0, 0, 0, $slot);
  130.                     $amount -= $stack_size;
  131.                 }
  132.             } else {
  133.                 #$client->Message(335, "$slot is valid!");
  134.                 #$client->Message(335, "Summoning item into... $slot");
  135.                 #SummonItem(THIS, item_id, charges=0, attune=0, aug1=0, aug2=0, aug3=0, aug4=0, aug5=0, slot_id=30)
  136.                 if ($max_charges > 1) {
  137.                     $client->SummonItem($itemid, $max_charges, 0, $aug1, $aug2, $aug3, $aug4, $aug5, $slot);  #Charged items
  138.                 } else {
  139.                     $client->SummonItem($itemid, 1, 0, $aug1, $aug2, $aug3, $aug4, $aug5, $slot);  #normal items
  140.                 }
  141.                 $amount--;
  142.             }
  143.         }
  144.         if($amount <= 0) { #We finished brah
  145.                 return;
  146.         }
  147.     }
  148.    
  149.     #NO MORE VALID SLOTS... time to summon the rest to cursor...
  150.     if ($amount > 0) {
  151.         while ($amount > 0) {
  152.             if ($stackable) {
  153.                 if ($stack_size > $amount) {
  154.                     $client->SummonItem($itemid, $amount);
  155.                     $amount = 0;
  156.                 } elsif ($amount >= $stack_size) {
  157.                     $client->SummonItem($itemid, $stack_size);
  158.                     $amount -= $stack_size;
  159.                 }
  160.             } else {
  161.                 if ($max_charges > 1) {
  162.                     $client->SummonItem($itemid, $max_charges, 0, $aug1, $aug2, $aug3, $aug4, $aug5);  #Charged items
  163.                 } else {
  164.                     $client->SummonItem($itemid, 1, 0, $aug1, $aug2, $aug3, $aug4, $aug5);  #normal items
  165.                 }
  166.                 $amount--;
  167.             }
  168.         }
  169.     }
  170.     return;
  171. }
Add Comment
Please, Sign In to add comment