filler

Lance

Dash through the air when right clicking

← Back to main

Code Block:


api.giveItem(myId, "Diamond Sword", 1, {
  customDisplayName: "Lance"
});
      

World Code:


const lanceCooldowns = {} // Track cooldown per player

onPlayerAltAction = (playerId, x, y, z, block, targetEId) => {
  const heldItem = api.getHeldItem(playerId)

  if (heldItem && heldItem.name == "Diamond Sword" && heldItem.attributes.customDisplayName == "Lance") {
    const now = Date.now()
    const lastUse = lanceCooldowns[playerId] || 0
    const cooldownDuration = 10000 // 10 seconds

    if (now - lastUse >= cooldownDuration) {
      // :white_check_mark: Not cooling down → activate dash
      const facingInfo = api.getPlayerFacingInfo(playerId)
      const dir = facingInfo.dir // [x, y, z]

      const dashStrength = 40
      const dashX = dir[0] * dashStrength
      const dashY = dir[1] * (dashStrength / 2) // Small vertical dash
      const dashZ = dir[2] * dashStrength

      api.setVelocity(playerId, dashX, dashY, dashZ)

      api.sendMessage(playerId, "You dashed forward!", { color: "aqua" })

      // Save time of dash
      lanceCooldowns[playerId] = now

    } else {
      // :red_circle: Still cooling down → show time left
      const timeLeftMs = cooldownDuration - (now - lastUse)
      const secondsLeft = Math.ceil(timeLeftMs / 1000)

      api.sendMessage(playerId, `Lance ready in ${secondsLeft} seconds!`, { color: "red" })
    }
  }
}