Advertisement
Hiranus

LimitsFromFile

Jun 17th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.84 KB | None | 0 0
  1. local LimitsFile= "Limits.json";
  2. local Limits = nil;
  3. local LimitsIndexed = nil;
  4.  
  5. function RefreshLimits()
  6.   if Limits == nil then
  7.     Limits= JsonSaveLoad.Load(LimitsFile);
  8.     for i=1,#Limits do
  9.       local item = Limits[i];
  10.       local id = item.Fingerprint.id;
  11.       if LimitsIndexed[id] == nil then
  12.         LimitsIndexed[id] = {};
  13.       end
  14.       LimitsIndexed[id][#LimitsIndexed[id] + 1] = item;
  15.     end
  16.   end
  17. end
  18.  
  19. function GetLimitForItem(fingerprint)
  20.   local limits = LimitsIndexed[fingerprint.id];
  21.   if limits then
  22.     for i=1,#limits do
  23.       local limit = limits[i];
  24.       local limitFingerprint = limit.Fingerprint;
  25.       if limitFingerprint.id == fingerprint.id and limitFingerprint.dmg == fingerprint.dmg and limitFingerprint.nbt_hash == fingerprint.nbt_hash then
  26.         return limit.Limit;
  27.       end
  28.     end
  29.   end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement