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

7.6 fishing, how to make worms work?

Viduy

Member
Joined
Oct 5, 2011
Messages
25
Reaction score
14
Hey Guys!

I've tried for hours and hours to figure out how to add worms into fishing script. I've managed to get the worms used but if they were not in a bag/backpack, fishing rod was working either way. That's what I've got at the moment
Code:
   function onUse(cid, item, frompos, item2, topos)
         -- itemid means that is a creature
        if item2.itemid == 4608 then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
      else
    return 0
   end
   return 1
   end
ID of worm: 3976
 
I found this one on old YurOTS which I have and I added
Lua:
doPlayerRemoveItem(cid, 3976, 1)
Try it
Lua:
-- example of fishing script--
  
   function onUse(cid, item, frompos, item2, topos)
         -- itemid means that is a creature
        if item2.itemid == 490 and doPlayerRemoveItem(cid, 3976, 1) then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 491 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 492 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 618 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 619 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 620 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 622 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 623 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 624 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 625 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 626 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 627 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 628 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
  
        elseif item2.itemid == 629 and doPlayerRemoveItem(cid, 3976, 1)  then
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
          end
             doPlayerAddSkillTry(cid,6,1)
      else
    return 0
   end
   return 1
   end
 
doPlayerRemoveItem(cid, 3976, 1)

Just added that line, it does remove the worm but the rod works even if you don't have the worms!

I'm not excellent at coding! I just kind of figure it out by looking at other codes and taking bits and bobs from different ones and putting them together which normally works for me!

I feel like the worm itself needs a function similar to this but then I had some errors
Code:
if item.type > 1 then doChangeTypeItem(item.uid,item.type-1)
else
doRemoveItem(item.uid,1)

but not sure how to add the function that rod would not simply work if there's no worms :D

also I'll add
Code:
 doPlayerSendCancel(cid,"You need worms to be able to fish.")
 
Try this one
Lua:
doPlayerRemoveItem(cid,3976,1) == TRUE

Sadly I don't think I have that function compiled yet. I'm slowly working on it.
I've tried doing this
Code:
-- example of fishing script--
 
   function onUse(cid, item, frompos, item2, topos)
         -- itemid means that is a creature

              if item2.itemid == 4608
    and
        itemstatus = doPlayerRemoveItem(cid, 3976, 1)
        if itemstatus > 0 then
          doPlayerSendCancel(cid,"You need worms to be able to fish.")
    else
                 skill_level = getPlayerSkill(cid,6)
                 random_number = math.random(1,(100+skill_level/10))
                 doSendMagicEffect(topos,1)
                 if random_number<=skill_level then
                 doPlayerAddItem(cid,2667,1)
    end
             doPlayerAddSkillTry(cid,6,1)

but I get error saying

Code:
fishing.lua:7: 'then' expected near '='
 
Would it be possible to try this script? Please note, you can "fish" (as in, make a water make a little circle) but you will not gain skills nor catch any fish unless you actually have worms in your backpack. You could modify this script to give a "no skill or fish without worms!" if that is a key feature.

Lua:
local FISH_WATER = {4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616}
local NOFISH_WATER = {493, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4820, 4821, 4822, 4823, 4824, 4825}
local ITEM_WORM = 3976
local ITEM_FISH = 2667
local ITEM_FISHING_ROD = 2580

function onUse(cid, item, fromPosition, itemEx, toPosition)

    if(toPosition.x == CONTAINER_POSITION) then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
        return true
    end
    
    if (isInArray(NOFISH_WATER, itemEx.itemid) ) then
        doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
        return true
    end

    local formula = (getPlayerSkill(cid, CONST_SKILL_FISHING) / 200) + (0.85 * math.random())
    local canGainSkill = not(getTilePzInfo(getThingPos(cid)) or (getPlayerItemCount(cid, ITEM_WORM) < 1 and item.itemid == ITEM_FISHING_ROD))

    -- First verify the most common case
    if (isInArray(FISH_WATER, itemEx.itemid) ) then
        -- The water has a fish. Verify if the player can gain skills
        if(canGainSkill) then
            if(formula > 0.7) then
                doPlayerAddItem(cid, ITEM_FISH)
                doPlayerAddSkillTry(cid, CONST_SKILL_FISHING, 1)
                doTransformItem(itemEx.uid, itemEx.itemid + 9)
                doPlayerRemoveItem(cid, ITEM_WORM, 1)
            end
            doPlayerAddSkillTry(cid, CONST_SKILL_FISHING, 1)
        end
        doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
        else
    
            return false
        
    end

    doDecayItem(itemEx.uid)

    return true
