• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Why my fishing.lua dont work?

gmstrikker

Well-Known Member
Joined
Jul 30, 2014
Messages
458
Solutions
1
Reaction score
50
It's my fishing system, fishs change if u have more lvl's but it's dont work so fine

Look, when i use fishing rod on water, dont have effect on water and dont give me fishs...

Look the logs and script guys
console when i use fishing rod (first only remove worms, latter no remove and dont do nothign, latter back to remove worms, but dont do effect on water and dont give fishs)
o5zrvSh.png


fishing.lua
Code:
  local items = {
  [1] = {item = 2670, desc = "itemname"},
  [2] = {item = 2667, desc = "itemname"},
  [3] = {item = 7159, desc = "itemname"},
  [4] = {item = 7158, desc = "itemname"},
  [5] = {item = 2669, desc = "itemname"},
  [6] = {item = 7963, desc = "itemname"}
  }
   
  local skillLevels = {
  {20, 40},  -- 1
  {40, 60},  -- 2
  {60, 80},  -- 3
  {80, 100},  -- 4
  {100, 130},  -- 5
  {130, 255}  -- 6
  }
   
  local chance = 30 --30% Chance to get item
  local fishingSkill = 0
   
  local fishable = {4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825}
  local VIP_WORM = 10224
   
  function onUse(cid, item, fromPosition, itemEx, toPosition)
  print(itemEx.itemid)
  if isInArray(fishable, itemEx.itemid) then
  print("fishing rod works")
         local hasVipItem = getPlayerItemCount(cid, VIP_WORM) >= 1 and true or false
         local hasWorms = getPlayerItemCount(cid, ITEM_WORM) >= 1 and true or false
  if  (hasVipItem or hasWorms) then
  print("you have the required item to fish")
  if(hasWorms) then
  doPlayerRemoveItem(cid, ITEM_WORM, 1)
  print("and they are regular worms")
  end
  else
  print("you don't have the required item to fish")
  doPlayerSendCancel(cid, "You must have worms to fish.")
  return false
  end
   
  fishingSkill = getPlayerSkillLevel(cid, SKILL_FISH)
  print("fishing skill "..fishingSkill)
  if math.random(1, 100) <= chance then
  for i = 1, #skillLevels do
  if fishingSkill >= skillLevels[i][1] and fishingSkill < skillLevels[i][2] then
  print("min "..skillLevels[i][1].." max "..skillLevels[i][2] )
  ITEM = items[math.random(1, i)]
  print("ITEM "..ITEM)
  end
  end
  end
   
  if (not ITEM) then
  print("no item")
  return true
  end
   
  doPlayerAddItem(cid, ITEM.item, 1)
  doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have caught a "..ITEM.desc..".")
  doSendMagicEffect(toPosition, 1)
  end
  return true
  end
 
Try this. Say if it works, if not what happens.
Code:
    local items = {
    [1] = {item = 2670, desc = "itemname"},
    [2] = {item = 2667, desc = "itemname"},
    [3] = {item = 7159, desc = "itemname"},
    [4] = {item = 7158, desc = "itemname"},
    [5] = {item = 2669, desc = "itemname"},
    [6] = {item = 7963, desc = "itemname"}
    }

    local skillLevels = {
    {20, 40},  -- 1
    {40, 60},  -- 2
    {60, 80},  -- 3
    {80, 100},  -- 4
    {100, 130},  -- 5
    {130, 255}  -- 6
    }

    local chance = 30 --30% Chance to get item
    local fishingSkill = 0

    local fishable = {4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825}
    local VIP_WORM = 10224

    function onUse(cid, item, fromPosition, itemEx, toPosition)
        print(itemEx.itemid)
    if isInArray(fishable, itemEx.itemid) then
        print("fishing rod works")
        local hasVipItem = getPlayerItemCount(cid, VIP_WORM) >= 1 and true or false
        local hasWorms = getPlayerItemCount(cid, ITEM_WORM) >= 1 and true or false
        if  (hasVipItem or hasWorms) then
            print("you have the required item to fish")
            if(hasWorms) then
                doPlayerRemoveItem(cid, ITEM_WORM, 1)
                print("and they are regular worms")
            end
        else
            print("you don't have the required item to fish")
            doPlayerSendCancel(cid, "You must have worms to fish.")
        return false
    end

    fishingSkill = getPlayerSkillLevel(cid, SKILL_FISH)
        print("fishing skill "..fishingSkill)
    if math.random(1, 100) <= chance then
        for i = 1, #skillLevels do
            if fishingSkill >= skillLevels[i][1] and fishingSkill < skillLevels[i][2] then
                print("min "..skillLevels[i][1].." max "..skillLevels[i][2] )
                ITEM = items[math.random(1, i)]
                print("ITEM "..ITEM)
            end
        end
    end

    doPlayerAddItem(cid, ITEM.item, 1)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have caught a "..ITEM.desc..".")
    doSendMagicEffect(toPosition, 1)
    end
    return true
