Advertisement
Guest User

Fishing ~ MaXwEllDeN

a guest
Apr 17th, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.34 KB | None | 0 0
  1. local config = {
  2.     fishes = {
  3.         leveis = {20, 40, 50, 60, 80, 100, 120},
  4.        
  5.         fish = {
  6.             [20] = 2670,
  7.             [40] = 2667,
  8.             [50] = 2668,
  9.             [60] = 7459,
  10.             [80] = 7458,
  11.             [100] = 2669,
  12.             [120] = 7963,
  13.         }
  14.    
  15.     },
  16.     waters = {4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825},
  17.     fishable = {4608, 4609, 4610, 4611, 4612, 4613, 7236},
  18.     spawning = {4614, 4615, 4616, 4617, 4618, 4619},
  19.     holes = {7236},
  20.  
  21.     corpses = {
  22.         -- [corpse] = {items}
  23.         [2025] = {
  24.             -- {itemid, countmax, chance}
  25.             -- TODO: Water elemental and Massive Water Elemental loot...
  26.         }
  27.     },
  28.     checkCorpseOwner = getConfigValue("checkCorpseOwner"),
  29.     rateLoot = getConfigValue("rateLoot"),
  30.  
  31.     summons = {
  32.         -- {skill, name, chance, bossName, bossChance}
  33.     },
  34.     rateSpawn = getConfigValue("rateSpawn"),
  35.  
  36.     baitFailRemoveChance = 10,
  37.     allowFromPz = false,
  38.     useBait = true,
  39.     baitCount = 1,
  40.     fishes = 1
  41. }
  42.  
  43. local function getFish(uid)
  44.     local lvl = getPlayerSkillLevel(cid, 6)
  45.     for i = 1, #config.fishes.leveis do
  46.         if not config.fishes.leveis[i + 1] then
  47.             return config.fishes.fish[config.fishes.leveis[i]]
  48.         elseif lvl <= lvls[i] then
  49.             return config.fishes.fish[config.fishes.leveis[i]]
  50.         end
  51.     end
  52.    
  53.     return 2670
  54. end
  55.  
  56. config.checkCorpseOwner = getBooleanFromString(config.checkCorpseOwner)
  57.  
  58. function onUse(cid, item, fromPosition, itemEx, toPosition)
  59.     if(isInArray(config.waters, itemEx.itemid)) then
  60.         if(isInArray(config.spawning, itemEx.itemid)) then
  61.             doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
  62.         end
  63.  
  64.         doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
  65.         return true
  66.     end
  67.  
  68.     local corpse = config.corpses[itemEx.itemid]
  69.     if(corpse ~= nil) then
  70.         local owner = getItemAttribute(cid, "corpseowner")
  71.         if(owner ~= 0 and owner ~= getPlayerGUID(cid) and config.checkCorpseOwner) then
  72.             doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUARENOTTHEOWNER)
  73.             return true
  74.         end
  75.  
  76.         local chance, items = math.random(0, 100000) / config.rateLoot, {}
  77.         for _, data in ipairs(corpse) do
  78.             if(data[3] >= chance) then
  79.                 local tmp = {data[1], math.random(1, data[2])}
  80.                 table.insert(items, tmp)
  81.             end
  82.         end
  83.  
  84.         local itemCount = table.maxn(items)
  85.         if(itemCount > 0) then
  86.             local loot = items[math.random(1, itemCount)]
  87.             doPlayerAddItem(cid, loot[1], loot[2])
  88.         end
  89.  
  90.         doTransformItem(itemEx.uid, itemEx.uid + 1)
  91.         return true
  92.     end
  93.  
  94.     if(not isInArray(config.fishable, itemEx.itemid)) then
  95.         return false
  96.     end
  97.  
  98.     local position, formula, tries = getThingPosition(cid), getPlayerSkill(cid, SKILL_FISHING) / 200 + 0.85 * math.random(), 0
  99.     config.allowFromPz = config.allowFromPz or not getTileInfo(position).protection
  100.     if(item.itemid ~= ITEM_MECHANICAL_FISHING_ROD) then
  101.         if(config.allowFromPz and (not config.useBait or getPlayerItemCount(cid, ITEM_WORM) >= config.baitCount)) then
  102.             tries = 1
  103.             if(isInArray(config.holes, itemEx.itemid)) then
  104.                 if(doPlayerRemoveItem(cid, ITEM_WORM, config.baitCount)) then
  105.                     tries = 2
  106.                     if(formula > 0.83) then
  107.                         doPlayerAddItem(cid, ITEM_RAINBOW_TROUT, config.fishes)
  108.                     elseif(formula > 0.7) then
  109.                         doPlayerAddItem(cid, ITEM_NORTHERN_PIKE, config.fishes)
  110.                     elseif(formula > 0.5) then
  111.                         doPlayerAddItem(cid, ITEM_GREEN_PERCH, config.fishes)
  112.                     else
  113.                         doPlayerAddItem(cid, ITEM_FISH, config.fishes)
  114.                     end
  115.                 end
  116.             elseif(formula > 0.7 and doPlayerRemoveItem(cid, ITEM_WORM, config.baitCount)) then
  117.                 tries = 2
  118.                 if(table.maxn(config.summons) > 0 and getDistanceBetween(position, toPosition) < 2) then
  119.                     local skill, summon = getPlayerSkill(cid, SKILL_FISHING), {name = "", chance = 0, bossName = "", bossChance = 0}
  120.                     for _, data in pairs(config.summons) do
  121.                         if(skill >= data[1]) then
  122.                             summon.name = data[2]
  123.                             summon.chance = data[3]
  124.                             summon.bossName = data[4]
  125.                             summon.bossChance = data[5]
  126.                         end
  127.                     end
  128.  
  129.                     local random = math.random(1, 100000) / config.rateSpawn
  130.                     if(summon.bossName ~= "" and summon.bossChance >= random) then
  131.                         doCreateMonster(summon.bossName, position)
  132.                         tries = 4
  133.                     elseif(summon.name ~= "" and summon.chance >= random) then
  134.                         doCreateMonster(summon.name, position)
  135.                         tries = 3
  136.                     else
  137.                         doPlayerAddItem(cid, ITEM_FISH, config.fishes)
  138.                     end
  139.                 else
  140.                     doPlayerAddItem(cid, getFish(cid), config.fishes)
  141.                 end
  142.             end
  143.         end
  144.     elseif(config.allowFromPz and (not config.useBait or getPlayerItemCount(cid, ITEM_NAIL) >= config.baitCount)) then
  145.         if(formula > 0.7 and doPlayerRemoveItem(cid, ITEM_NAIL, config.baitCount)) then
  146.             doPlayerAddItem(cid, ITEM_MECHANICAL_FISH, config.fishes)
  147.             tries = 2
  148.         else
  149.             tries = 1
  150.         end
  151.     end
  152.  
  153.     if(tries > 1) then
  154.         doPlayerAddSkillTry(cid, SKILL_FISHING, tries)
  155.         if(not isInArray(config.holes, itemEx.itemid)) then
  156.             doTransformItem(itemEx.uid, itemEx.itemid + 6)
  157.         else
  158.             doTransformItem(itemEx.uid, itemEx.itemid + 1)
  159.         end
  160.  
  161.         doDecayItem(itemEx.uid)
  162.     elseif(tries > 0) then
  163.         doPlayerAddSkillTry(cid, SKILL_FISHING, 1)
  164.         if(config.baitFailRemoveChance >= math.random(1, 100)) then
  165.             if(item.itemid == ITEM_MECHANICAL_FISHING_ROD) then
  166.                 doPlayerRemoveItem(cid, ITEM_NAIL, config.baitCount)
  167.             else
  168.                 doPlayerRemoveItem(cid, ITEM_FISH, config.baitCount)
  169.             end
  170.         end
  171.     end
  172.  
  173.     doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
  174.     return true
  175. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement