King's Blade
Right click to gain potion effects
← Back to main
Code Block:
api.giveItem(myId, "Gold Sword", 1, {
customDisplayName: "King's Blade"
});
World Code:
const kingBladeCooldowns = {} // Track cooldowns for each player
onPlayerAltAction = (playerId, x, y, z, block, targetEId) => {
const heldItem = api.getHeldItem(playerId)
if (heldItem && heldItem.name == "Gold Sword" && heldItem.attributes.customDisplayName == "King's Blade") {
const now = Date.now()
const lastUse = kingBladeCooldowns[playerId] || 0
const cooldownDuration = 30000 // 30 seconds cooldown
if (now - lastUse >= cooldownDuration) {
// Not cooling down → Activate the King's Power
api.applyEffect(playerId, "Speed", 20000, { inbuiltLevel: 2 })
api.applyEffect(playerId, "Damage", 20000, { inbuiltLevel: 3 })
api.applyEffect(playerId, "Invisible", 5000, { inbuiltLevel: 1 })
api.sendMessage(playerId, "You activated King's Power!", { color: "gold" })
// Save the current time as the last use
kingBladeCooldowns[playerId] = now
} else {
// Still on cooldown → tell the player how much time is left
const timeLeftMs = cooldownDuration - (now - lastUse)
const secondsLeft = Math.ceil(timeLeftMs / 1000)
api.sendMessage(playerId, `King's Power ready in ${secondsLeft} seconds!`, { color: "red" })
}
}
}