end
 
Try this. Say if it works, if not what happens.
Code:
    local items = {
    [1] = {item = 2670, desc = "itemname"},
    [2] = {item = 2667, desc = "itemname"},
    [3] = {item = 7159, desc = "itemname"},
    [4] = {item = 7158, desc = "itemname"},
    [5] = {item = 2669, desc = "itemname"},
    [6] = {item = 7963, desc = "itemname"}
    }

    local skillLevels = {
    {20, 40},  -- 1
    {40, 60},  -- 2
    {60, 80},  -- 3
    {80, 100},  -- 4
    {100, 130},  -- 5
    {130, 255}  -- 6
    }

    local chance = 30 --30% Chance to get item
    local fishingSkill = 0

    local fishable = {4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825}
    local VIP_WORM = 10224

    function onUse(cid, item, fromPosition, itemEx, toPosition)
        print(itemEx.itemid)
    if isInArray(fishable, itemEx.itemid) then
        print("fishing rod works")
        local hasVipItem = getPlayerItemCount(cid, VIP_WORM) >= 1 and true or false
        local hasWorms = getPlayerItemCount(cid, ITEM_WORM) >= 1 and true or false
        if  (hasVipItem or hasWorms) then
            print("you have the required item to fish")
            if(hasWorms) then
                doPlayerRemoveItem(cid, ITEM_WORM, 1)
                print("and they are regular worms")
            end
        else
            print("you don't have the required item to fish")
            doPlayerSendCancel(cid, "You must have worms to fish.")
        return false
    end

    fishingSkill = getPlayerSkillLevel(cid, SKILL_FISH)
        print("fishing skill "..fishingSkill)
    if math.random(1, 100) <= chance then
        for i = 1, #skillLevels do
            if fishingSkill >= skillLevels[i][1] and fishingSkill < skillLevels[i][2] then
                print("min "..skillLevels[i][1].." max "..skillLevels[i][2] )
                ITEM = items[math.random(1, i)]
                print("ITEM "..ITEM)
            end
        end
    end

    doPlayerAddItem(cid, ITEM.item, 1)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have caught a "..ITEM.desc..".")
    doSendMagicEffect(toPosition, 1)
    end
    return true
end

