Paldail

Collect Quest

Oct 12th, 2021
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.36 KB | None | 0 0
  1. #plugin::collect_quest($client, itemid => count, itemid => count)
  2. #Can do money amount as well.. example...
  3. # ... plugin::collect_quest($client, 1001 => 5, 1002 => 2, "platinum" => 1, "gold" => 5, "silver" => 5, "copper" => 5)
  4. # ...
  5. #THE TAKEMONEYFROM PP ONLY WORKS UP TO 2,147,000~ platinum.. so be aware!
  6.  
  7. sub collect_quest {
  8.     my $client = shift;
  9.     my %required = @_;
  10.     my $count_total = 0;
  11.     my $stackable = 0;
  12.     my $money_total = 0;
  13.    
  14.     my @slots = (quest::getinventoryslotid("general.begin") .. quest::getinventoryslotid("general.end"),
  15.                 quest::getinventoryslotid("generalbags.begin") .. quest::getinventoryslotid("generalbags.end"));
  16.    
  17.     foreach my $req (keys %required) {
  18.         $count_total = 0;
  19.        
  20.         if ($req =~/platinum/i) {
  21.             $money_total += $required{$req} * 1000;
  22.             next;
  23.         } elsif ($req=~/gold/i) {
  24.             $money_total += $required{$req} * 100;
  25.             next;
  26.         } elsif ($req =~/silver/i) {
  27.             $money_total += $required{$req} * 10;
  28.             next;
  29.         }  elsif ($req =~/copper/i) {
  30.             $money_total += $required{$req};
  31.             next;
  32.         }
  33.        
  34.         foreach $slot (@slots) {
  35.             if ($client->GetItemIDAt($slot) == $req) {
  36.                 $stackable = $client->GetItemStat($req, "stackable");
  37.                 if($stackable) {
  38.                     $count_total+= $client->GetItemAt($slot)->GetCharges();
  39.                 } else {
  40.                     $count_total++;
  41.                 }
  42.                
  43.                 #We have enough of this item.. stop checking..
  44.                 if($count_total >= $required{$req}) {
  45.                     last;
  46.                 }
  47.             }
  48.         }
  49.         if ($count_total < $required{$req} || $count_total == 0) {
  50.             #We failed this check.. return 0
  51.             plugin::collect_quest_failed($client, %required);
  52.             return 0;
  53.         }
  54.     }
  55.    
  56.     if ($money_total > 0) {
  57.         if ($client->TakeMoneyFromPP($money_total, 1)) {
  58.             plugin::collect_quest_remove($client, %required);
  59.             return 1;
  60.         } else {
  61.             plugin::Whisper("You do not have enough money for this hand in!");
  62.             return 0;
  63.         }
  64.     } else {
  65.         plugin::collect_quest_remove($client, %required);
  66.         return 1;
  67.     }
  68. }
  69.  
  70. sub collect_quest_remove {
  71.     my $client = shift;
  72.     my %required = @_;
  73.     my $count_total = 0;
  74.     my $stackable = 0;
  75.     my $item_charges = 0;
  76.    
  77.     my @slots = (quest::getinventoryslotid("general.begin") .. quest::getinventoryslotid("general.end"),
  78.                 quest::getinventoryslotid("generalbags.begin") .. quest::getinventoryslotid("generalbags.end"));
  79.    
  80.     foreach my $req (keys %required) {
  81.         $count_total = 0;
  82.         if ($req =~/platinum|gold|silver|copper/i) {
  83.             next;
  84.         }
  85.        
  86.         foreach $slot (@slots) {
  87.             if ($client->GetItemIDAt($slot) == $req) {
  88.                 $stackable = $client->GetItemStat($req, "stackable");
  89.                
  90.                 if($stackable) {
  91.                     $item_charges = $client->GetItemAt($slot)->GetCharges();
  92.                     if ($item_charges >= $required{$req}) {
  93.                         $client->DeleteItemInInventory($slot, $required{$req}, 1);
  94.                         $required{$req} = 0;
  95.                     }
  96.                     elsif($item_charges < $required{$req} && $item_charges > 0) {
  97.                         $client->DeleteItemInInventory($slot, $item_charges, 1);
  98.                         $required{$req}-= $item_charges;
  99.                     }
  100.                 } else {
  101.                 #non-stackable items must be 0 charges to remove the entire item
  102.                     $item_charges = 1;
  103.                     $client->DeleteItemInInventory($slot, 0, 1);
  104.                     $required{$req}-= $item_charges;
  105.                 }
  106.                
  107.                 #We removed enough of the item.. jump to next item!
  108.                 if ($required{$req} <= 0) {
  109.                     last;
  110.                 }
  111.             }
  112.         }
  113.     }
  114. }
  115.  
  116. #Called when they are missing required items...
  117. sub collect_quest_failed {
  118.     my $client = shift;
  119.     my %required = @_;
  120.     my $count_total = 0;
  121.     my $stackable = 0;
  122.    
  123.     my @slots = (quest::getinventoryslotid("general.begin") .. quest::getinventoryslotid("general.end"),
  124.                 quest::getinventoryslotid("generalbags.begin") .. quest::getinventoryslotid("generalbags.end"));
  125.    
  126.     $client->Message(335, "Missing required items!");
  127.     foreach my $req (keys %required) {
  128.         $count_total = 0;
  129.        
  130.         if ($req =~/platinum|gold|silver|copper/i) {
  131.             next;
  132.         }
  133.        
  134.         foreach $slot (@slots) {
  135.             if ($client->GetItemIDAt($slot) == $req) {
  136.                 $stackable = $client->GetItemStat($req, "stackable");
  137.                 if($stackable) {
  138.                     $count_total+= $client->GetItemAt($slot)->GetCharges();
  139.                 } else {
  140.                     $count_total++;
  141.                 }
  142.                
  143.                 #We have enough of this item.. stop checking..
  144.                 if($count_total >= $required{$req}) {
  145.                     last;
  146.                 }
  147.             }
  148.         }
  149.        
  150.         if ($count_total < $required{$req} || $count_total == 0) {
  151.             $client->Message(335,"" . $required{$req} . "x " . quest::varlink($req) . " you have  " . $count_total);
  152.         }
  153.     }
  154. }
Add Comment
Please, Sign In to add comment