Guest User

Untitled

a guest
Jan 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.85 KB | None | 0 0
  1. local STORAGE_SKILL_LEVEL = 20002
  2. local STORAGE_SKILL_TRY = 20003  
  3.  
  4.     local config = {
  5.      levels = {
  6.          {level = {0,9}, quant = {1,2}, percent = 5},
  7.          {level = {10,19}, quant = {2,4}, percent = 10},
  8.          {level = {20,29}, quant = {3,6}, percent = 15},
  9.          {level = {30,39}, quant = {4,8}, percent = 20},
  10.          {level = {40,49}, quant = {5,10}, percent = 25},
  11.          {level = {50,59}, quant = {6,12}, percent = 30},
  12.          {level = {60,69}, quant = {7,14}, percent = 30},
  13.          {level = {70,79}, quant = {8,16}, percent = 35},
  14.          {level = {80,89}, quant = {9,18}, percent = 35},
  15.          {level = {90,99}, quant = {10,20}, percent = 40},
  16.          {level = {100}, quant = {11,22}, percent = 50}
  17.      },
  18.      rocks = {1356, 1285, 3607, 3616}, -- Id das rochas que podem ser quebradas
  19.      stones = {},  -- Modelo = {rock_id, rock_id}
  20.      default_stone = 2157, -- pedra padrão
  21.      rock_delay = 1, -- Tempo de volta da rocha (Em segundos)
  22.      bonus_chance = 3, -- Chance (em porcentagem) de se conseguir um bonus de exp
  23.      bonus_exp = 1 -- Bonus extra
  24.     }
  25.    
  26.    
  27. ------------------------------------
  28. -- END Configurations ---
  29. ------------------------------------
  30.  
  31. function getMiningLevel(cid)
  32.     return getPlayerStorageValue(cid, STORAGE_SKILL_LEVEL)
  33. end
  34.  
  35. function setPlayerMiningLevel(cid, n)
  36.     setPlayerStorageValue(cid, STORAGE_SKILL_LEVEL, n)
  37. end
  38.  
  39. function addMiningLevel(cid, n)
  40.     setPlayerMiningLevel(cid, getMiningLevel(cid) + (isNumber(n) and n or 1))
  41.     setMiningTry(cid, 0)
  42. end
  43.  
  44. function getMiningInfo(cid)
  45.     for i = 1, #config.levels do
  46.         min = config.levels[i].level[1]; max = config.levels[i].level[2]
  47.         if (getMiningLevel(cid) >= min and getMiningLevel(cid) <= max) then
  48.             return {quantity = {min = config.levels[i].quant[1], max = config.levels[i].quant[2]}, chance = config.levels[i].percent}
  49.         end
  50.     end
  51. end
  52.  
  53. function getStoneByRock(rockid)
  54.     for i = 1, #config.stones do
  55.         if (config.stones[2] == rockid) then
  56.             return config.stones[1]
  57.         end
  58.     end
  59.     return config.default_stone
  60. end
  61.  
  62. function getMiningTries(cid)
  63.     return getPlayerStorageValue(cid, STORAGE_SKILL_TRY)
  64. end
  65.  
  66. function setMiningTry(cid, n)
  67.     setPlayerStorageValue(cid, STORAGE_SKILL_TRY, n)
  68. end
  69.  
  70. function addMiningTry(cid, bonus)
  71.     setMiningTry(cid, getMiningTries(cid) + 1 + (bonus and config.bonus_exp or 0))
  72.    
  73.     if (getMiningTries(cid) >= getMiningExpTo(getMiningLevel(cid))) then -- Up
  74.         doPlayerSendTextMessage(cid, 22, "You advanced from level " .. getMiningLevel(cid) .. " to level ".. (getMiningLevel(cid) + 1) .." in mining.")
  75.        
  76.         if ((getMiningLevel(cid)+1) == getMiningMaxLevel()) then
  77.             doPlayerSendTextMessage(cid, 22, "Max level reached in mining.")
  78.         end
  79.        
  80.         addMiningLevel(cid)
  81.         doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))
  82.         setMiningTry(cid, 0)
  83.     end
  84. end
  85.  
  86. function getMiningExpTo(level)
  87.     return ((level*1.5)+((level+1)*7))
  88. end
  89.  
  90. function getMiningMaxLevel()
  91.     return config.levels[#config.levels].level[#config.levels[#config.levels].level]
  92. end
  93.  
  94. ---------------------------
  95.  
  96.  
  97. function onUse(cid, item, fromPosition, itemEx, toPosition)
  98.     rock = { id = itemEx.itemid, uid = itemEx.uid, position = toPosition }
  99.     player = { position = getCreaturePosition(cid) }
  100.  
  101. gems = {
  102. {gem = {2146, 2149, 2150, 2147, 2145, 5880, 2157, 9970, 2153, 2158, 2154, 2156, 2155} }
  103. }
  104.  
  105. quanti = { {quant = {math.random(1,3), math.random(1,3), math.random(1,3), math.random(1,3), math.random(1,2), math.random(1,2), math.random(1,2), math.random(1,2), 1, 1, 1, 1, 1} } }
  106.  
  107.  
  108.  
  109.     if (getMiningLevel(cid) < 0) then
  110.         setPlayerMiningLevel(cid, 0)
  111.     end
  112.    
  113.     if (isInArray(config.rocks, rock.id)) then
  114.         addMiningTry(cid)
  115.    
  116.         if (math.random(1,100) <= getMiningInfo(cid).chance) then
  117.             doPlayerAddItem(cid, gems[1].gem[math.random(1,2)], quanti[1].quant[math.random(1,2)])
  118.             doPlayerSendTextMessage(cid, 22, "You got " .. collected .. " gold" .. (collected > 1 and "s" or "") .. " nuggets.")
  119.     elseif (math.random(1,100) <= getMiningInfo(cid).chance) and (getMiningLevel(cid) >= 10) then
  120.                         doPlayerAddItem(cid, gems[1].gem[math.random(3,4)], quanti[1].quant[math.random(3,4)])
  121.             doPlayerSendTextMessage(cid, 22, "You got " .. collected .. " gold" .. (collected > 1 and "s" or "") .. " nuggets.")
  122.  
  123.             if (math.random(1,100) <= config.bonus_chance) then -- Bonus calc
  124.                 addMiningTry(cid, true)
  125.                 doSendAnimatedText(player.position, "Bonus!", COLOR_ORANGE)
  126.             end
  127.            
  128.             event_rockCut(rock)
  129.         else
  130.             if (math.random(1,100) <= (10-getMiningInfo(cid).chance/10)) then
  131.                 doPlayerSendTextMessage(cid, 22, "You got nothing.")
  132.                 event_rockCut(rock)
  133.             else
  134.     local som = {
  135.     {nome = "Toff!"},
  136.     {nome = "Teck!"},
  137.     {nome = "Pleck"}
  138.     }
  139.     local rands = math.random(1,3)
  140.                 doSendMagicEffect(rock.position, 3)
  141.                 doSendAnimatedText(rock.position, som[rands].nome, COLOR_GREY)
  142.             end
  143.         end
  144.     else
  145.         doPlayerSendCancel(cid, "This can't be cut.")
  146.     end
  147. end
  148.  
  149. function event_rockCut(rock)
  150.     addEvent(event_rockGrow, config.rock_delay * 1000, rock.position, rock.id)
  151.    
  152.     doTransformItem(rock.uid, 3610)
  153.     doSendMagicEffect(rock.position, 3)
  154.     doSendAnimatedText(rock.position, "Crack!", COLOR_GREY)
  155.     doItemSetAttribute(rock.uid, "name", "A trunk of " .. getItemNameById(rock.id))
  156. end
  157.  
  158. function event_rockGrow(rockPos, old_id)
  159.     local rock = getThingFromPos(rockPos).uid
  160.     doTransformItem(rock, old_id)
  161.     doItemSetAttribute(rock, "name", getItemNameById(old_id))
  162.     doSendMagicEffect(rockPos, 3)
  163. end
Add Comment
Please, Sign In to add comment