#How to implement when play attack with some weapon then shoot a projectile
5 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
I don't find a method to get attack cooldown but you can get player's attack speed and do some math to check if the cool down is over.
const MapPlayerLeftClickLastTime = {}
const rechargeTimeRatio = 1 //set this to 0.5, and you can fire again when the attack cool down is 50%.
ItemEvents.firstLeftClicked("iron_axe" ,event=>{
const tickPerSecond = 20
const {player, player:{uuid}, server:{tickCount}} = event
const playerHashcode = uuid.hashCode()
const lastLeftClickTime = MapPlayerLeftClickLastTime[playerHashcode] ?? 0
const timeDifference = tickCount - lastLeftClickTime
MapPlayerLeftClickLastTime[playerHashcode] = tickCount
const playerAttackSpeed = player.getAttributeValue("minecraft:generic.attack_speed")
if(playerAttackSpeed * timeDifference >= tickPerSecond * rechargeTimeRatio){
player.tell("FIRE")
player.damageHeldItem("main_hand")
}
})