• 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!

Action Fishing on Steroids TFS 1.2

Itutorial

Legendary OT User
Joined
Dec 23, 2014
Messages
2,334
Solutions
68
Reaction score
1,011
Advanced fishing action and talkaction script.

This code supports:
-Monster catching
-Fish up items/trash
-Chance to break rod
-Use worms
-Chance to catch random fish
-*Automatic Fishing*
-players can check what monsters they or another player has fished up with a talkaction

Actionscript
Lua:
--All chances are out of 100000--
local waters = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 7236, 10499, 15401, 15402}
local monsters = {
    [1] = {name = "Fish1", levelReq = 50, fishingReq = 50, storage = 10000, chance = 1000, msg = nil, magicEffect = CONST_ME_LOSEENERGY},
    [2] = {name = "Fish2", levelReq = 50, fishingReq = 50, storage = 10001, chance = 800, msg = "|PLAYERNAME| has caught a Fish2!", magicEffect = CONST_ME_LOSEENERGY}
}
local items = {
    [1] = {itemid = 1111, chance = 1000, onGround = true}, -- true = the item will fall on the ground under the player. This is used for player fishing trash if wanted.
    [2] = {itemid = 1111, chance = 800, onGround = false}
}
local monsterEnabled = true
local itemsEnabled = true
--Set to false if you do not want any of these--
local chanceBreakRod = 1000
local catchFish = 1000
local fishIds = {1111, 1111, 1111} --Type the fish ids they can catch => normal, salmon, ect.
local useWorms = false
local automaticFishing = false --If this is true players will not have to fish manually they will fish until they move.--
local msgStart = "You will automatically fish until you move."
local msgStop = "You have stopped automatic fishing."
-------------------------------------------------
function onUse(player, item, target, fromPosition, toPosition, isHotkey)
    if not isInArray(waters, target:getId()) then
        return false
    end
   
    local TILE = Tile(fromPosition)
   
    if TILE:getPzInfo() then
        return player:sendCancelMessage("You cannot fish in protection zones.")
    end
   
    if useWorms and not player:removeItem("worm", 1) then
        return player:sendCancelMessage("You need worms to fish with!")
    end
   
    if monsterEnabled then
        for i = 1, #monsters do
            if player:getLevel() >= monsters[i].levelReq and player:getSkillLevel(SKILL_FISHING) >= monsters[i].fishingReq then
                if math.random(1, 100000) <= monsters[i].chance then
                local MONS = Game.createMonster(monsters[i].name, fromPosition)
                if MONS then
                    MONS:setDescription(MONS:getDescription().."\nIt was caught by: "..player:getName()..".")
                end
                if player:getStorageValue(monsters[i].storage) == nil then
                    player:setStorageValue(monsters[i].storage, 1)
                else
                    player:setStorageValue(monsters[i].storage, player:getStorageValue(monsters[i].storage) + 1)
                end
                if monsters[i].msg then
                    local text = string.gsub(monsters[i].msg, "|PLAYERNAME|", player:getName())
                    Game.broadcastMessage(text, 1)
                end
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have caught a(n) "..monsters[i].name.."!")
                player:getPosition():sendMagicEffect(monsters[i].magicEffect)
                break
                end
            end
        end
    end
   
    if itemsEnabled then
        for i = 1, #items do
            if math.random(1, 100000) <= items[i].chance then
                if items[i].onGround then
                    Game.createItem(items[i].itemid, 1, fromPosition)
                else
                    player:addItem(items[i].itemid, 1)
                end
                break
            end
        end
    end
   
    if chanceBreakRod ~= false and math.random(1, 100000) <= chanceBreakRod then
        item:remove()
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Your fishing rod has broken.")
    end
   
    if catchFish ~= false and math.random(1, 100000) <= catchFish then
        local fishId = fishIds[math.random(1, #fishIds)]
        player:addItem(fishId, 1)
    end
   
    if automaticFishing then
        local pos = player:getPosition()
        local pid = player:getId()
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, msgStart)
        startAutomaticFishing(pid, pos, toPosition)
    end
    player:addSkillTries(SKILL_FISHING, 1)
    toPosition:sendMagicEffect(CONST_ME_LOSEENERGY}
return true
end
function startAutomaticFishing(pid, pos, toPosition)
    local player = Player(pid)
    if player then
        if player:getPosition() == pos then
            if useWorms and player:getItemCount(1111) < 1 then
                return player:sendCancelMessage("You need worms to fish with!")
            end
   
            if monsterEnabled then
                for i = 1, #monsters do
                    if player:getLevel() >= monsters[i].levelReq and player:getSkillLevel(SKILL_FISHING) >= monsters[i].fishingReq then
                        if math.random(1, 100000) <= monsters[i].chance then
                        local MONS = Game.createMonster(monsters[i].name, fromPosition)
                        if MONS then
                            MONS:setDescription(MONS:getDescription().."\nIt was caught by: "..player:getName()..".")
                        end
                        if player:getStorageValue(monsters[i].storage) == nil then
                            player:setStorageValue(monsters[i].storage, 1)
                        else
                            player:setStorageValue(monsters[i].storage, player:getStorageValue(monsters[i].storage) + 1)
                        end
                        if monsters[i].msg then
                            local text = string.gsub(monsters[i].msg, "|PLAYERNAME|", player:getName())
                            Game.broadcastMessage(text, 1)
                        end
                        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have caught a(n) "..monsters[i].name.."!")
                        player:getPosition():sendMagicEffect(monsters[i].magicEffect)
                        break
                        end
                    end
                end
            end
   
            if itemsEnabled then
                for i = 1, #items do
                    if math.random(1, 100000) <= items[i].chance then
                        if items[i].onGround then
                            Game.createItem(items[i].itemid, 1, fromPosition)
                        else
                            player:addItem(items[i].itemid, 1)
                        end
                    break
                    end
                end
            end
   
    if chanceBreakRod ~= false and math.random(1, 100000) <= chanceBreakRod then
        item:remove()
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Your fishing rod has broken.")
    end
   
    if catchFish ~= false and math.random(1, 100000) <= catchFish then
        local fishId = fishIds[math.random(1, #fishIds)]
        player:addItem(fishId, 1)
    end
   
    player:addSkillTries(SKILL_FISHING, 1)
    toPosition:sendMagicEffect(CONST_ME_LOSEENERGY}
    addEvent(startAutomaticFishing, 2000, pid, pos, toPosition)
    end
    end
end


Talkaction: !catchs // !catchs playername
Lua:
function onSay(player, words, param, channel)
    if param == "" then
        local text = "[Catches]\n"
        for i = 1, #monsters do
            if player:getStorageValue(monsters[i].storage) == nil then
                player:setStorageValue(monsters[i].storage, 1)
            end
            text = text..""..monsters[i].name..": "..player:getStorageValue(monsters[i].storage).."\n"
        end
        player:showTextDialog(2160, text)
       
    else
        local target = Player(param)
        if not target then
            return player:sendCancelMessage("Player is not online or does not exist.")
        end
       
        local text = "["..param.."'s Catches]\n"
        for i = 1, #monsters do
            if target:getStorageValue(monsters[i].storage) == nil then
                target:setStorageValue(monsters[i].storage, 1)
            end
            text = text..""..monsters[i].name..": "..target:getStorageValue(monsters[i].storage).."\n"
        end
        player:showTextDialog(2160, text)
    end
return true
end
 
Im getting this error

Lua Script Error: [Action Interface]
data/actions/scripts/tools/fishing.lua:eek:nUse
data/actions/scripts/tools/fishing.lua:25: attempt to call method 'getId' (a nil value)
stack traceback:
[C]: in function 'getId'
data/actions/scripts/tools/fishing.lua:25: in function <data/actions/scripts/tools/fishing.lua:24>
 
Change

if not isInArray(waters, target:getId()) then

to

if not isInArray(waters, target.itemid) then
 
What distro are you using?

If you give me a list of what parts of this code you want I can create a better one that is cleaner for you.
 
Last edited by a moderator:
The Script is pretty much what i want.

fishing up items
fishing up monsters
fishing up fish
auto fishing is nice
usage of worms

only thing i "dislike" is rod breaking but since you are able to disable it its all good
 
I hate that i cant edit post so sorry for double posting...
Btw uses tfs 1.2 says so in my signature ;)
 
Alright add this line to your login.lua somewhere

Lua:
player:setStorageValue(15000, 0)

Then this is the fishing code.
Lua:
--Broadcast will broadcast the players catch to the whole server.--
--|PLAYERNAME| is automatically changed to the players name in the code you can put it at any time in the message.--
local waters = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 7236, 10499, 15401, 15402}

local monsters = {
    [1] = {name = "Mons Name1", chance = 1000, level = 50, fishing = 80, msg = "|PLAYERNAME| has caught a(n) Mons Name1!", broadcast = true}
}

local items = {
    [1] = {itemid = 1111, chance = 1000, onGround = true}, -- onGround = true means is the player doesnt have room or capacity item will drop on the ground.
    [2] = {itemid = 1111, chance = 1000}
}

local fish = {
    [1] = {itemid = 1111, chance = 15000}, --Normal Fish
    [2] = {itemid = 1111, chance = 7000}, --Northern Pike
    [3] = {itemid = 1111, chance = 3000}, --Salmon
}

local baseChance = 100000 --This chance is used against all other chances to dertermine if a monster is caught, and item is fished up, or a fish is fished up.
local wormItemId = 1111 --Set to the worms item id

function onUse(player, item, fromPosition, target, toPosition)
    if not isInArray(waters, target.itemid) then
        return false
    end
   
    local tile = Tile(fromPosition)
   
    if tile and tile:getPzInfo() then
        return player:sendCancelMessage("You may not fish in protection zone.")
    end
   
    if player:getStorageValue(15000) == 1 then
        return player:sendCancelMessage("You are automatically fishing. You do not need to use your rod manually.")
    end
   
    if player:getItemCount(wormItemId) < 1 then
        return player:sendCancelMessage("You must have worms to fish.")
    end

    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will now automatically fish until you move.")
    local pos = player:getPosition()
    player:setStorageValue(15000, 1)
    addEvent(executeFishing, 1000, player, pos, toPosition)
return true
end


function executeFishing(player, pos, toPosition)
    if not player then return true end
   
    if player:getStorageValue(15000) ~= 1 then return true end
   
    if player:getItemCount(wormItemId) < 1 then
        return player:sendCancelMessage("You have run out of worms.")
    end
   
    if player:getPosition() ~= pos then
        player:setStorageValue(15000, 0)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are no longer automatically fishing.")
        return true
    end
   
    for i = 1, #monsters do
        if player:getLevel() >= monsters[i].level and player:getSkillLevel(SKILL_FISHING) >= monsters[i].fishing then   
            if math.random(1, baseChance) <= monsters[i].chance then
                Game.createMonster(monsters[i].name, player:getPosition())
                if monsters[i].broadcast then
                    local text = string.gsub(monsters[i].msg, "|PLAYERNAME|", player:getName())
                    Game.broadcastMessage(text)
                end
                break
            end
        end
    end
   
    for i = 1, #items do
        if math.random(1, baseChance) <= items[i].chance then
            if items[i].onGround then
                player:addItem(items[i].itemid, 1, true)
            else
                player:addItem(items[i].itemid, 1, false)
            end
        end
    end
   
    for i = 1, #fish do
        if math.random(1, baseChance) <= fish[i].chance then
            player:addItem(fish[i].itemid, 1, true)
        end
    end
   
    player:addSkillTries(SKILL_FISHING, 1)
    player:removeItem(wormItemId, 1)
    toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
    addEvent(executeFishing, 1000, player, pos, toPosition)
return true
end
 
  • function executeFishing(player, pos, toPosition)
  • if not player then return true end
unsafe

Lua:
function executeFishing(cid, pos, toPosition)
    local player = Player(cid)
    if not player then return end
    -- the rest
Lua:
addEvent(executeFishing, 1000, player:getId(), pos, toPosition)
 
Lua:
--Broadcast will broadcast the players catch to the whole server.--
--|PLAYERNAME| is automatically changed to the players name in the code you can put it at any time in the message.--
local waters = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 7236, 10499, 15401, 15402}

