• 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 Simple fishing monsters TFS 1.x

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,284
Location
Sweden?
Here is a simple fishing up monsters script which you can easily extend on.

Inspiration is from this and works on a similar way:
nLdjYQT.gif


Lua:
local waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4664, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825, 7236, 15401, 15402}
local monsters = {
    {monsterName = "Frog", amount = 2, skillLevel = 5, chance = 20},
    {monsterName = "Crab", amount = 3, skillLevel = 3, chance = 20},
    {monsterName = "Jellyfish", amount = 1, skillLevel = 10, chance = 20}
}

local event = {}

-- We call this function to avoid memory leaks
local function clearCache(id)
    event[id] = nil
end

local function executeFishing(id, oldPosition, toPosition)
    local player = Player(id)
    if not player then
        clearCache(id)
        return
    end
   
    -- If player move from the current position, cancel the fishing
    if oldPosition ~= player:getPosition() then
        clearCache(id)
        return
    end
   
    local random = math.random
    local randTable = monsters[random(#monsters)]
    local fishingSkill = player:getEffectiveSkillLevel(SKILL_FISHING)
   
    if random(100) <= math.min(math.max(10 + (fishingSkill - 10) * 0.597, 10), 50) then
        if fishingSkill >= randTable.skillLevel then
            for i = 1, random(randTable.amount) do
                local monster = Game.createMonster(randTable.monsterName, player:getPosition(), true)
                if monster then
                    doChallengeCreature(player, monster)
                end
               
                toPosition:sendMagicEffect(CONST_ME_WATERSPLASH)
            end
           
            clearCache(id)
            player:addSkillTries(SKILL_FISHING, 1)
            return
        end
    end

    toPosition:sendMagicEffect(CONST_ME_LOSEENERGY, player)
    event[id] = addEvent(executeFishing, 1000, id, oldPosition, toPosition)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not isInArray(waterIds, target.itemid) then
        return false
    end
   
    local playerPosition = player:getPosition()
    if Tile(playerPosition):hasFlag(TILESTATE_PROTECTIONZONE) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot fishing in protection zones.")
        return true
    end
   
    local playerId = player:getId()
    if event[playerId] ~= nil then
        stopEvent(event[playerId])
    end
   
    event[playerId] = executeFishing(playerId, playerPosition, toPosition)
    return true
end

Enjoy
 
Last edited by a moderator:
Can someone tell my why is it not possible to Edit your post? I would like to move line 41, above line 44.
i think is because some users were deleting their releases. But you can write a post and tag a mod and he will update your main post
 
Back
Top