So, you want to make, when you hit an enemy with custom item/sword it will take custom damage?
If yes, this should be helpful:
//setting custom item
// 400 is the ID
// "stick" is the texture
// 0 is the number of colours like wool etc. so if 0 it will be only one
// "Powerful Sword" is the name in the game
ModPE.setItem(400, "stick", 0, "Powerful Sword");
//when you attack something
function attackHook(attacker,victim){
var hp_check = Entity.getHealth(victim); //setting vaule to mob health
//you can remove this
clientMessage("Before: " + hp_check+"hp");
//you can remove this
//when you hold your custom item and attack
if(getCarriedItem() == 400 && Entity.getHealth(victim) > 1){
Entity.setHealth(victim, Entity.getHealth(victim) - 4);
//set health to victim = get health vaule of victim - 4
//so the sword will take 5dmg, because every item do 1dmg
}
//you can remove this
clientMessage("After: " + (hp_check-1) + "hp");
//you can remove this
}
Didn't tested, but should work. (:
Thanks! And how would you make that custom sword run out?
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Can it also drop a item? Thanks
Thanks! And how would you make that custom sword run out?