Cuberite Forum

Full Version: Having problems
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Why won't this f****** code work? I don't find any problem.
        if (job == "farmer") then
            if (BlockType == E_BLOCK_CROPS) then
                i1 = Pickups:Get(0)
                i2 = Pickups:Get(1)
                item1 = i1.m_ItemType
                item2 = i2.m_ItemType
                amount1 = i1.m_ItemCount
                if (i2 == nil) then
                    return false
                end
                if (item1 == E_ITEM_WHEAT) or (item2 == E_ITEM_WHEAT) then
                    Coiny:Call("GiveMoney", PlayerDigger:GetName(), 10)
                    return false   
                elseif (item1 == E_ITEM_POTATO) or (item1 == E_ITEM_CARROT) then
                    if (amount1 > 1) then
                        result = amount1 * 5
                        Coiny:Call("GiveMoney", PlayerDigger:GetName(), result)
                        return false       
                    end     
                end
            end
        end
Wheat code works but potato and carrot code not, why?
We need a little more info (errors, Hook), but I'm assuming this is in the HOOK_BLOCK_TO_PICKUPS hook? If "Pickups" is an cPickup then: There is no "Get" function.
Later I'll upload code to github (when I sit to computer)
Pickups is cItems. Hook is block to pickups. No error on console.
How doesn't it work, is there an error message when the plugin loads, when this code executes, or no error message but no visible result?

I'm guessing Pickups is the cItems variable received in the OnPlayerBrokenBlock() hook, you really should check its size before querying items using the Get() function - if there's only one kind of pickup, the code will fail on the "item2 = i2.m_ItemType" line, because i2 is nil. And if there's no pickup at all, it will fail one line above that.
First of all I recommend reading the IniFile only on startup, Secondly have you tried to see how big the item count is? A simple print(amount1) before "if (amount1 > 1) then" should be enough. If that doesn't work then I have the feeling it goes wrong here:
if (i2 == nil) then
      return false
end
I noticed wheat is always first item, so no more problems about i2. The problem it's still there. I tried printing amount but it only prints amount when breaking wheat, so strange.
I updated the github file.
Where did you print the amount? before
if (i2 == nil) then
      return false
end
or after?
I found the problem! It seems carrots are not considered as crops.
Carrots and potatoes are E_BLOCK_CARROTS and E_BLOCK_POTATOES. I thought they were the same with different metas.