local monsters = {
    [1] = {name = "Mons Name1", chance = 1000, level = 50, fishing = 80, msg = "|PLAYERNAME| has caught a(n) Mons Name1!", broadcast = true}
}

local items = {
    [1] = {itemid = 1111, chance = 1000, onGround = true}, -- onGround = true means is the player doesnt have room or capacity item will drop on the ground.
    [2] = {itemid = 1111, chance = 1000}
}

local fish = {
    [1] = {itemid = 1111, chance = 15000}, --Normal Fish
    [2] = {itemid = 1111, chance = 7000}, --Northern Pike
    [3] = {itemid = 1111, chance = 3000}, --Salmon
}

local baseChance = 100000 --This chance is used against all other chances to dertermine if a monster is caught, and item is fished up, or a fish is fished up.
local wormItemId = 1111 --Set to the worms item id

function onUse(player, item, fromPosition, target, toPosition)
    if not isInArray(waters, target.itemid) then
        return false
    end
   
    local tile = Tile(fromPosition)
   
    if tile and tile:getPzInfo() then
        return player:sendCancelMessage("You may not fish in protection zone.")
    end
   
    if player:getStorageValue(15000) == 1 then
        return player:sendCancelMessage("You are automatically fishing. You do not need to use your rod manually.")
    end
   
    if player:getItemCount(wormItemId) < 1 then
        return player:sendCancelMessage("You must have worms to fish.")
    end

    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will now automatically fish until you move.")
    local pos = player:getPosition()
    player:setStorageValue(15000, 1)
    addEvent(executeFishing, 1000, player:getGuid(), pos, toPosition)
return true
end


function executeFishing(playerId, pos, toPosition)
    local player = Player(playerId)

if not player then return true end
   
    if player:getStorageValue(15000) ~= 1 then return true end
   
    if player:getItemCount(wormItemId) < 1 then
        return player:sendCancelMessage("You have run out of worms.")
    end
   
    if player:getPosition() ~= pos then
        player:setStorageValue(15000, 0)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are no longer automatically fishing.")
        return true
    end
   
    for i = 1, #monsters do
        if player:getLevel() >= monsters[i].level and player:getSkillLevel(SKILL_FISHING) >= monsters[i].fishing then 
            if math.random(1, baseChance) <= monsters[i].chance then
                Game.createMonster(monsters[i].name, player:getPosition())
                if monsters[i].broadcast then
                    local text = string.gsub(monsters[i].msg, "|PLAYERNAME|", player:getName())
                    Game.broadcastMessage(text)
                end
                break
            end
        end
    end
   
    for i = 1, #items do
        if math.random(1, baseChance) <= items[i].chance then
            if items[i].onGround then
                player:addItem(items[i].itemid, 1, true)
            else
                player:addItem(items[i].itemid, 1, false)
            end
        end
    end
   
    for i = 1, #fish do
        if math.random(1, baseChance) <= fish[i].chance then
            player:addItem(fish[i].itemid, 1, true)
        end
    end
   
    player:addSkillTries(SKILL_FISHING, 1)
    player:removeItem(wormItemId, 1)
    toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
    addEvent(executeFishing, 1000, player, pos, toPosition)
