Advertisement
gabrielsoldani

eAScript F_CheckGetItem

Feb 20th, 2012
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function    script  F_CheckGetItem  {
  2.     getinventorylist;
  3.  
  4.     //New inventory entries.
  5.     set .@new_entries, 0;
  6.  
  7.     //Sum of all weights.
  8.     set .@sum_weight, 0;
  9.  
  10.     //Loop though all parameters.
  11.     for (set .@i, 0; getarg(.@i, 0) <= 0; set .@i, .@i + 2)
  12.     {
  13.         //Check if is stackable.
  14.         if (callfunc("F_IsStackable", getarg(.@i)))
  15.         {
  16.             //If true, find a match.
  17.             for (set .@j, 0; .@j < @inventorylist_count; set .@j, .@j + 1)
  18.             {
  19.                 //Check if id matches.
  20.                 if (@inventorylist_id[.@j] == getarg(.@i))
  21.                 {
  22.                     //If true, check for possible amount overflow.
  23.                     if (@inventorylist_amount[.@j] + getarg(.@i+1) > MAX_AMOUNT)
  24.                         return -1;
  25.                     //No need to check for more inventory entries.
  26.                     break;
  27.                 }
  28.             }
  29.             //Check if no match was found
  30.             if (.@j == @inventorylist_count)
  31.                 //If true, add a new inventory entry.
  32.                 set .@new_entries, .@new_entries + 1;
  33.         }
  34.         else
  35.         {
  36.             //If false, add item amount as new entries.
  37.             set .@new_entries, .@new_entries + getarg(.@i+1);
  38.         }
  39.         //Add weight.
  40.         set .@sum_weight, .@sum_weight + getiteminfo(getarg(.@i), 6) * getarg(.@i+1);
  41.     }
  42.  
  43.     return ((.@new_entries + @inventorylist_count) > MAX_INVENTORY) ? -2 : ((.@sum_weight + Weight) > MaxWeight) ? 0 : 1;
  44. }
  45.  
  46. function    script  F_IsStackable   {
  47.     switch (getiteminfo(getarg(0), 2)
  48.     {
  49.         case IT_WEAPON:
  50.         case IT_ARMOR:
  51.         case IT_PETEGG:
  52.         case IT_PETARMOR:
  53.             return 0;
  54.         default:
  55.             return 1;
  56.     }
  57. }
  58.  
  59. //const.txt
  60. MAX_INVENTORY   100
  61. MAX_AMOUNT  30000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement