This site works best with JavaScript enabled. Please enable JavaScript to get the best experience from this site.
This Tutorial shows you how you can add Damage to your Items with ModPE:
There are two ways:
1. Way:
Create a tool item (an item with the category tool).
Now use
Item.setMaxDamage(Id, maxDamage);
and ready!
2. Way:
This way gives you more control over the situations it should get Damage.
First you have to define the item.
Tip: The Item shouldn´t be stackable.
And then you use one (or more) of these hooks:
with attackHook(), useful for swords etc:
function attackHook(a, v){ if(a==getPlayerEnt()){ if(Player.getCarriedItem()==theId){ if(Player.getCarriedItemData()==theMaxDamage){ Player.clearInventorySlot(Player.getSelectedSlotId()); Level.playSound(Player.getX(), Player.getY(), Player.getZ(), "random.break", 1.0, 25.0); }else{ Entity.setCarriedItem(getPlayerEnt(), Player.getCarriedItem(), Player.getCarrriedItemCount(), Player.getCarriedItemData()+1); } } } }
with destroyBlock(), useful for pickaxes, axes, etc:
function destroyBlock(x, y, z, side){ if(Player.getCarriedItem()==theId){ if(Player.getCarriedItemData()==theMaxDamage){ Player.clearInventorySlot(Player.getSelectedSlotId()); Level.playSound(Player.getX(), Player.getY(), Player.getZ(), "random.break", 1.0, 25.0); }else{ Entity.setCarriedItem(getPlayerEnt(), Player.getCarriedItem(), Player.getCarrriedItemCount(), Player.getCarriedItemData()+1); } } }
with useItem(), useful for... I don´t know:
function useItem(x, y, z, itemId, blockId, side, itemDamage, blockDamage){ if(Player.getCarriedItem()==itemId){ if(Player.getCarriedItem()==theId){ if(Player.getCarriedItemData()==theMaxDamage){ Player.clearInventorySlot(Player.getSelectedSlotId()); Level.playSound(Player.getX(), Player.getY(), Player.getZ(), "random.break", 1.0, 25.0); }else{ Entity.setCarriedItem(getPlayerEnt(), Player.getCarriedItem(), Player.getCarrriedItemCount(), Player.getCarriedItemData()+1); } } } }
don´t forget to replace all theId with your Id and all theMaxDamage with the maximal damage the item can have (the times it can be used).
Quote from WorldWideFunGameing» how to set a tool item?
how to set a tool item?
Item.setCategory(Id, category, unknown);
for example:
Item.setCategory(400, 2);
2=Tool
Can i have a example?
This Tutorial shows you how you can add Damage to your Items with ModPE:
There are two ways:
1. Way:
Create a tool item (an item with the category tool).
Now use
Item.setMaxDamage(Id, maxDamage);
and ready!
2. Way:
This way gives you more control over the situations it should get Damage.
First you have to define the item.
Tip: The Item shouldn´t be stackable.
And then you use one (or more) of these hooks:
don´t forget to replace all theId with your Id and all theMaxDamage with the maximal damage the item can have (the times it can be used).
Item.setCategory(Id, category, unknown);
for example:
Item.setCategory(400, 2);
2=Tool
Can i have a example?