Having problems - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: Having problems (/thread-1292.html) |
Having problems - tonibm19 - 12-31-2013 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 endWheat code works but potato and carrot code not, why? RE: Having problems - NiLSPACE - 12-31-2013 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. RE: Having problems - tonibm19 - 12-31-2013 Later I'll upload code to github (when I sit to computer) Pickups is cItems. Hook is block to pickups. No error on console. RE: Having problems - xoft - 12-31-2013 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. RE: Having problems - tonibm19 - 12-31-2013 Uploaded file to github: https://github.com/tonibm19/Jobs/blob/master/hooks.lua RE: Having problems - NiLSPACE - 12-31-2013 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 RE: Having problems - tonibm19 - 12-31-2013 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. RE: Having problems - NiLSPACE - 12-31-2013 Where did you print the amount? before if (i2 == nil) then return false endor after? RE: Having problems - tonibm19 - 12-31-2013 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. |