Set items to chest?
#1
Information 
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.
Reply
Thanks given by:
#2
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
Reply
Thanks given by:
#3
Thanks, can you give me an example of how to use them?
Reply
Thanks given by:
#4
-- 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
)
Reply
Thanks given by:
#5
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?
Reply
Thanks given by:
#6
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.
Reply
Thanks given by:
#7
Yes, it was the "World" now works, thanks again! Smile
EDIT (Last question): There any way that the coordinates do not appear in the log?
Reply
Thanks given by:
#8
I'm afraid you'll have to be more specific. What coordinates, how in log?
Reply
Thanks given by:
#9
When executing the function appears in the log "[00:55:26] x 345 y 64 z 274" for each chest...
Reply
Thanks given by:
#10
I don't think that is a message from the MCS; rather, it's from the plugin itself.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)