return true
end

shit this one...mod please fix this mess

Lua:
--Broadcast will broadcast the players catch to the whole server.--
--|PLAYERNAME| is automatically changed to the players name in the code you can put it at any time in the message.--
local waters = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 7236, 10499, 15401, 15402}

local monsters = {
    [1] = {name = "Mons Name1", chance = 1000, level = 50, fishing = 80, msg = "|PLAYERNAME| has caught a(n) Mons Name1!", broadcast = true}
}

local items = {
    [1] = {itemid = 1111, chance = 1000, onGround = true}, -- onGround = true means is the player doesnt have room or capacity item will drop on the ground.
    [2] = {itemid = 1111, chance = 1000}
}

local fish = {
    [1] = {itemid = 1111, chance = 15000}, --Normal Fish
    [2] = {itemid = 1111, chance = 7000}, --Northern Pike
    [3] = {itemid = 1111, chance = 3000}, --Salmon
}

local baseChance = 100000 --This chance is used against all other chances to dertermine if a monster is caught, and item is fished up, or a fish is fished up.
local wormItemId = 1111 --Set to the worms item id

function onUse(player, item, fromPosition, target, toPosition)
    if not isInArray(waters, target.itemid) then
        return false
    end
   
    local tile = Tile(fromPosition)
   
    if tile and tile:getPzInfo() then
        return player:sendCancelMessage("You may not fish in protection zone.")
    end
   
    if player:getStorageValue(15000) == 1 then
        return player:sendCancelMessage("You are automatically fishing. You do not need to use your rod manually.")
    end
   
    if player:getItemCount(wormItemId) < 1 then
        return player:sendCancelMessage("You must have worms to fish.")
    end

    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will now automatically fish until you move.")
    local pos = player:getPosition()
    player:setStorageValue(15000, 1)
    addEvent(executeFishing, 1000, player:getGuid(), pos, toPosition)
return true
end


function executeFishing(playerId, pos, toPosition)
    local player = Player(playerId)

if not player then return true end
   
    if player:getStorageValue(15000) ~= 1 then return true end
   
    if player:getItemCount(wormItemId) < 1 then
        return player:sendCancelMessage("You have run out of worms.")
    end
   
    if player:getPosition() ~= pos then
        player:setStorageValue(15000, 0)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are no longer automatically fishing.")
        return true
    end
   
    for i = 1, #monsters do
        if player:getLevel() >= monsters[i].level and player:getSkillLevel(SKILL_FISHING) >= monsters[i].fishing then
            if math.random(1, baseChance) <= monsters[i].chance then
                Game.createMonster(monsters[i].name, player:getPosition())
                if monsters[i].broadcast then
                    local text = string.gsub(monsters[i].msg, "|PLAYERNAME|", player:getName())
                    Game.broadcastMessage(text)
                end
                break
            end
        end
    end
   
    for i = 1, #items do
        if math.random(1, baseChance) <= items[i].chance then
            if items[i].onGround then
                player:addItem(items[i].itemid, 1, true)
            else
                player:addItem(items[i].itemid, 1, false)
            end
        end
    end
   
    for i = 1, #fish do
        if math.random(1, baseChance) <= fish[i].chance then
            player:addItem(fish[i].itemid, 1, true)
        end
    end
   
    player:addSkillTries(SKILL_FISHING, 1)
    player:removeItem(wormItemId, 1)
    toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
    addEvent(executeFishing, 1000, player:getGuid(), pos, toPosition)
return true
end
 
Last edited by a moderator:
shit this one...mod please fix this mess

Lua:
--Broadcast will broadcast the players catch to the whole server.--
--|PLAYERNAME| is automatically changed to the players name in the code you can put it at any time in the message.--
local waters = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 7236, 10499, 15401, 15402}

local monsters = {
    [1] = {name = "Mons Name1", chance = 1000, level = 50, fishing = 80, msg = "|PLAYERNAME| has caught a(n) Mons Name1!", broadcast = true}
}

local items = {
    [1] = {itemid = 1111, chance = 1000, onGround = true}, -- onGround = true means is the player doesnt have room or capacity item will drop on the ground.
    [2] = {itemid = 1111, chance = 1000}
}

local fish = {
    [1] = {itemid = 1111, chance = 15000}, --Normal Fish
    [2] = {itemid = 1111, chance = 7000}, --Northern Pike
    [3] = {itemid = 1111, chance = 3000}, --Salmon
}

local baseChance = 100000 --This chance is used against all other chances to dertermine if a monster is caught, and item is fished up, or a fish is fished up.
local wormItemId = 1111 --Set to the worms item id

function onUse(player, item, fromPosition, target, toPosition)
    if not isInArray(waters, target.itemid) then
        return false
    end
  
    local tile = Tile(fromPosition)
  
    if tile and tile:getPzInfo() then
        return player:sendCancelMessage("You may not fish in protection zone.")
    end
  
    if player:getStorageValue(15000) == 1 then
        return player:sendCancelMessage("You are automatically fishing. You do not need to use your rod manually.")
    end
  
    if player:getItemCount(wormItemId) < 1 then
        return player:sendCancelMessage("You must have worms to fish.")
    end

    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will now automatically fish until you move.")
    local pos = player:getPosition()
    player:setStorageValue(15000, 1)
    addEvent(executeFishing, 1000, player:getGuid(), pos, toPosition)
return true
end


function executeFishing(playerId, pos, toPosition)
    local player = Player(playerId)

if not player then return true end
  
    if player:getStorageValue(15000) ~= 1 then return true end
  
    if player:getItemCount(wormItemId) < 1 then
        return player:sendCancelMessage("You have run out of worms.")
    end
  
    if player:getPosition() ~= pos then
        player:setStorageValue(15000, 0)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are no longer automatically fishing.")
        return true
    end
  
    for i = 1, #monsters do
        if player:getLevel() >= monsters[i].level and player:getSkillLevel(SKILL_FISHING) >= monsters[i].fishing then
            if math.random(1, baseChance) <= monsters[i].chance then
                Game.createMonster(monsters[i].name, player:getPosition())
                if monsters[i].broadcast then
                    local text = string.gsub(monsters[i].msg, "|PLAYERNAME|", player:getName())
                    Game.broadcastMessage(text)
                end
                break
            end
        end
    end
  
    for i = 1, #items do
        if math.random(1, baseChance) <= items[i].chance then
            if items[i].onGround then
                player:addItem(items[i].itemid, 1, true)
            else
                player:addItem(items[i].itemid, 1, false)
            end
        end
    end
  
    for i = 1, #fish do
        if math.random(1, baseChance) <= fish[i].chance then
            player:addItem(fish[i].itemid, 1, true)
        end
    end
  
    player:addSkillTries(SKILL_FISHING, 1)
    player:removeItem(wormItemId, 1)
    toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
    addEvent(executeFishing, 1000, player:getGuid(), pos, toPosition)
return true
end
should be using getId() not getGuid(), you can't construct a Player instance with GUID pre-tfs 1.3
 
Everything inside the script works as a charm!
However one small problem..
I made the script for fishing rod and it works fine, and then i wanted to copy the script and make a new one with slightly different rewards but when i do that the old one does not work anymore... its wierd.

I did change storage, added a new line in login.lua installed it just like the other one.
it gives no errors just doesn't let me fish.. nothing happens.
 
Add "local" infront of all functions that are not onUse
 
I know this is old but I am not sure if it works so I wanted to correct it.

Lua:
--Broadcast will broadcast the players catch to the whole server.--
--|PLAYERNAME| is automatically changed to the players name in the code you can put it at any time in the message.--
local waters = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 7236, 10499, 15401, 15402}

local monsters = {
    [1] = {name = "Mons Name1", chance = 1000, level = 50, fishing = 80, msg = "|PLAYERNAME| has caught a(n) Mons Name1!", broadcast = true}
}

local items = {
    [1] = {itemid = 1111, chance = 1000, onGround = true}, -- onGround = true means is the player doesnt have room or capacity item will drop on the ground.
    [2] = {itemid = 1111, chance = 1000}
}

local fish = {
    [1] = {itemid = 1111, chance = 15000}, --Normal Fish
    [2] = {itemid = 1111, chance = 7000}, --Northern Pike
    [3] = {itemid = 1111, chance = 3000}, --Salmon
}

local autoFish = true -- Set to false if you do not want auto fishing.
local useWorms = true

local baseChance = 100000 --This chance is used against all other chances to dertermine if a monster is caught, and item is fished up, or a fish is fished up.
local wormItemId = 1111 --Set to the worms item id

local fishingPlayers = {} -- Dont touch

function onUse(player, item, fromPosition, target, toPosition)
    if not isInArray(waters, target.itemid) then
        return false
    end
   
    local tile = Tile(fromPosition)
   
    if tile and tile:getPzInfo() then
        return player:sendCancelMessage("You may not fish in protection zone.")
    end
   
    if fishingPlayers[player:getId()] then
        return player:sendCancelMessage("You are automatically fishing. You do not need to use your rod manually.")
    end
   
    if useWorms and player:getItemCount(wormItemId) < 1 then
        return player:sendCancelMessage("You must have worms to fish.")
    end
    if autoFish then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will now automatically fish until you move.")
        fishingPlayers[player:getId()] = true
    end
    local pos = player:getPosition()
    addEvent(executeFishing, 0, player:getId(), pos, toPosition)
return true
end


function executeFishing(playerId, pos, toPosition)
    local player = Player(playerId)

    if not player or player:getPosition() ~= pos then 
        if fishingPlayers[playerId] then
            fishingPlayers[playerId] = nil
        end
    return true 
    end
    
    if useWorms and player:getItemCount(wormItemId) < 1 then
        if fishingPlayers[playerId] then
            fishingPlayers[playerId] = nil
        end
        return player:sendCancelMessage("You have run out of worms.")
    end
   
    for i = 1, #monsters do
        if player:getLevel() >= monsters[i].level and player:getSkillLevel(SKILL_FISHING) >= monsters[i].fishing then
            if math.random(1, baseChance) <= monsters[i].chance then
                Game.createMonster(monsters[i].name, player:getPosition())
                if monsters[i].broadcast then
                    local text = string.gsub(monsters[i].msg, "|PLAYERNAME|", player:getName())
                    Game.broadcastMessage(text)
                end
                break
            end
        end
    end
   
    for i = 1, #items do
        if math.random(1, baseChance) <= items[i].chance then
            if items[i].onGround then
                player:addItem(items[i].itemid, 1, true)
            else
                player:addItem(items[i].itemid, 1, false)
            end
        end
    end
   
    for i = 1, #fish do
        if math.random(1, baseChance) <= fish[i].chance then
            player:addItem(fish[i].itemid, 1, true)
        end
    end
   
    player:addSkillTries(SKILL_FISHING, 1)
    player:removeItem(wormItemId, 1)
    toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
    if fishingPlayers[pid] then
        addEvent(executeFishing, 1000, player:getId(), pos, toPosition)
    end
