Changing Item Drops
#1
I want to make a plugin that makes gold/iron drop ingots instead of the ore, I adapted the example from the docs but can't seem to get it to work (it crashes cuberite). I'm new to cuberite plugin development (lua in general, actually). I already add the hook HOOK_BLOCK_TO_PICKUPS. Please helpTongue
Reply
Thanks given by:
#2
Of course it would help if you showed your code. Do you just have the example from the docs? Do you have a link to the page showing the example?
Reply
Thanks given by:
#3
A plugin shouldn't be able to crash the server. I'd really appreciate if you could post your code so that we can hunt down the bug you've run into.
Reply
Thanks given by:
#4
I've used other ways of trying but this is the one I could seem to replicate. Doesn't work and seems to crash cuberite Sad

function OnBlockToPickups(a_World, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_Pickups)
if (a_Digger ~= nil) then
return false;
end

if (a_BlockType == E_BLOCK_IRON_ORE) then
return true
end

a_Pickups:Clear();

a_Pickups:Add(cItem(E_ITEM_IRON_INGOT));
return true;
end;
Reply
Thanks given by:
#5
Hey,

I checked your code and corrected it. 
I think you want to run the code only if it's a player
Also corrected the item that you want to have as a new pickup.
Here you can find a list of all values http://api-docs.cuberite.org/Globals.html

function OnBlockToPickups(a_World, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_Pickups)
 -- Check if digger is null or is not a player
 if (a_Digger == nil) or (a_Digger:GetEntityType() ~= cEntity.etPlayer) then
 return false
 end
 
 -- Check if the block is a iron ore
 if (a_BlockType ~= E_BLOCK_IRON_ORE) then
 return true
 end

 -- Clear all defaul pickups
 a_Pickups:Clear();

 -- Add iron ingot
 a_Pickups:Add(cItem(E_ITEM_IRON))
 return true
end


If you mean red lines in the terminal, this can be a error inside of cuberite or something gone wrong in a plugin. If the error is from a plugin it's a stack trace, that contains the plugin name and the line of the error.
In this case I think it was the wrong item type, because it was nil and adding a nil value will cause an error.
Reply
Thanks given by: Epsilith
#6
Omg, thanks. Now I just need to add goldTongue
Problem solvedBig Grin
Reply
Thanks given by:
#7
Epsilith, so was it a crash or just a red error report (and the server continued running)? The red error report is a normal reaction to code errors in plugins.
Reply
Thanks given by:
#8
Oh, I though it actually crashed cuberite... But it might be something else, because it still happens. I can't figure out why it does it, though.
Reply
Thanks given by:




Users browsing this thread: 3 Guest(s)