• 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 [0.3.6] Fishing Channel and Script

Samaster

Raptorserver.ddns.net
Joined
Jun 9, 2013
Messages
291
Reaction score
23
Location
UK
Hi, I want my fishing script to Broadcast in my Fishing channel when a player catches a monster

This is my fishing script:
Code:
local config =  { 
    waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625}, 
    rateSkill = 0.25, 
    allowFromPz = false,
    useWorms = false  
} 
local v = { 
    [{200,100}] = {name = "Angry Water Elemental", chance = 262500, storage = 36000}, 
    [{400,100}] = {name = "Ophion Slave", chance = 52500, storage = 36001}, 
    [{600,100}] = {name = "Hydras", chance = 8750, storage = 36002}, 
    [{1000,110}] = {name = "Hydrilica", chance = 4375, storage = 36003}, 
    [{1500,110}] = {name = "Blood Crab", chance = 1225, storage = 36004}, 
    [{2000,115}] = {name = "Mature Blood Crab", chance = 875, storage = 36005}, 
    [{2000,115}] = {name = "Giant Squid", chance = 437.5, storage = 36006}, 
    [{2500,120}] = {name = "Ophion", chance = 35, storage = 36007}, 
    [{3000,130}] = {name = "Megladon", chance = 17.5, storage = 36008}, 
    [{3000,130}] = {name = "Immature Sharkeater", chance = 8.75, storage = 36009}, 
    [{4000,135}] = {name = "The Lurker", chance = 1.75, storage = 36010}, 
    [{5000,140}] = {name = "Aquafilus", chance = 0.175, storage = 360011}, 
    [{6000,145}] = {name = "Sharkeater", chance = 0.00175, storage = 36012}  
} 
         
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if not isInArray(config.waterIds, itemEx.itemid) then
        return false
    end
if getTilePzInfo(getPlayerPosition(cid)) then
     return doPlayerSendCancel(cid, "You can't use this in pz.")
end
 if itemEx.itemid ~= 493 and math.random((100 + (getPlayerSkill(cid, SKILL_FISHING) / 60))) <  getPlayerSkill(cid, SKILL_FISHING) and (not config.useWorms or (getPlayerItemCount(cid, ITEM_WORM) > 0 and  doPlayerRemoveItem(cid, ITEM_WORM, 1))) then
        for i, k in pairs(v) do
            if getPlayerLevel(cid) >= i[1] and getPlayerSkillLevel(cid, SKILL_FISHING) >= i[2] then
                local c = math.random(200000000)
                if c <= k.chance then
                    doSummonCreature(k.name, getThingPos(cid))
                    setPlayerStorageValue(cid, k.storage, getPlayerStorageValue(cid, k.storage) +1)
                    doPlayerSendChannelMessage(cid, getPlayerName(cid), "%s has caught a".. getCreatureName(target) ..", level ".. getPlayerLevel(cid) ..".", TALKTYPE_CHANNEL_W, 12)
                end
            end
            if k.broadcast then
                doBroadcastMessage(bsMessage:format(getCreatureName(cid), k.name))
                break
            end
        end
    end
    if doPlayerAddSkillTry(cid, SKILL_FISHING, 1) then
    return doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
end
end

And when a player catches a monster, I get this error code:
Code:
[25/02/2015 19:23:16] [Error - Action Interface] 
[25/02/2015 19:23:16] data/actions/scripts/tools/upgfishing.lua:onUse
[25/02/2015 19:23:16] Description: 
[25/02/2015 19:23:16] (luaGetCreatureName) Creature not found

[25/02/2015 19:23:16] [Error - Action Interface] 
[25/02/2015 19:23:16] data/actions/scripts/tools/upgfishing.lua:onUse
[25/02/2015 19:23:16] Description: 
[25/02/2015 19:23:16] data/actions/scripts/tools/upgfishing.lua:37: attempt to concatenate a boolean value
[25/02/2015 19:23:17] stack traceback:
[25/02/2015 19:23:17]     data/actions/scripts/tools/upgfishing.lua:37: in function <data/actions/scripts/tools/upgfishing.lua:23>

I don't know what I need to do to change it?
 
Last edited:
updated
Code:
local config =  {
    waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625},
    rateSkill = 0.25,
    allowFromPz = false,
    useWorms = false
}
local t = {
        targetId = 0,
        SpeakClasses = TALKTYPE_CHANNEL_W,
        message = '',
        channel = 12
    }

local v = {
    [{200,100}] = {name = "Angry Water Elemental", chance = 262500, storage = 36000},
    [{400,100}] = {name = "Ophion Slave", chance = 52500, storage = 36001},
    [{600,100}] = {name = "Hydras", chance = 8750, storage = 36002},
    [{1000,110}] = {name = "Hydrilica", chance = 4375, storage = 36003},
    [{1500,110}] = {name = "Blood Crab", chance = 1225, storage = 36004},
    [{2000,115}] = {name = "Mature Blood Crab", chance = 875, storage = 36005},
    [{2000,115}] = {name = "Giant Squid", chance = 437.5, storage = 36006},
    [{2500,120}] = {name = "Ophion", chance = 35, storage = 36007},
    [{3000,130}] = {name = "Megladon", chance = 17.5, storage = 36008},
    [{3000,130}] = {name = "Immature Sharkeater", chance = 8.75, storage = 36009},
    [{4000,135}] = {name = "The Lurker", chance = 1.75, storage = 36010},
    [{5000,140}] = {name = "Aquafilus", chance = 0.175, storage = 360011},
    [{6000,145}] = {name = "Sharkeater", chance = 0.00175, storage = 36012}
}

function reallyLongReturn(cid, config)
    return math.random((100 + (getPlayerSkill(cid, SKILL_FISHING) / 60))) <  getPlayerSkill(cid, SKILL_FISHING) and (not config.useWorms or (getPlayerItemCount(cid, ITEM_WORM) > 0 and  doPlayerRemoveItem(cid, ITEM_WORM, 1)))
end
      
function onUse(cid, item, fromPosition, itemEx, toPosition)
    t.targetId = cid
    if not isInArray(config.waterIds, itemEx.itemid) then
        return false
    end
    if getTilePzInfo(getPlayerPosition(cid)) then
         doPlayerSendCancel(cid, "You can't use this in pz.")
         return false
    end
 
    if itemEx.itemid ~= 493 and reallyLongReturn(cid, config) then
        for i, k in pairs(v) do
            if getPlayerLevel(cid) >= i[1] and getPlayerSkillLevel(cid, SKILL_FISHING) >= i[2] then
                local c = math.random(200000000)
                if c <= k.chance then
                    t.message = getPlayerName(cid).." has caught a ".. k.name ..", level ".. getPlayerLevel(cid) .."."
                    doSummonCreature(k.name, getThingPos(cid))
                    setPlayerStorageValue(cid, k.storage, getPlayerStorageValue(cid, k.storage) +1)
                    doPlayerSendChannelMessage(cid, t.targetId, t.SpeakClasses, t.message, t.channel)
                end
            end
            if k.broadcast then
                doBroadcastMessage(bsMessage:format(getCreatureName(cid), k.name))
                break
            end
        end
    end
    doPlayerAddSkillTry(cid, SKILL_FISHING, 1)
    doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
end
 
Last edited:
Code:
local config =  {
    waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625},
    rateSkill = 0.25,
    allowFromPz = false,
    useWorms = false
}
local t = {
        targetId = 0,
        SpeakClasses = TALKTYPE_CHANNEL_W,
        message = '',
        channel = 12
    }

local v = {
    [{200,100}] = {name = "Angry Water Elemental", chance = 262500, storage = 36000},
    [{400,100}] = {name = "Ophion Slave", chance = 52500, storage = 36001},
    [{600,100}] = {name = "Hydras", chance = 8750, storage = 36002},
    [{1000,110}] = {name = "Hydrilica", chance = 4375, storage = 36003},
    [{1500,110}] = {name = "Blood Crab", chance = 1225, storage = 36004},
    [{2000,115}] = {name = "Mature Blood Crab", chance = 875, storage = 36005},
    [{2000,115}] = {name = "Giant Squid", chance = 437.5, storage = 36006},
    [{2500,120}] = {name = "Ophion", chance = 35, storage = 36007},
    [{3000,130}] = {name = "Megladon", chance = 17.5, storage = 36008},
    [{3000,130}] = {name = "Immature Sharkeater", chance = 8.75, storage = 36009},
    [{4000,135}] = {name = "The Lurker", chance = 1.75, storage = 36010},
    [{5000,140}] = {name = "Aquafilus", chance = 0.175, storage = 360011},
    [{6000,145}] = {name = "Sharkeater", chance = 0.00175, storage = 36012}
}

function reallyLongReturn(cid, config)
    return math.random((100 + (getPlayerSkill(cid, SKILL_FISHING) / 60))) <  getPlayerSkill(cid, SKILL_FISHING) and (not config.useWorms or (getPlayerItemCount(cid, ITEM_WORM) > 0 and  doPlayerRemoveItem(cid, ITEM_WORM, 1)))
end
      