return true
end
 
for some reason autofish do not work for me, just the first USE works but the player donot continue fishing after that one.
also I can move freely and the autofish function will not disable.

everything else works fine. im using tfs 1.3
no console errors btw.
Post automatically merged:

I know this is old but I am not sure if it works so I wanted to correct it.

Lua:
--Broadcast will broadcast the players catch to the whole server.--
--|PLAYERNAME| is automatically changed to the players name in the code you can put it at any time in the message.--
local waters = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 7236, 10499, 15401, 15402}

local monsters = {
    [1] = {name = "Mons Name1", chance = 1000, level = 50, fishing = 80, msg = "|PLAYERNAME| has caught a(n) Mons Name1!", broadcast = true}
}

local items = {
    [1] = {itemid = 1111, chance = 1000, onGround = true}, -- onGround = true means is the player doesnt have room or capacity item will drop on the ground.
    [2] = {itemid = 1111, chance = 1000}
}

local fish = {
    [1] = {itemid = 1111, chance = 15000}, --Normal Fish
    [2] = {itemid = 1111, chance = 7000}, --Northern Pike
    [3] = {itemid = 1111, chance = 3000}, --Salmon
}

local autoFish = true -- Set to false if you do not want auto fishing.
local useWorms = true

local baseChance = 100000 --This chance is used against all other chances to dertermine if a monster is caught, and item is fished up, or a fish is fished up.
local wormItemId = 1111 --Set to the worms item id

local fishingPlayers = {} -- Dont touch

function onUse(player, item, fromPosition, target, toPosition)
    if not isInArray(waters, target.itemid) then
        return false
    end
 
    local tile = Tile(fromPosition)
 
    if tile and tile:getPzInfo() then
        return player:sendCancelMessage("You may not fish in protection zone.")
    end
 
    if fishingPlayers[player:getId()] then
        return player:sendCancelMessage("You are automatically fishing. You do not need to use your rod manually.")
    end
 
    if useWorms and player:getItemCount(wormItemId) < 1 then
        return player:sendCancelMessage("You must have worms to fish.")
    end
    if autoFish then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You will now automatically fish until you move.")
        fishingPlayers[player:getId()] = true
    end
    local pos = player:getPosition()
    addEvent(executeFishing, 0, player:getId(), pos, toPosition)
return true
end


function executeFishing(playerId, pos, toPosition)
    local player = Player(playerId)

    if not player or player:getPosition() ~= pos then
        if fishingPlayers[playerId] then
            fishingPlayers[playerId] = nil
        end
    return true
    end
  
    if useWorms and player:getItemCount(wormItemId) < 1 then
        if fishingPlayers[playerId] then
            fishingPlayers[playerId] = nil
        end
        return player:sendCancelMessage("You have run out of worms.")
    end
 
    for i = 1, #monsters do
        if player:getLevel() >= monsters[i].level and player:getSkillLevel(SKILL_FISHING) >= monsters[i].fishing then
            if math.random(1, baseChance) <= monsters[i].chance then
                Game.createMonster(monsters[i].name, player:getPosition())
                if monsters[i].broadcast then
                    local text = string.gsub(monsters[i].msg, "|PLAYERNAME|", player:getName())
                    Game.broadcastMessage(text)
                end
                break
            end
        end
    end
 
    for i = 1, #items do
        if math.random(1, baseChance) <= items[i].chance then
            if items[i].onGround then
                player:addItem(items[i].itemid, 1, true)
            else
                player:addItem(items[i].itemid, 1, false)
            end
        end
    end
 
    for i = 1, #fish do
        if math.random(1, baseChance) <= fish[i].chance then
            player:addItem(fish[i].itemid, 1, true)
        end
    end
 
    player:addSkillTries(SKILL_FISHING, 1)
    player:removeItem(wormItemId, 1)
    toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
    if fishingPlayers[pid] then
        addEvent(executeFishing, 1000, player:getId(), pos, toPosition)
    end
