Advertisement
NonSequitur

Untitled

Feb 4th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. local function getLocals(level)
  2.     local loc = 0
  3.     return function()
  4.         loc = loc + 1
  5.         local i, v = debug.getlocal(level + 1, loc)
  6.         if i then
  7.             return i, v
  8.         end
  9.     end
  10. end
  11.  
  12. local function getPrice(cid, shopItem)
  13.     if Player(cid):getName() ~= 'Rotanev'  then
  14.         return shopItem.buy, shopItem.sell
  15.     end
  16.     return shopItem.buy / 2, shopItem.sell * 2
  17. end
  18.  
  19. for k, v in pairs(npcHandler.modules) do
  20.     local getShopItem = v.getShopItem
  21.     if getShopItem then
  22.         v.getShopItem = function(self, itemId, itemSubType)
  23.             local shopItem = getShopItem(self, itemId, itemSubType)
  24.             if not shopItem then return nil end
  25.             for i, v in getLocals(2) do
  26.                 if i == 'cid' then
  27.                     local buy, sell = getPrice(v, shopItem)
  28.                     return {id = shopItem.id, buy = buy, sell = sell, subType = shopItem.subType, name = shopItem.name}
  29.                 end
  30.             end
  31.             return shopItem
  32.         end
  33.         break
  34.     end
  35. end
  36.  
  37. local shopItems = npcHandler.shopItems
  38. if shopItems then
  39.     npcHandler.shopItems = newproxy(true)
  40.     local mt = getmetatable(npcHandler.shopItems)
  41.     mt.__index = function(self, index)
  42.         for i, v in getLocals(2) do
  43.             if i == 'cid' then
  44.                 local shopItem = rawget(shopItems, index)
  45.                 if not shopItem then return nil end
  46.                 local buy, sell = getPrice(v, shopItem)
  47.                 return {id = shopItem.id, buy = buy, sell = sell, subType = shopItem.subType, name = shopItem.name}
  48.             end
  49.         end
  50.  
  51.         return rawget(shopItems, index)
  52.     end
  53.  
  54.     mt.__len = function(self)
  55.         return #shopItems
  56.     end
  57.  
  58.     local tablenext = next
  59.     next = function(t, ...)
  60.         if type(t) == 'userdata' then
  61.             return #t > 0
  62.         end
  63.         return tablenext(t, ...)
  64.     end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement