Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #plugin::collect_quest($client, itemid => count, itemid => count)
- #Can do money amount as well.. example...
- # ... plugin::collect_quest($client, 1001 => 5, 1002 => 2, "platinum" => 1, "gold" => 5, "silver" => 5, "copper" => 5)
- # ...
- #THE TAKEMONEYFROM PP ONLY WORKS UP TO 2,147,000~ platinum.. so be aware!
- sub collect_quest {
- my $client = shift;
- my %required = @_;
- my $count_total = 0;
- my $stackable = 0;
- my $money_total = 0;
- my @slots = (quest::getinventoryslotid("general.begin") .. quest::getinventoryslotid("general.end"),
- quest::getinventoryslotid("generalbags.begin") .. quest::getinventoryslotid("generalbags.end"));
- foreach my $req (keys %required) {
- $count_total = 0;
- if ($req =~/platinum/i) {
- $money_total += $required{$req} * 1000;
- next;
- } elsif ($req=~/gold/i) {
- $money_total += $required{$req} * 100;
- next;
- } elsif ($req =~/silver/i) {
- $money_total += $required{$req} * 10;
- next;
- } elsif ($req =~/copper/i) {
- $money_total += $required{$req};
- next;
- }
- foreach $slot (@slots) {
- if ($client->GetItemIDAt($slot) == $req) {
- $stackable = $client->GetItemStat($req, "stackable");
- if($stackable) {
- $count_total+= $client->GetItemAt($slot)->GetCharges();
- } else {
- $count_total++;
- }
- #We have enough of this item.. stop checking..
- if($count_total >= $required{$req}) {
- last;
- }
- }
- }
- if ($count_total < $required{$req} || $count_total == 0) {
- #We failed this check.. return 0
- plugin::collect_quest_failed($client, %required);
- return 0;
- }
- }
- if ($money_total > 0) {
- if ($client->TakeMoneyFromPP($money_total, 1)) {
- plugin::collect_quest_remove($client, %required);
- return 1;
- } else {
- plugin::Whisper("You do not have enough money for this hand in!");
- return 0;
- }
- } else {
- plugin::collect_quest_remove($client, %required);
- return 1;
- }
- }
- sub collect_quest_remove {
- my $client = shift;
- my %required = @_;
- my $count_total = 0;
- my $stackable = 0;
- my $item_charges = 0;
- my @slots = (quest::getinventoryslotid("general.begin") .. quest::getinventoryslotid("general.end"),
- quest::getinventoryslotid("generalbags.begin") .. quest::getinventoryslotid("generalbags.end"));
- foreach my $req (keys %required) {
- $count_total = 0;
- if ($req =~/platinum|gold|silver|copper/i) {
- next;
- }
- foreach $slot (@slots) {
- if ($client->GetItemIDAt($slot) == $req) {
- $stackable = $client->GetItemStat($req, "stackable");
- if($stackable) {
- $item_charges = $client->GetItemAt($slot)->GetCharges();
- if ($item_charges >= $required{$req}) {
- $client->DeleteItemInInventory($slot, $required{$req}, 1);
- $required{$req} = 0;
- }
- elsif($item_charges < $required{$req} && $item_charges > 0) {
- $client->DeleteItemInInventory($slot, $item_charges, 1);
- $required{$req}-= $item_charges;
- }
- } else {
- #non-stackable items must be 0 charges to remove the entire item
- $item_charges = 1;
- $client->DeleteItemInInventory($slot, 0, 1);
- $required{$req}-= $item_charges;
- }
- #We removed enough of the item.. jump to next item!
- if ($required{$req} <= 0) {
- last;
- }
- }
- }
- }
- }
- #Called when they are missing required items...
- sub collect_quest_failed {
- my $client = shift;
- my %required = @_;
- my $count_total = 0;
- my $stackable = 0;
- my @slots = (quest::getinventoryslotid("general.begin") .. quest::getinventoryslotid("general.end"),
- quest::getinventoryslotid("generalbags.begin") .. quest::getinventoryslotid("generalbags.end"));
- $client->Message(335, "Missing required items!");
- foreach my $req (keys %required) {
- $count_total = 0;
- if ($req =~/platinum|gold|silver|copper/i) {
- next;
- }
- foreach $slot (@slots) {
- if ($client->GetItemIDAt($slot) == $req) {
- $stackable = $client->GetItemStat($req, "stackable");
- if($stackable) {
- $count_total+= $client->GetItemAt($slot)->GetCharges();
- } else {
- $count_total++;
- }
- #We have enough of this item.. stop checking..
- if($count_total >= $required{$req}) {
- last;
- }
- }
- }
- if ($count_total < $required{$req} || $count_total == 0) {
- $client->Message(335,"" . $required{$req} . "x " . quest::varlink($req) . " you have " . $count_total);
- }
- }
- }
Add Comment
Please, Sign In to add comment