return true
end
 
If you walk after using fishing rod it will stop auto fishing. Are you sure its not working?
Post automatically merged:

TFS 1.3

Lua:
local waters = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 7236, 10499, 15401, 15402}

local monsterFishing = false
local itemsFishing = false
local catchFish = false
local breakRod = false
local breakRodChance = 10
local useWorms = false
local automaticFishing = false
local wormId = 1111

local chances = {
    monster = 10000000, -- Change this to make it easier/harder to catch all monsters --
    breakRod = 10000, -- Chance to break rod default 10/10000
    item = 100000,
    fish = 100000
}

local monsters = { -- Use |PLAYERNAME| in broadcastMsg to add the players name --
    [1] = {name = "Monster 1", level = 10, fishing = 10, chance = 10000, broadcastMsg = false, storage = 10000}
}

local items = {
    [1] = {itemid = 1111, amount = 5, chance = 1000}
}

local fish = {
    [1] = {itemid = 1111, chance = 1000}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not isInArray(waters, target.itemid) then return false end

    local TILE = Tile(fromPosition())
    local TILE2 = Tile(toPosition())
    
    if TILE and TILE:hasFlag(TILE_STATE_PROTECTIONZONE) then
        return player:sendCancelMessage("You may not fish in protection zones.")
    end
    
    if TILE2 and TILE2:hasFlag(TILE_STATE_PROTECTIONZONE) then
        return player:sendCancelMessage("You may not fish in protection zones.")
    end
    
    if useWorms and player:getItemCount(wormId) < 1 then
        return player:sendCancelMessage("You need worms to fish.")
    end
    
    if automaticFishing then
        player:popupFYI("You are now automatic fishing. You do not need to use your rod.")
    end
    addEvent(autoFish, 0, player:getId(), player:getPosition())
return true
end

function autoFish(pid, pos)
    local player = Player(pid)
    
    if not player then return false end
    
    if player:getPosition() ~= pos then return false end
    
    if not player:removeItem(wormId, 1) then
        return player:sendCancelMessage("You have run out of worms.")
    end
    
    if breakRod and math.random(chances.breakRod) <= breakRodChance then
        item:remove()
        return player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Your fishing rod has broken!")
    end
        
    if itemsFishing then
        for i = 1, #items do
            if math.random(chances.item) <= items[i].chance then
                local ITEM = player:addItem(items[i].itemid, math.random(items[i].amount))
                local IT = ItemType(ITEM)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have found "..ITEM:getCount().." "..IT:getName().." in the water!")
            break
            end
        end
    end
    
    if catchFish then
        for i = 1, #fish do
            if math.random(chances.fish) <= fish[i].chance then
                player:addItem(fish[i].itemid, 1)
                break
            end
        end
    end

    if monsterFishing then
        for i = 1, #monsters do
            if player:getLevel() >= monsters[i].level and player:getSkillLevel(SKILL_FISHING) >= monsters[i].fishing then
                if math.random(chances.monster) <= monsters[i].chance then
                    if player:getStorageValue(monsters[i].storage) == -1 then
                        player:setStorageValue(monsters[i].storage, 1)
                    else
                        player:setStorageValue(monsters[i].storage, player:getStorageValue(monsters[i].storage) + 1)
                    end
                    
                    if monsters[i].broadcastMsg then
                        local newMsg = string.gsub(monsters[i].broadcastMsg, "|PLAYERNAME|", player:getName())
                        Game.broadcastMessage(newMsg)
                    end
                    
                    Game.createMonster(monsters[i].name, player:getPosition())
                    break
                end
            end
        end
    end
    
    player:addSkillTries(SKILL_FISHING, 1)
    toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
    
    if automaticFishing then
        addEvent(autoFish, 1000, pid, pos)
    end
end
 
Last edited:
@Itutorial im testing it now, this is the first issue I foundScreenshot_3.png

edit:
i changed it into this
Screenshot_4.png

but still autofishing is not working.
also toPosition is not defined in autofish function.
and also found an error in getCount method
Screenshot_6.png
 
Last edited:
Oh jesus just change

Code:
local TILE = Tile(fromPosition())
    local TILE2 = Tile(toPosition())

to

Code:
local TILE = Tile(fromPosition)
    local TILE2 = Tile(toPosition)
 
Back
Top