function onUse(cid, item, fromPosition, itemEx, toPosition)
    t.targetId = cid
    if not isInArray(config.waterIds, itemEx.itemid) then
        return false
    end
    if getTilePzInfo(getPlayerPosition(cid)) then
         doPlayerSendCancel(cid, "You can't use this in pz.")
         return false
    end
 
    if itemEx.itemid ~= 493 and reallyLongReturn(cid, config) then
        for i, k in pairs(v) do
            if getPlayerLevel(cid) >= i[1] and getPlayerSkillLevel(cid, SKILL_FISHING) >= i[2] then
                local c = math.random(200000000)
                if c <= k.chance then
                    t.message = getPlayerName(cid).." has caught a ".. getCreatureName(k.name) ..", level ".. getPlayerLevel(cid) .."."
                    doSummonCreature(k.name, getThingPos(cid))
                    setPlayerStorageValue(cid, k.storage, getPlayerStorageValue(cid, k.storage) +1)
                    doPlayerSendChannelMessage(cid, t.targetId, t.SpeakClasses, t.message, t.channel)
                end
            end
            if k.broadcast then
                doBroadcastMessage(bsMessage:format(getCreatureName(cid), k.name))
                break
            end
        end
    end
    doPlayerAddSkillTry(cid, SKILL_FISHING, 1)
    doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
end

I don't catch any monsters now :/
 
I don't catch any monsters now :/
Well what is the error?

Then change this
t.targetId = cid
to this
t.targetId = getPlayerGUID(cid)

Also change this
doPlayerSendChannelMessage(cid, t.targetId, t.SpeakClasses, t.message, t.channel)
to this
doPlayerSendChannelMessage(cid, t.targetId, t.message, t.SpeakClasses, t.channel)

If the script doesn't work, change it back.

Updated
 
Last edited by a moderator:
Then change this
t.targetId = cid
to this
t.targetId = getPlayerGUID(cid)

Also change this
doPlayerSendChannelMessage(cid, t.targetId, t.SpeakClasses, t.message, t.channel)
to this
doPlayerSendChannelMessage(cid, t.targetId, t.message, t.SpeakClasses, t.channel)

If the script doesn't work, change it back, I don't know I never used the chat channels in 8.6 and I am seeing 2 two different implementations

The script works fine on the basis it has no errors on server load or on use; however when I am suppose to catch something, I get this error instead:
Code:
[26/02/2015 07:31:52] [Error - Action Interface]
[26/02/2015 07:31:52] data/actions/scripts/tools/upgfishing.lua:onUse
[26/02/2015 07:31:52] Description:
[26/02/2015 07:31:52] (luaGetCreatureName) Creature not found

[26/02/2015 07:31:52] [Error - Action Interface]
[26/02/2015 07:31:52] data/actions/scripts/tools/upgfishing.lua:onUse
[26/02/2015 07:31:52] Description:
[26/02/2015 07:31:52] data/actions/scripts/tools/upgfishing.lua:49: attempt to concatenate a boolean value
[26/02/2015 07:31:52] stack traceback:
[26/02/2015 07:31:52]     data/actions/scripts/tools/upgfishing.lua:49: in function <data/actions/scripts/tools/upgfishing.lua:34>
 
Last edited:
The script works fine on the basis it has no errors on server load or on use; however when I am suppose to catch something, I get this error instead:
Just change this
Code:
t.message = getPlayerName(cid).." has caught a ".. getCreatureName(k.name) ..", level ".. getPlayerLevel(cid) .."."
to this
Code:
t.message = getPlayerName(cid).." has caught a ".. k.name ..", level ".. getPlayerLevel(cid) .."."
 
Just change this
Code:
t.message = getPlayerName(cid).." has caught a ".. getCreatureName(k.name) ..", level ".. getPlayerLevel(cid) .."."
to this
Code:
t.message = getPlayerName(cid).." has caught a ".. k.name ..", level ".. getPlayerLevel(cid) .."."
Okay now the fishing script works and I catch monsters, but still no message in the Fishing Channel? :/

This is my script now:
Code:
local config =  {
    waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625},
    rateSkill = 0.2,
    allowFromPz = false,
    useWorms = false
}
local t = {
        targetId = 0,
        SpeakClasses = TALKTYPE_CHANNEL_W,
        message = '',
        channel = 12
    }

