MaXwEllDeN

[Smith] LIB

Jul 25th, 2012
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.99 KB | None | 0 0
  1. --[[
  2. ################################################
  3. ##      Smith System                          ##
  4. ##      Author: Maxwell Denisson(MaXwEllDeN)  ##
  5. ##      Version: 1.0                          ##
  6. ################################################
  7. ]]
  8.  
  9. _SMITHY_ = {
  10.     exp_b = 40,
  11.     receitas = {
  12.         --dif = Dificuldade
  13.         [1] = {dif = 5, -- Staff
  14.                re = {{5892, 2},
  15.                     },
  16.                 ma = {2401, 1}
  17.         },
  18.         [2] = {dif = 10, -- Mercenary Sword
  19.                re = {{2401, 1},
  20.                      {9971, 5},
  21.                      {5887, 3},
  22.                      {5892, 2},
  23.                     },
  24.                 ma = {7386, 1}
  25.         },
  26.         [3] = {dif = 3, -- Huge chuck of crude iron
  27.                re = {{5880, 20},
  28.                     },
  29.                 ma = {5892, 1}
  30.         },
  31.         [4] = {dif = 20, -- Piece of Royal Steel
  32.                re = {{5880, 10},
  33.                      {2475, 1},
  34.                     },
  35.                 ma = {5887, 3}
  36.         },
  37.     }
  38.  
  39. }
  40.  
  41. _SMITHY_.getRevenue = function (pos)
  42.     local recs = {}
  43.     local ipos = {}
  44.     local posi = {}
  45.  
  46.     local block = {1642, 1643, 1644, 1645, 1617, 1618, 1620, 1621, 2555}
  47.  
  48.     local IDEx = 0
  49.  
  50.     for i, v in pairs(_SMITHY_.receitas) do
  51.         recs[i] = {}
  52.         for _, a in pairs(v.re) do
  53.             for b = 1, a[2] do
  54.                 table.insert(recs[i], a[1])
  55.             end
  56.         end
  57.     end
  58.  
  59.     local Zk = {}
  60.     for _, v in pairs(getAllItemsInPos(pos, block)) do
  61.         if not isInArray(Zk, v.uid) then
  62.             table.insert(ipos, v)
  63.             table.insert(Zk, v.uid)
  64.         end
  65.     end
  66.  
  67.     for _, v in pairs(ipos) do
  68.         local t = (v.type > 0) and v.type or 1
  69.         for te = 1, t do
  70.             table.insert(posi, v.itemid)
  71.         end
  72.     end
  73.  
  74.     for _, v in pairs(recs) do
  75.         local AE = true
  76.         for x, i in pairs(posi) do
  77.             if (AE) then
  78.                 if (not isInArray(v, i)) or (#v ~= #posi) then
  79.                     AE = false
  80.                 else
  81.                     IDEx = _
  82.                 end
  83.             end
  84.         end
  85.     end
  86.  
  87.     if (#recs < 1) then
  88.         return 0, ipos
  89.     else
  90.         return IDEx, ipos
  91.     end
  92. end
  93.  
  94. _SMITHY_.getExp = function (uid)
  95.     if (getPlayerStorageValue(uid, 58913) < 1) then
  96.         setPlayerStorageValue(uid, 58913, 0)
  97.     end
  98.    return getPlayerStorageValue(uid, 58913)
  99. end
  100.  
  101. _SMITHY_.getLevel = function (uid)
  102.     if (getPlayerStorageValue(uid, 58912) < 1) then
  103.         setPlayerStorageValue(uid, 58912, 1)
  104.     end
  105.    return getPlayerStorageValue(uid, 58912)
  106. end
  107.  
  108. _SMITHY_.addLevel = function (uid, ammount)
  109.     local level = _SMITHY_.getLevel(uid)
  110.     return setPlayerStorageValue(uid, 58912, level + ammount)
  111. end
  112.  
  113. _SMITHY_.getExpToNextLevel = function (uid)
  114.     return _SMITHY_.getExpLevel(_SMITHY_.getLevel(uid) + 1)
  115. end
  116.  
  117. _SMITHY_.getExpLevel = function (level)
  118.     return level * (_SMITHY_.exp_b) + (level - 1* (_SMITHY_.exp_b))
  119. end
  120.  
  121. _SMITHY_.setExp = function (uid, ammount)
  122.     return setPlayerStorageValue(uid, 58913, ammount)
  123. end
  124.  
  125. _SMITHY_.addExp = function (uid, ammount)
  126.     local xp = _SMITHY_.getExp(uid)
  127.     return _SMITHY_.setExp(uid, xp + ammount)
  128. end
  129.  
  130. function getAllItemsInPos(pos, block)
  131.    local results = {}
  132.  
  133.    for _ = 1, 255 do
  134.        local findPos = {x = pos.x, y = pos.y, z = pos.z, stackpos = _}
  135.        local item = getThingFromPos(findPos)
  136.        if (not isInArray(block, item.itemid)) and (item.uid > 1) then
  137.           table.insert(results, item)
  138.        end
  139.    end
  140.  
  141.    return results
  142. end
Advertisement
Add Comment
Please, Sign In to add comment