Set items to chest? - 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: Set items to chest? (/thread-1414.html) |
Set items to chest? - agusnat16 - 03-19-2014 Is there anyway for set random items in the chests on the map, but not use hook OnPlayerUsedBlock, etc? I do not like the way of hunger games plugin. RE: Set items to chest? - xoft - 03-19-2014 Hi, welcome to the forum. cWorld has the DoWithChestAt() function which lets you have any Lua function called with the cChestEntity parameter representing the chest: http://mc-server.xoft.cz/LuaAPI/cWorld.html Then you can simply use the cChestEntity's SetSlot() function to set the slots: http://mc-server.xoft.cz/LuaAPI/cChestEntity.html You'll need to handle the "random" part yourself in the plugin RE: Set items to chest? - agusnat16 - 03-19-2014 Thanks, can you give me an example of how to use them? RE: Set items to chest? - xoft - 03-19-2014 -- ChestX, ChestY and ChestZ are coords of the chest, obtained elsewhere cWorld:DoWithChestAt(ChestX, ChestY, ChestZ, function (a_ChestEntity) a_ChestEntity:SetSlot(0, 0, cItem(E_BLOCK_GOLD_BLOCK)) -- gold block to upper left slot a_ChestEntity:SetSlot(1, 0, cItem(E_ITEM_DIAMOND_SWORD, 500)) -- half-broken diamond sword to slot [1, 0] a_ChestEntity:SetSlot(3, cItem(E_ITEM_BOW)) -- regular bow to slot #3 ([3, 0], fourth slot) a_ChestEntity:SetSlot(math.random(27), cItem(256 + math.random(50))) -- completely random item to a random slot end ) RE: Set items to chest? - agusnat16 - 03-19-2014 I make the function and obtain the position of .ini for set the items, but this returns the position (in the LOG) and the server crashes... why? RE: Set items to chest? - xoft - 03-20-2014 Hmm, I wrote the code wrong, the red "cWorld" in the second line should be "World" instead, a variable that holds a cWorld instance. I wrote that off the top of my head with no checks whatsoever, so it might need further tweaking. RE: Set items to chest? - agusnat16 - 03-20-2014 Yes, it was the "World" now works, thanks again! EDIT (Last question): There any way that the coordinates do not appear in the log? RE: Set items to chest? - xoft - 03-20-2014 I'm afraid you'll have to be more specific. What coordinates, how in log? RE: Set items to chest? - agusnat16 - 03-20-2014 When executing the function appears in the log "[00:55:26] x 345 y 64 z 274" for each chest... RE: Set items to chest? - xoft - 03-20-2014 I don't think that is a message from the MCS; rather, it's from the plugin itself. |