local v = {
    [{200,100}] = {name = "Angry Water Elemental", chance = 262500, storage = 36000},
    [{400,100}] = {name = "Ophion Slave", chance = 52500, storage = 36001},
    [{600,100}] = {name = "Hydras", chance = 8750, storage = 36002},
    [{1000,110}] = {name = "Hydrilica", chance = 4375, storage = 36003},
    [{1500,110}] = {name = "Blood Crab", chance = 1225, storage = 36004},
    [{2000,115}] = {name = "Mature Blood Crab", chance = 875, storage = 36005},
    [{2000,115}] = {name = "Giant Squid", chance = 437.5, storage = 36006},
    [{2500,120}] = {name = "Ophion", chance = 35, storage = 36007},
    [{3000,130}] = {name = "Megladon", chance = 17.5, storage = 36008},
    [{3000,130}] = {name = "Immature Sharkeater", chance = 8.75, storage = 36009},
    [{4000,135}] = {name = "The Lurker", chance = 1.75, storage = 36010},
    [{5000,140}] = {name = "Aquafilus", chance = 0.175, storage = 360011},
    [{6000,145}] = {name = "Sharkeater", chance = 0.00175, storage = 36012}
}

function reallyLongReturn(cid, config)
    return math.random((100 + (getPlayerSkill(cid, SKILL_FISHING) / 60))) <  getPlayerSkill(cid, SKILL_FISHING) and (not config.useWorms or (getPlayerItemCount(cid, ITEM_WORM) > 0 and  doPlayerRemoveItem(cid, ITEM_WORM, 1)))
end
    
function onUse(cid, item, fromPosition, itemEx, toPosition)
    t.targetId = getPlayerGUID(cid)
    if not isInArray(config.waterIds, itemEx.itemid) then
        return false
    end
    if getTilePzInfo(getPlayerPosition(cid)) then
         doPlayerSendCancel(cid, "You can't use this in pz.")
         return false
    end
    if itemEx.itemid ~= 493 and reallyLongReturn(cid, config) then
        for i, k in pairs(v) do
            if getPlayerLevel(cid) >= i[1] and getPlayerSkillLevel(cid, SKILL_FISHING) >= i[2] then
                local c = math.random(200000000)
                if c <= k.chance then
                    t.message = getPlayerName(cid).." has caught a ".. k.name ..", level ".. getPlayerLevel(cid) .."."
                    doSummonCreature(k.name, getThingPos(cid))
                    setPlayerStorageValue(cid, k.storage, getPlayerStorageValue(cid, k.storage) +1)
                    doPlayerSendChannelMessage(cid, t.targetId, t.message, t.SpeakClasses, t.channel)
                end
            end
            if k.broadcast then
                doBroadcastMessage(bsMessage:format(getCreatureName(cid), k.name))
                break
            end
        end
    end
    doPlayerAddSkillTry(cid, SKILL_FISHING, 1)
    doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
end
 
Last edited:
I tested the script on TFS 0.3.7 and it's sending the messages, can you post your channels.xml?

Also post any error messages that you are getting in the console.

I'm not getting any error reports..
Channels.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<channels>
    <!-- README:
        0 - dynamic, reserved for guilds
        1 - always acts as Party channel, only "name" tag available
        3 - always acts as Rule Violations channel
        9 - acts as Help channel- clientsided message
        65535 - DO NOT CHANGE THE ID- only "name", "enabled", "active" and "logged" tags available
     -->
    <channel id="1" name="Party"/>
    <channel id="2" name="Staff" access="3"/>
    <channel id="3" name="Rule Violations" logged="yes"/>
    <channel id="4" name="Counsellor" access="1"/>
    <channel id="5" name="Game Chat" level="1"/>
    <channel id="6" name="Trade" level="1" muted="120" conditionId="2" conditionMessage="You may only place one offer in two minutes.">
        <vocation id="1-12"/>
    </channel>
    <channel id="7" name="Trade-Rookgaard" level="1" muted="120" conditionId="3" conditionMessage="You may only place one offer in two minutes.">
        <vocation id="0"/>
    </channel>
    <channel id="8" name="RL-Chat" level="1"/>
    <channel id="9" name="Help" logged="yes"/>
    <channel id="10" name="PVP" logged="yes" active="no"/>
    <channel id="11" name="World Chat" level="1"/>
    <channel id="12" name="Fishing" active="no"/>
    <channel id="65535" name="Private Chat Channel"/>
</channels>
 
I tested the script on TFS 0.3.7 and it's sending the messages, can you post your channels.xml?

Also post any error messages that you are getting in the console.

I want it to do a Channel Broadcast so everyone can see it.. Example:
Code:
11:11 "Player Name" "[Player Level]" has caught a "Monster Name"

At the moment, the only person that can see the message is the player who caught it.
Also, it doesn't always work, I realised it was working before, but now when I catch monsters sometimes it doesn't broadcast?
 
Back
Top