Dont work bro :(

OSfuD60.png
 
Im really bad with loops at this moment but you have not working this line, it can't specify what item to give.
Someone need to correct this whole loop.
Code:
        for i = 1, #skillLevels do
            if fishingSkill >= skillLevels[i][1] and fishingSkill < skillLevels[i][2] then
ITEM = items[math.random(1, i)]
I think it's not finished script because there vipitem is not used for anything, only useless code.
You didn't say what TFS version you use.

If you want working fishing system you could use that one from tfs 8.6 engines.

Code:
local config = {
    waters = {4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825},
    fishable = {4608, 4609, 4610, 4611, 4612, 4613, 7236},
    spawning = {4614, 4615, 4616, 4617, 4618, 4619},
    holes = {7236},

    corpses = {
        -- [corpse] = {[aid] = { {itemid, countmax, chance} }}
        [10499] = {
            [101] = {
                -- TODO: Water Elemental loot...
            },
            [102] = {
                -- TODO: Massive Water Elemental loot
            }
        }
    },
    checkCorpseOwner = getConfigValue("checkCorpseOwner"),
    rateLoot = getConfigValue("rateLoot"),

    summons = {
        -- {skill, name, chance, bossName, bossChance}
    },
    rateSpawn = getConfigValue("rateSpawn"),

    baitFailRemoveChance = 10,
    allowFromPz = false,
    useBait = true,
    baitCount = 1,
    fishes = 1
}

config.checkCorpseOwner = getBooleanFromString(config.checkCorpseOwner)

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(isInArray(config.waters, itemEx.itemid)) then
        if(isInArray(config.spawning, itemEx.itemid)) then
            doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
        end

        doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
        return true
    end

    local corpse = config.corpses[itemEx.itemid]
    if(corpse ~= nil) then
        corpse = corpse[itemEx.actionid]
        if(corpse ~= nil) then
            local owner = getItemAttribute(itemEx.uid, "corpseowner")
            if(owner ~= 0 and owner ~= getPlayerGUID(cid) and config.checkCorpseOwner) then
                doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUARENOTTHEOWNER)
                return true
            end

            local chance, items = math.random(0, 100000) / config.rateLoot, {}
            for _, data in ipairs(corpse) do
                if(data[3] >= chance) then
                    local tmp = {data[1], math.random(1, data[2])}
                    table.insert(items, tmp)
                end
            end

            local itemCount = table.maxn(items)
            if(itemCount > 0) then
                local loot = items[math.random(1, itemCount)]
                doPlayerAddItem(cid, loot[1], loot[2])
            end

            doTransformItem(itemEx.uid, getItemInfo(itemEx.itemid).decayTo)
            doSendMagicEffect(toPosition, CONST_ME_WATERSPLASH)
            doDecayItem(itemEx.uid)
            return true
        end
    end

    if(not isInArray(config.fishable, itemEx.itemid)) then
        return false
    end

    local position, formula, tries = getThingPosition(cid), getPlayerSkill(cid, SKILL_FISHING) / 200 + 0.85 * math.random(), 0
    config.allowFromPz = config.allowFromPz or not getTileInfo(position).protection
    if(item.itemid ~= ITEM_MECHANICAL_FISHING_ROD) then
        if(config.allowFromPz and (not config.useBait or getPlayerItemCount(cid, ITEM_WORM) >= config.baitCount)) then
            tries = 1
            if(isInArray(config.holes, itemEx.itemid)) then
                if(doPlayerRemoveItem(cid, ITEM_WORM, config.baitCount)) then
                    tries = 2
                    if(formula > 0.83) then
                        doPlayerAddItem(cid, ITEM_RAINBOW_TROUT, config.fishes)
                    elseif(formula > 0.7) then
                        doPlayerAddItem(cid, ITEM_NORTHERN_PIKE, config.fishes)
                    elseif(formula > 0.5) then
                        doPlayerAddItem(cid, ITEM_GREEN_PERCH, config.fishes)
                    else
                        doPlayerAddItem(cid, ITEM_FISH, config.fishes)
                    end
                end
            elseif(formula > 0.7 and doPlayerRemoveItem(cid, ITEM_WORM, config.baitCount)) then
                tries = 2
                if(table.maxn(config.summons) > 0 and getDistanceBetween(position, toPosition) < 2) then
                    local skill, summon = getPlayerSkill(cid, SKILL_FISHING), {name = "", chance = 0, bossName = "", bossChance = 0}
                    for _, data in pairs(config.summons) do
                        if(skill >= data[1]) then
                            summon.name = data[2]
                            summon.chance = data[3]
                            summon.bossName = data[4]
                            summon.bossChance = data[5]
                        end
                    end

                    local random = math.random(1, 100000) / config.rateSpawn
                    if(summon.bossName ~= "" and summon.bossChance >= random) then
                        doCreateMonster(summon.bossName, position)
                        tries = 4
                    elseif(summon.name ~= "" and summon.chance >= random) then
                        doCreateMonster(summon.name, position)
                        tries = 3
                    else
                        doPlayerAddItem(cid, ITEM_FISH, config.fishes)
                    end
                else
                    doPlayerAddItem(cid, ITEM_FISH, config.fishes)
                end
            end
        end
    elseif(config.allowFromPz and (not config.useBait or getPlayerItemCount(cid, ITEM_NAIL) >= config.baitCount)) then
        if(formula > 0.7 and doPlayerRemoveItem(cid, ITEM_NAIL, config.baitCount)) then
            doPlayerAddItem(cid, ITEM_MECHANICAL_FISH, config.fishes)
            tries = 2
        else
            tries = 1
        end
    end

    if(tries > 1) then
        doPlayerAddSkillTry(cid, SKILL_FISHING, tries)
        if(not isInArray(config.holes, itemEx.itemid)) then
            doTransformItem(itemEx.uid, itemEx.itemid + 6)
        else
            doTransformItem(itemEx.uid, itemEx.itemid + 1)
        end

        doDecayItem(itemEx.uid)
    elseif(tries > 0) then
        doPlayerAddSkillTry(cid, SKILL_FISHING, 1)
        if(config.baitFailRemoveChance >= math.random(1, 100)) then
            if(item.itemid == ITEM_MECHANICAL_FISHING_ROD) then
                doPlayerRemoveItem(cid, ITEM_NAIL, config.baitCount)
            else
                doPlayerRemoveItem(cid, ITEM_FISH, config.baitCount)
            end
        end
    end

    doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
    return true
end
 
Last edited:
i think error is here:
if(formula > 0.83) then

wait a better member im a noob :\
Indeed you are.
My script is working but gmstrikker want his own script > modified.
I could made it but it would take too much time for me and im not interested in 8.6 anymore.

I suggest you to use that script i posted and edit it for your purposes because your script looks really sad.
 
Indeed you are.
My script is working but gmstrikker want his own script > modified.
I could made it but it would take too much time for me and im not interested in 8.6 anymore.

I suggest you to use that script i posted and edit it for your purposes because your script looks really sad.

Yeah, i'm but i know it
You think is good, but isnt, you can not even read the script, let alone solve it
Your script is base TFS script...

So, dont lie please...

my suggestion is: expect someone who actually know something
 
Yeah, i'm but i know it
You think is good, but isnt, you can not even read the script, let alone solve it
Your script is base TFS script...

So, dont lie please...

my suggestion is: expect someone who actually know something
Maybe you understand scripts abit but obviously you dont understand english enough to communicate with others. I give him base TFS script so he could edit it with only understanding the code.

gmstrikker feel my good heart i worked few hours to make it.
It is 100% like you wanted to be.
Tested on TFS 0.4_SVN (8.60)
I am waiting on your feedback how is it working.
Code:
local config = {
    waters = {4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825},
    fishable = {4608, 4609, 4610, 4611, 4612, 4613, 7236},
    spawning = {4614, 4615, 4616, 4617, 4618, 4619},
    holes = {7236},
    baitCount = 1,
    fishes = 1,
    chance = 30
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(isInArray(config.waters, itemEx.itemid)) then
        if(isInArray(config.spawning, itemEx.itemid)) then
            doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
        end

        doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
        return true
    end

    if(not isInArray(config.fishable, itemEx.itemid)) then
        return false
    end

    local position, tries, myfisning = getThingPosition(cid), 0, getPlayerSkill(cid, SKILL_FISHING)
    config.allowFromPz = config.allowFromPz or not getTileInfo(position).protection
    if(item.itemid ~= ITEM_MECHANICAL_FISHING_ROD) then
        if(getPlayerItemCount(cid, ITEM_WORM) >= config.baitCount) then
            tries = 1
            if(math.random(100) <= config.chance) then
                if(doPlayerRemoveItem(cid, ITEM_WORM, config.baitCount)) then
                    tries = 2
                    if(myfisning >= 0) and (myfisning < 40) then
                        doPlayerAddItem(cid, 2670, config.fishes)
                    elseif(myfisning >= 40) and (myfisning < 60) then
                        doPlayerAddItem(cid, 2667, config.fishes)
                    elseif(myfisning >= 60) and (myfisning < 80) then
                        doPlayerAddItem(cid, 7159, config.fishes)
                    elseif(myfisning >= 80) and (myfisning < 100) then
                        doPlayerAddItem(cid, 7158, config.fishes)
                    elseif(myfisning >= 100) and (myfisning < 130) then
                        doPlayerAddItem(cid, 2669, config.fishes)
                    elseif(myfisning >= 130) then
                        doPlayerAddItem(cid, 7963, config.fishes)
                    else
                        doPlayerAddItem(cid, ITEM_FISH, config.fishes)
                    end
                end
            end
        end
    end

    if(tries > 1) then
        doPlayerAddSkillTry(cid, SKILL_FISHING, tries)
        if(not isInArray(config.holes, itemEx.itemid)) then
            doTransformItem(itemEx.uid, itemEx.itemid + 6)
        else
            doTransformItem(itemEx.uid, itemEx.itemid + 1)
        end
        doDecayItem(itemEx.uid)
    elseif(tries > 0) then
        doPlayerAddSkillTry(cid, SKILL_FISHING, 1)
    end

    doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
    return true
end
 
Last edited:
Maybe you understand scripts abit but obviously you dont understand english enough to communicate with others. I give him base TFS script so he could edit it with only understanding the code.

gmstrikker feel my good heart i worked few hours to make it.
It is 100% like you wanted to be.
Tested on TFS 0.4_SVN (8.60)
I am waiting on your feedback how is it working.
Code:
local config = {
    waters = {4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825},
    fishable = {4608, 4609, 4610, 4611, 4612, 4613, 7236},
    spawning = {4614, 4615, 4616, 4617, 4618, 4619},
    holes = {7236},
    baitCount = 1,
    fishes = 1,
    chance = 30
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(isInArray(config.waters, itemEx.itemid)) then
        if(isInArray(config.spawning, itemEx.itemid)) then
            doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
        end

        doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
        return true
    end

    if(not isInArray(config.fishable, itemEx.itemid)) then
        return false
    end

    local position, tries, myfisning = getThingPosition(cid), 0, getPlayerSkill(cid, SKILL_FISHING)
    config.allowFromPz = config.allowFromPz or not getTileInfo(position).protection
    if(item.itemid ~= ITEM_MECHANICAL_FISHING_ROD) then
        if(getPlayerItemCount(cid, ITEM_WORM) >= config.baitCount) then
            tries = 1
            if(math.random(100) <= config.chance) then
                if(doPlayerRemoveItem(cid, ITEM_WORM, config.baitCount)) then
                    tries = 2
                    if(myfisning >= 0) and (myfisning < 40) then
                        doPlayerAddItem(cid, 2670, config.fishes)
                    elseif(myfisning >= 40) and (myfisning < 60) then
                        doPlayerAddItem(cid, 2667, config.fishes)
                    elseif(myfisning >= 60) and (myfisning < 80) then
                        doPlayerAddItem(cid, 7159, config.fishes)
                    elseif(myfisning >= 80) and (myfisning < 100) then
                        doPlayerAddItem(cid, 7158, config.fishes)
                    elseif(myfisning >= 100) and (myfisning < 130) then
                        doPlayerAddItem(cid, 2669, config.fishes)
                    elseif(myfisning >= 130) then
                        doPlayerAddItem(cid, 7963, config.fishes)
                    else
                        doPlayerAddItem(cid, ITEM_FISH, config.fishes)
                    end
                end
            end
        end
    end

    if(tries > 1) then
        doPlayerAddSkillTry(cid, SKILL_FISHING, tries)
        if(not isInArray(config.holes, itemEx.itemid)) then
            doTransformItem(itemEx.uid, itemEx.itemid + 6)
        else
            doTransformItem(itemEx.uid, itemEx.itemid + 1)
        end
        doDecayItem(itemEx.uid)
    elseif(tries > 0) then
        doPlayerAddSkillTry(cid, SKILL_FISHING, 1)
    end

    doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
    return true
end

PERFECT man! TY SO MUCH!!!!!
 
Back
Top