end
 
Would it be possible to try this script? Please note, you can "fish" (as in, make a water make a little circle) but you will not gain skills nor catch any fish unless you actually have worms in your backpack. You could modify this script to give a "no skill or fish without worms!" if that is a key feature.

Lua:
local FISH_WATER = {4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616}
local NOFISH_WATER = {493, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4820, 4821, 4822, 4823, 4824, 4825}
local ITEM_WORM = 3976
local ITEM_FISH = 2667
local ITEM_FISHING_ROD = 2580

function onUse(cid, item, fromPosition, itemEx, toPosition)

    if(toPosition.x == CONTAINER_POSITION) then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
        return true
    end
   
    if (isInArray(NOFISH_WATER, itemEx.itemid) ) then
        doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
        return true
    end

    local formula = (getPlayerSkill(cid, CONST_SKILL_FISHING) / 200) + (0.85 * math.random())
    local canGainSkill = not(getTilePzInfo(getThingPos(cid)) or (getPlayerItemCount(cid, ITEM_WORM) < 1 and item.itemid == ITEM_FISHING_ROD))

    -- First verify the most common case
    if (isInArray(FISH_WATER, itemEx.itemid) ) then
        -- The water has a fish. Verify if the player can gain skills
        if(canGainSkill) then
            if(formula > 0.7) then
                doPlayerAddItem(cid, ITEM_FISH)
                doPlayerAddSkillTry(cid, CONST_SKILL_FISHING, 1)
                doTransformItem(itemEx.uid, itemEx.itemid + 9)
                doPlayerRemoveItem(cid, ITEM_WORM, 1)
            end
            doPlayerAddSkillTry(cid, CONST_SKILL_FISHING, 1)
        end
        doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
        else
   
            return false
       
    end

    doDecayItem(itemEx.uid)

    return true
end

Nope. Didn't give me any errors in the console, but in the game it says that 'You cannot use this object'. It's too complicated script for the engine :D, I'll be looking into C++ later on. at the moment I can't compile the server, so playing with xml at the moment :D
 
Oh, sorry to hear it. Just to double check, did you make sure that the local fish water tiles (4608,4609, etc) are matching the item id correctly in your server? The "You cannot use this object" is what message you get if you try to use the fishing rod on land, so perhaps it is almost there?
 
Thank you all so much for your help but it didn't work for me I'm afraid, I've tried different functions but didn't manage to get it work... so I've changed the idea of fishing rod disappearing after certain try, I'll add some more random items and maybe monster summoning to it too! But the code I've finished with looks like that:
Code:
-- Fishing by Viduy v7.6--
  
   function onUse(cid, item, frompos, item2, topos)
         -- itemid means that is a creature

         if (item2.itemid >= 490 and item2.itemid <= 492) or
        (item2.itemid >= 618 and item2.itemid <= 629) or
        (item2.itemid >= 4820 and item2.itemid <= 4825) or
        (item2.itemid >= 4608 and item2.itemid <= 4666)
then
                 skill_level = getPlayerSkill(cid,6)
                 rand = math.random(1,3000)
                 doSendMagicEffect(topos,1)

if rand >= 50 and rand <100 then
    doRemoveItem(item.uid,1)
  doSendMagicEffect(topos,2)
doPlayerSendTextMessage(cid,22,"You lost your rod in the water...")

elseif rand >100 and rand <300 then
doPlayerAddHealth(cid,-100)
doPlayerSendTextMessage(cid,22,"You hurt yourself with a hook.")

elseif rand >300 and rand <800 then
doPlayerAddItem(cid,2667,1)
doPlayerSay(cid,"Whoa! a Fish!",16)

elseif rand >800 and rand <1300 then
doPlayerAddItem(cid,2669,1)
doPlayerSay(cid,"Whoa! a Big Fish!",16)

elseif rand >1300 and rand <1700 then
doPlayerAddItem(cid,2670,1)
doPlayerSay(cid,"Whoa! a Shrimp!",16)

elseif rand >1700 and rand <1800 then
doPlayerAddItem(cid,2226,1)
doPlayerSay(cid,"Yuck! a Fishbone!",16)

elseif rand == 2999 then
doPlayerSendTextMessage(cid,22,"You are lucky! 1 Milion Experience Points!")
doPlayerAddExp(cid, 1000000)



          end
             doPlayerAddSkillTry(cid,6,1)
      else
    return 0
   end
   return 1
   end
 
Back
Top