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

Lua Fishing dont work? Why?

gmstrikker

Well-Known Member
Joined
Jul 30, 2014
Messages
458
Solutions
1
Reaction score
50
It's cod is from Itutorial, he say my code is so bad, and make it, but this code dont work, dont give me erros, dont give effect on water on use, dont do nothing!!!
Why?
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 = {
  {1, 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)
  if isInArray(fishable, itemEx.itemid) then
  if (not getPlayerItemCount(cid, VIP_WORM) > 0 or (not doPlayerRemoveItem(cid, ITEM_WORM, 1))) then
  doPlayerSendCancel(cid, "You must have worms to fish.")
  return false
  end
   
  fishingSkill = getPlayerSkillLevel(cid, SKILL_FISH)
  if math.random(1, 100) <= chance then
  for i = 1, #skillLevels do
  if fishingSkill >= skillLevels[i][1] and fishingSkill < skillLevels[i][2] then
  ITEM = items[math.random(1, i)]
  end
  end
  end
   
  if (not ITEM) then
  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
 
Run this and take a screen shot of your console or copy and paste what is displayed on screen
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")
            if (not getPlayerItemCount(cid, VIP_WORM) > 0 or (not doPlayerRemoveItem(cid, ITEM_WORM, 1))) then
            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
 
Run this and take a screen shot of your console or copy and paste what is displayed on screen
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")
            if (not getPlayerItemCount(cid, VIP_WORM) > 0 or (not doPlayerRemoveItem(cid, ITEM_WORM, 1))) then
            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

eiN9rG6.png
 
replace this line of code
Code:
if (not getPlayerItemCount(cid, VIP_WORM) > 0 or (not doPlayerRemoveItem(cid, ITEM_WORM, 1))) then

with this and show us the results
Code:
if getPlayerItemCount(cid, VIP_WORM) or doPlayerRemoveItem(cid, ITEM_WORM, 1) then

When we write scripts and have to debug them, we place print statements pretty much anywhere a value can change so that we see the execution process.
Try this
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 ? true : false
                local hasWorms = getPlayerItemCount(cid, ITEM_WORM) >= 1 ? true : false
                if  (hasVipItem or hasWorms) then
                    print("you have the required item to fish")
                    if(hasWorms)
                        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
 
Last edited by a moderator:
When we write scripts and have to debug them, we place print statements pretty much anywhere a value can change so that we see the execution process.
Try this
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 ? true : false
                local hasWorms = getPlayerItemCount(cid, ITEM_WORM) >= 1 ? true : false
                if  (hasVipItem or hasWorms) then
                    print("you have the required item to fish")
                    if(hasWorms)
                        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

I really need study english, ty to u help bro

on start

I really need study english, ty to u help bro

on start

Lol IMG dont load, error on start:
Code:
[Error - LuaInterface::loadFile] data/actions/scripts/tools/fishing.lua:29: unexpected symbol near '?'
[Warning - Event::loadScript] Cannot load script <data/actions/scripts/tools/fishing>
data/actions/scripts/tools/fishing:29: unexpected symbol near '?'

BUMP
 
Last edited by a moderator:
Sorry I got confused with the short hand.. o well
Code:
local hasVipItem = getPlayerItemCount(cid, VIP_WORM) >= 1 ? true : false
local hasWorms = getPlayerItemCount(cid, ITEM_WORM) >= 1 ? true : false

it should be this
Code:
local hasVipItem = getPlayerItemCount(cid, VIP_WORM) >= 1 and true or false
local hasWorms = getPlayerItemCount(cid, ITEM_WORM) >= 1 and true or false
 
Sorry I got confused with the short hand.. o well
Code:
local hasVipItem = getPlayerItemCount(cid, VIP_WORM) >= 1 ? true : false
local hasWorms = getPlayerItemCount(cid, ITEM_WORM) >= 1 ? true : false

it should be this
Code:
local hasVipItem = getPlayerItemCount(cid, VIP_WORM) >= 1 and true or false
local hasWorms = getPlayerItemCount(cid, ITEM_WORM) >= 1 and true or false

MvgfOVZ.png
 
lol replace this
Code:
if(hasWorms)

with this
Code:
if(hasWorms) then
mybad I'm just waking up :p

my char have skill 25 fishing

Dont come fishs, dont effect on water...

But now remove worms

log:
Code:
4609
4617
fishing rod wors
you have the required item to fish
and they are regular worms
fishing skill 14
no item
4617
fishing rod works
you have required item to fish
and they are regular worms
fishing skill 14
no item
4609
4665
fishing rod works
you have required item to fish
and they are regular worms
fishing skill 14
no item
4608
4609
4609
4613
4609
4611
 
log:
Code:
4609
4617
fishing rod wors
you have the required item to fish
and they are regular worms
fishing skill 14
no item
4617
fishing rod works
you have required item to fish
and they are regular worms
fishing skill 14
no item
4609
4665
fishing rod works
you have required item to fish
and they are regular worms
fishing skill 14
no item
4608
4609
4609
4613
4609
4611

script
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
 
Back
Top