Whack-a-mole Mallet
Bury Enemies into the ground
← Back to main
Code Block:
api.giveItem(myId, "Stone Spade", 1, {
customDisplayName: "Whack-a-Mole Mallet"
});
World Code:
function isMidAir(playerId) {
const blockTypes = api.getBlockTypesPlayerStandingOn(playerId);
return blockTypes.every(type => type === "Air");
}
// Handle attack logic
onPlayerDamagingOtherPlayer = function(attackerId, victimId, damage, withItem, bodyPartHit, damagerDbId) {
const held = api.getHeldItem(attackerId);
if (!held || held.name !== "Stone Spade" || held.attributes?.customDisplayName !== "Whack-a-Mole Mallet") {
return;
}
if (isMidAir(attackerId)) {
const victimPos = api.getPosition(victimId);
if (!victimPos) return;
const [x, y, z] = victimPos;
const newY = Math.max(y - 3, -99); // Prevents teleporting below y=-100
api.setPosition(victimId, x, newY, z);
api.applyHealthChange(victimId, -Math.round(damage * 0.5)) //change the multiplier to increase the damage
}
};
onPlayerSelectInventorySlotMallet = function(playerId, slotIdx) {
const item = api.getItemSlot(playerId, slotIdx);
if (item && item.name === "Stone Spade" && item.attributes?.customDisplayName === "Whack-a-Mole Mallet") {
api.applyEffect(playerId, "Jump Boost", null, {
inbuiltLevel: 1,
});
} else {
// Optional: Remove effect if player stops holding it
api.removeEffect(playerId, "Jump Boost");
}
};