Having problems
#1
Why won't this f****** code work? I don't find any problem.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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?
Reply
Thanks given by:
#2
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.
Reply
Thanks given by:
#3
Later I'll upload code to github (when I sit to computer)
Pickups is cItems. Hook is block to pickups. No error on console.
Reply
Thanks given by:
#4
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.
Reply
Thanks given by:
#5
Uploaded file to github: https://github.com/tonibm19/Jobs/blob/master/hooks.lua
Reply
Thanks given by:
#6
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:
1
2
3
if (i2 == nil) then
      return false
end
Reply
Thanks given by:
#7
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.
Reply
Thanks given by:
#8
Where did you print the amount? before
1
2
3
if (i2 == nil) then
      return false
end
or after?
Reply
Thanks given by:
#9
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.
Reply
Thanks given by:




Users browsing this thread: