Advertisement
NatedogServer

collect_quest

Jan 31st, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.97 KB | None | 0 0
  1. #TEST QUEST...
  2. sub EVENT_SAY {
  3.     if($text=~/#balls/i) {
  4.         if(plugin::collect_quest($client, 1081, 4)) {
  5.             $client->Message(335, "Removing 4 waters!");
  6.         } else {
  7.             $client->Message(335, "You dont have 4 waters!");
  8.         }
  9.     }
  10. }
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. #plugin::check_hascount($client, itemid, amountcheck)
  18. sub collect_quest {
  19.     my $client = shift;
  20.     my $itemid = shift;
  21.     my $count = shift;
  22.     my $count_total = 0;
  23.     my $stackable = 0;
  24.    
  25.     #Ignore cursor / cursor bags Slots 30 / 331-340
  26.     my @slots = (22..29, 251..330);
  27.     foreach $slot (@slots) {
  28.         if ($client->GetItemIDAt($slot) == $itemid) {
  29.             $stackable = $client->GetItemStat($itemid, "stackable");
  30.             if($stackable) {
  31.                 $count_total+= $client->GetItemAt($slot)->GetCharges();
  32.             } else {
  33.                 $count_total++;
  34.             }
  35.         }
  36.     }
  37.     if ($count_total >= $count) {
  38.         plugin::collect_quest_remove($client, $itemid, $count);
  39.         return 1;
  40.     } else {
  41.         return 0;
  42.     }
  43. }
  44.  
  45. #plugin::collect_quest($client, itemid, amountcheck)
  46. sub collect_quest_remove {
  47.     my $client = shift;
  48.     my $itemid = shift;
  49.     my $count = shift;
  50.     my $item_charges;
  51.     my $stackable = 0;
  52.    
  53.     #Ignore cursor / cursor bags Slots 30 / 331-340
  54.     my @slots = (22..29, 251..330);
  55.     foreach $slot (@slots) {
  56.         if ($client->GetItemIDAt($slot) == $itemid) {
  57.             $stackable = $client->GetItemStat($itemid, "stackable");
  58.            
  59.             #stackable items must remove charges...
  60.             if($stackable) {
  61.                 $item_charges = $client->GetItemAt($slot)->GetCharges();
  62.                 if ($item_charges >= $count) {
  63.                     $client->DeleteItemInInventory($slot, $count, 1);
  64.                     $count = 0;
  65.                 }
  66.                 elsif($item_charges < $count && $item_charges > 0) {
  67.                     $client->DeleteItemInInventory($slot, $item_charges, 1);
  68.                     $count-= $item_charges;
  69.                 }
  70.             } else {
  71.             #non-stackable items must be 0 charges to remove the entire item
  72.                 $item_charges = 1;
  73.                 $client->DeleteItemInInventory($slot, 0, 1);
  74.                 $count-= $item_charges;
  75.             }
  76.         }
  77.         if($count <= 0) {
  78.             return 1;
  79.         }
  80.     }
  81.     return 0;
  82. }
  83.  
  84.  
  85. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement