filler

Water Club

Gain a shield everytime you attack (Right click to trigger)

← Back to main

Code Block:


api.giveItem(myId, "Diamond Axe", 1,{customDisplayName: "Water Club", customDescription: "Every hit gives a 10HP shield, right click to trigger"});

const waterClubActive = {};     // Tracks active window end time per player
const waterClubCooldown = {};   // Tracks last use time

function onPlayerAltActionWater(playerId) {
  const held = api.getHeldItem(playerId);
  if (!held || held.name !== "Diamond Axe" || held.attributes?.customDisplayName !== "Water Club") return;

  const now = Date.now();
  const lastUsed = waterClubCooldown[playerId] || 0;
  const cooldown = 30000; // 30s cooldown

  if (now - lastUsed < cooldown) {
    const secondsLeft = Math.ceil((cooldown - (now - lastUsed)) / 1000);
    api.sendMessage(playerId, `🕒 Water Club ready in ${secondsLeft}s`, { color: "gray" });
    return;
  }

  // Activate shield-boosting window
  waterClubActive[playerId] = now + 10000; // 10s effect window
  waterClubCooldown[playerId] = now;

  api.sendMessage(playerId, "💧 Water Club activated! +10 Shield on hits for 10s", { color: "aqua" });

  // Send expiry message after 10s
  setTimeOut(() => {
    if (Date.now() >= (waterClubActive[playerId] || 0)) {
      api.sendMessage(playerId, "❌ Water Club effect has worn off.", { color: "red" });
      delete waterClubActive[playerId];
    }
  }, 10000);
};

function onPlayerDamagingOtherPlayerWater(attackerId, victimId, baseDamage, withItem, bodyPartHit, damagerDbId) {
  if (
    !withItem ||
    withItem !== "Diamond Axe" ||
    api.getHeldItem(attackerId)?.attributes?.customDisplayName !== "Water Club"
  ) {
    return;
  }
  api.applyHealthChange(victimId, -Math.round(baseDamage/2))



  const now = Date.now();
  if (now <= (waterClubActive[attackerId] || 0)) {
    const currentShield = api.getShieldAmount(attackerId) || 0;
    const newShield = Math.min(currentShield + 10, 100); // cap at 100
    api.setShieldAmount(attackerId, newShield);
  }
};
      

World Code:


//Timeout Code by Sulfrox
let ordinary_tick_function,do_next_tick_queue=new Set,timed_functions_queue=[];function tick(t){if("function"==typeof ordinary_tick_function&&ordinary_tick_function(t),do_next_tick_queue.forEach((t=>{"function"==typeof t&&t(),do_next_tick_queue.delete(t)})),timed_functions_queue.length&&timed_functions_queue[0][0]{"function"==typeof t&&do_next_tick_queue.add(t)},setTimeOut=(t,e)=>{let n=Date.now()+e;"function"==typeof t&&(timed_functions_queue.push([n,t]),timed_functions_queue.sort((([t],[e])=>t-e)))};


// Handle attack logic
onPlayerDamagingOtherPlayer = function(attackerId, victimId, baseDamage, withItem, bodyPartHit, damagerDbId) {
  const held = api.getHeldItem(attackerId);
  if (held && held.name === "Diamond Axe" && held.attributes?.customDisplayName === "Water Club") {
    onPlayerDamagingOtherPlayerWater(attackerId, victimId, baseDamage, withItem, bodyPartHit, damagerDbId)
  }
}

onPlayerAltAction = function(playerId) {
  const held = api.getHeldItem(playerId)
  if (held && held.name === "Diamond Axe" && held.attributes?.customDisplayName === "Water Club") {
    onPlayerAltActionWater(playerId)
  }
}