Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub summon_into_inventory {
- my $client = $_[0];
- my $itemid = $_[1];
- my $amount = $_[2];
- my $aug1 = $_[3] ? $_[3] : 0;
- my $aug2 = $_[4] ? $_[4] : 0;
- my $aug3 = $_[5] ? $_[5] : 0;
- my $aug4 = $_[6] ? $_[6] : 0;
- my $aug5 = $_[7] ? $_[7] : 0;
- my $stackable = $client->GetItemStat($itemid, "stackable");
- my $stack_size = $client->GetItemStat($itemid, "stacksize");
- my $max_charges = $client->GetItemStat($itemid, "maxcharges");
- my $item_charges = 0;
- my @slots = (quest::getinventoryslotid("general.begin") .. quest::getinventoryslotid("general.end"),
- quest::getinventoryslotid("generalbags.begin") .. quest::getinventoryslotid("generalbags.end"));
- #If stackable.. lets find spots where it will fit current stacks already in place...
- if($stackable) {
- foreach $slot (@slots) {
- if ($client->GetItemIDAt($slot) == $itemid) {
- #stackable items must remove charges...
- $item_charges = $client->GetItemAt($slot)->GetCharges();
- if ($item_charges < $stack_size) {
- my $stack_diff = $stack_size - $item_charges; #How many can fit in this current stack...
- my $added_amount = 0;
- if ($amount > $stack_diff) {
- $added_amount = $stack_diff;
- } else {
- $added_amount = $amount;
- }
- #SummonItem(THIS, item_id, charges=0, attune=0, aug1=0, aug2=0, aug3=0, aug4=0, aug5=0, slot_id=30)
- $client->SummonItem($itemid, $item_charges + $added_amount, 0, 0, 0, 0, 0, 0, $slot);
- $amount -= $added_amount;
- }
- }
- if($amount <= 0) { #We finished brah
- return;
- }
- }
- }
- #Now we place the rest of the items into open slots..
- my $bag_begin = quest::getinventoryslotid("general1bag.begin"); #very first bag slot
- my $first_bag = quest::getinventoryslotid("general.begin");
- my %first_slot = (
- $first_bag => $bag_begin,
- $first_bag+1 => $bag_begin+10,
- $first_bag+2 => $bag_begin+20,
- $first_bag+3 => $bag_begin+30,
- $first_bag+4 => $bag_begin+40,
- $first_bag+5 => $bag_begin+50,
- $first_bag+6 => $bag_begin+60,
- $first_bag+7 => $bag_begin+70,
- $first_bag+8 => $bag_begin+80,
- $first_bag+9 => $bag_begin+90
- );
- foreach $slot (@slots) {
- my $check_bag = 0;
- #Slots 251 -330 require a bag in the correct slot..
- #quest::getinventoryslotid("general.begin") .. quest::getinventoryslotid("general.end"),
- #quest::getinventoryslotid("generalbags.begin") .. quest::getinventoryslotid("generalbags.end")
- if ($slot >= quest::getinventoryslotid("general1bag.begin") && $slot <= quest::getinventoryslotid("general1bag.end")) {
- $check_bag = quest::getinventoryslotid("general.begin");
- } elsif ($slot >= quest::getinventoryslotid("general2bag.begin") && $slot <= quest::getinventoryslotid("general2bag.end")) {
- $check_bag = quest::getinventoryslotid("general.begin")+1;
- } elsif ($slot >= quest::getinventoryslotid("general3bag.begin") && $slot <= quest::getinventoryslotid("general3bag.end")) {
- $check_bag = quest::getinventoryslotid("general.begin")+2;
- } elsif ($slot >= quest::getinventoryslotid("general4bag.begin") && $slot <= quest::getinventoryslotid("general4bag.end")) {
- $check_bag = quest::getinventoryslotid("general.begin")+3;
- } elsif ($slot >= quest::getinventoryslotid("general5bag.begin") && $slot <= quest::getinventoryslotid("general5bag.end")) {
- $check_bag = quest::getinventoryslotid("general.begin")+4;
- } elsif ($slot >= quest::getinventoryslotid("general6bag.begin") && $slot <= quest::getinventoryslotid("general6bag.end")) {
- $check_bag = quest::getinventoryslotid("general.begin")+5;
- } elsif ($slot >= quest::getinventoryslotid("general7bag.begin") && $slot <= quest::getinventoryslotid("general7bag.end")) {
- $check_bag = quest::getinventoryslotid("general.begin")+6;
- } elsif ($slot >= quest::getinventoryslotid("general8bag.begin") && $slot <= quest::getinventoryslotid("general8bag.end")) {
- $check_bag = quest::getinventoryslotid("general.begin")+7;
- } elsif ($slot >= quest::getinventoryslotid("general9bag.begin") && $slot <= quest::getinventoryslotid("general9bag.end")) {
- $check_bag = quest::getinventoryslotid("general.begin")+8;
- } elsif ($slot >= quest::getinventoryslotid("general10bag.begin") && $slot <= quest::getinventoryslotid("general10bag.end")) {
- $check_bag = quest::getinventoryslotid("general.begin")+9;
- }
- if ($check_bag > 0) {
- #$client->Message(335, "Test - $check_bag - ". $client->GetItemIDAt($check_bag));
- if ($client->GetItemIDAt($check_bag) == -1) {
- #$client->Message(335, "No Bag here skipping... $check_bag");
- next;
- } else {
- #There is an item here.. check if its a bag..
- my $bag_slots = $client->GetItemStat($client->GetItemIDAt($check_bag), "bagslots");
- if ($bag_slots > 0) {
- #This is a bag.. zomg.. see if the slot is valid..
- #my $max_slot = (($check_bag * 10) + 30) + $bag_slots;
- my $max_slot = $first_slot{$check_bag}+$bag_slots;
- #$client->Message(335, "$slot > $max_slot");
- if ($slot >= $max_slot) {
- #$client->Message(335, "$slot not valid!");
- next; #This slot is not valid with this bag size...
- } else {
- #We are in a valid slot... check bag size...
- my $bag_size = $client->GetItemStat($client->GetItemIDAt($check_bag), "bagsize");
- my $item_size = $client->GetItemStat($itemid, "size");
- if ($item_size > $bag_size) {
- next; #This slit is not valid.. as this bag is too small
- }
- }
- } else {
- #$client->Message(335, "$slot---> not a bag");
- next; #This item is not a bag.. do not check this slot..
- }
- }
- }
- if ($client->GetItemIDAt($slot) == -1) {
- if ($stackable) {
- if ($stack_size > $amount) {
- $client->SummonItem($itemid, $amount, 0, 0, 0, 0, 0, 0, $slot);
- $amount = 0;
- } elsif ($amount >= $stack_size) {
- #$client->Message(335, "$slot is valid!");
- $client->SummonItem($itemid, $stack_size, 0, 0, 0, 0, 0, 0, $slot);
- $amount -= $stack_size;
- }
- } else {
- #$client->Message(335, "$slot is valid!");
- #$client->Message(335, "Summoning item into... $slot");
- #SummonItem(THIS, item_id, charges=0, attune=0, aug1=0, aug2=0, aug3=0, aug4=0, aug5=0, slot_id=30)
- if ($max_charges > 1) {
- $client->SummonItem($itemid, $max_charges, 0, $aug1, $aug2, $aug3, $aug4, $aug5, $slot); #Charged items
- } else {
- $client->SummonItem($itemid, 1, 0, $aug1, $aug2, $aug3, $aug4, $aug5, $slot); #normal items
- }
- $amount--;
- }
- }
- if($amount <= 0) { #We finished brah
- return;
- }
- }
- #NO MORE VALID SLOTS... time to summon the rest to cursor...
- if ($amount > 0) {
- while ($amount > 0) {
- if ($stackable) {
- if ($stack_size > $amount) {
- $client->SummonItem($itemid, $amount);
- $amount = 0;
- } elsif ($amount >= $stack_size) {
- $client->SummonItem($itemid, $stack_size);
- $amount -= $stack_size;
- }
- } else {
- if ($max_charges > 1) {
- $client->SummonItem($itemid, $max_charges, 0, $aug1, $aug2, $aug3, $aug4, $aug5); #Charged items
- } else {
- $client->SummonItem($itemid, 1, 0, $aug1, $aug2, $aug3, $aug4, $aug5); #normal items
- }
- $amount--;
- }
- }
- }
- return;
- }
Add Comment
Please, Sign In to add comment