let playerKillsByDbId = {};
/* Configuration: Change this number to give more or less Gold per kill */ //
const GOLD_PER_KILL = 5;
/* Helper function to determine rank and text color based on kills */
function getPlayerRankInfo(kills) {
if (kills >=250) return {name: "REAPER", color: "Black" };
if (kills >= 100) return { name: "MASTER", color: "White" };
if (kills >= 50) return { name: "LEGEND", color: "Blue" };
if (kills >= 25) return { name: "KILLER", color: "Red" };
if (kills >= 10) return { name: "WARRIOR", color: "Orange" };
return { name: "ROOKIE", color: "LightGray" };
}
/* Updates the visual subtitle under the player's name tag */
function updateNameTag(pId) {
const dbId = api.getPlayerDbId(pId);
if (!dbId) return;
const kills = playerKillsByDbId[dbId] || 0;
const rankInfo = getPlayerRankInfo(kills);
api.setTargetedPlayerSettingForEveryone(pId, 'nameTagInfo', {
subtitle: [
{ str: `[${rankInfo.name}] `, style: { color: rankInfo.color } },
{ str: `Kills: ${kills}`, style: { color: 'White' } }
],
subtitleBackgroundColor: 'Black'
}, true);
}
/* Event: Runs when a player joins and fetches permanent saved data */
onPlayerJoin = (playerId) => {
const dbId = api.getPlayerDbId(playerId);
if (!dbId) return;
// Use the temporary playerId to request data from the game's storage server
let savedData = api.getMoonstoneChestItemSlot(playerId, 99);
if (savedData && savedData.count) {
// Map the permanent dbId directly to the loaded count so it survives a tab clear
playerKillsByDbId[dbId] = savedData.count;
} else {
// Only reset to 0 if they have absolutely no save history recorded
if (playerKillsByDbId[dbId] === undefined) {
playerKillsByDbId[dbId] = 0;
}
}
updateNameTag(playerId);
};
/* Event: Runs when a player secures a kill, updates database saves, and awards Gold */
onPlayerKilledOtherPlayer = (killerId, deadId, damage, item) => {
if (killerId != null && killerId !== deadId) {
const killerDbId = api.getPlayerDbId(killerId);
if (!killerDbId) return;
// 1. Permanently update the score counter assigned to their real account profile
playerKillsByDbId[killerDbId] = (playerKillsByDbId[killerDbId] || 0) + 1;
// 2. Instruct the game core to lock that data into an invisible container
api.setMoonstoneChestItemSlot(killerId, 99, "Diamond", playerKillsByDbId[killerDbId]);
updateNameTag(killerId);
// 3. Award Gold Bars directly to inventory
api.giveItem(killerId, "Gold Bar", GOLD_PER_KILL);
// 4. FIXED: Replaced non-existent notification function with official messaging function
api.sendMessage(killerId, `+${GOLD_PER_KILL} Gold Bars for the kill! Total Kills: ${playerKillsByDbId[killerDbId]}`, { color: "gold" });
}
};
/* Global variables to manage the weapon systems */
if (typeof magmaWandCooldowns === "undefined") {
var magmaWandCooldowns = {};
}
if (typeof magmaWandTimers === "undefined") {
var magmaWandTimers = {};
}
/* Global dictionary to manage weapon timestamps */
if (typeof magmaWandCooldowns === "undefined") {
var magmaWandCooldowns = {};
}
/* Custom Weapon Abilities & Right-Click Magma Wand Functionality */
/* Triggered whenever a player right-clicks or interacts while holding an item */
onPlayerAltAction = (playerId) => {
try {
const heldItem = api.getHeldItem(playerId);
if (!heldItem) return;
/* Checks for a Molten Magma Rod specifically named Magma Wand */
if (
heldItem.name === "Molten Magma Rod" &&
heldItem.attributes &&
heldItem.attributes.customDisplayName === "Magma Wand"
) {
const currentTime = Date.now();
const lastUsed = magmaWandCooldowns[playerId] || 0;
const cooldownDuration = 2500; /* 2.5 seconds */
/* Blocks firing if 2.5 seconds have not passed */
if (currentTime - lastUsed < cooldownDuration) {
return;
}
const playerPos = api.getPosition(playerId);
if (playerPos && Array.isArray(playerPos)) {
const px = playerPos[0];
const py = playerPos[1];
const pz = playerPos[2];
/* Get looking direction to fire the fireballs forward */
let facing = [0, 0, -1];
const facingInfo = api.getPlayerFacingInfo ? api.getPlayerFacingInfo(playerId) : null;
if (facingInfo && facingInfo.dir) {
facing = facingInfo.dir;
}
const fx = facing[0];
const fy = facing[1];
const fz = facing[2];
/* Set the cooldown timestamp immediately before firing */
magmaWandCooldowns[playerId] = currentTime;
/* LAUNCH 9 FIREBALLS IN A COMPACT, SMALLER 3x3 SQUARE GRID PATTERN */
/* MIDDLE ROW (Eye Level - Small 0.08 spacing) */
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx, fy, fz], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx - 0.08, fy, fz + 0.08], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx + 0.08, fy, fz - 0.08], 2, 2, 0);
/* TOP ROW (Tighter vertical offset) */
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx, fy + 0.08, fz], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx - 0.08, fy + 0.08, fz + 0.08], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx + 0.08, fy + 0.08, fz - 0.08], 2, 2, 0);
/* BOTTOM ROW (Tighter vertical offset) */
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx, fy - 0.08, fz], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx - 0.08, fy - 0.08, fz + 0.08], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx + 0.08, fy - 0.08, fz - 0.08], 2, 2, 0);
}
}
} catch (err) {
api.log("Error in Magma Wand Right-Click: " + err);
}
};
/* Global dictionary to manage weapon timestamps */
if (typeof magmaWandCooldowns === "undefined") {
var magmaWandCooldowns = {};
}
/* Custom Weapon Abilities & Right-Click Magma Wand Functionality */
/* Triggered whenever a player right-clicks or interacts while holding an item */
onPlayerAltAction = (playerId) => {
try {
const heldItem = api.getHeldItem(playerId);
if (!heldItem) return;
/* Checks for a Molten Magma Rod specifically named Magma Wand */
if (
heldItem.name === "Molten Magma Rod" &&
heldItem.attributes &&
heldItem.attributes.customDisplayName === "Magma Wand"
) {
const currentTime = Date.now();
const lastUsed = magmaWandCooldowns[playerId] || 0;
const cooldownDuration = 2500; /* 2.5 seconds in milliseconds */
/* FIXED: Blocks firing instantly if 2.5 seconds have not passed */
if (currentTime - lastUsed < cooldownDuration) {
return;
}
const playerPos = api.getPosition(playerId);
if (playerPos && Array.isArray(playerPos)) {
const px = playerPos[0];
const py = playerPos[1];
const pz = playerPos[2];
/* Get looking direction to fire the fireballs forward */
let facing = [0, 0, -1];
const facingInfo = api.getPlayerFacingInfo ? api.getPlayerFacingInfo(playerId) : null;
if (facingInfo && facingInfo.dir) {
facing = facingInfo.dir;
}
const fx = facing[0];
const fy = facing[1];
const fz = facing[2];
/* Set the cooldown timestamp immediately before firing */
magmaWandCooldowns[playerId] = currentTime;
/* LAUNCH 9 FIREBALLS IN A 3x3 SQUARE GRID PATTERN */
/* MIDDLE ROW (Eye Level) */
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx, fy, fz], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx - 0.2, fy, fz + 0.2], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx + 0.2, fy, fz - 0.2], 2, 2, 0);
/* TOP ROW (Angled Upward) */
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx, fy + 0.2, fz], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx - 0.2, fy + 0.2, fz + 0.2], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx + 0.2, fy + 0.2, fz - 0.2], 2, 2, 0);
/* BOTTOM ROW (Angled Downward) */
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx, fy - 0.2, fz], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx - 0.2, fy - 0.2, fz + 0.2], 2, 2, 0);
api.attemptCreateThrowable(playerId, "Fireball", [px, py + 1.5, pz], [fx + 0.2, fy - 0.2, fz - 0.2], 2, 2, 0);
}
}
} catch (err) {
api.log("Error in Magma Wand Right-Click: " + err);
}
};
/* Triggered when damaging players with standard weapons */
onPlayerDamagingOtherPlayer = (attackerId, targetId, damageAmount, itemName, bodyPartHit, damagerDbId) => {
try {
const heldItem = api.getHeldItem(attackerId);
if (!heldItem) return;
/* Poison knife */
if (
heldItem.name === "Iron Dagger" &&
heldItem.attributes &&
heldItem.attributes.customDisplayName === "Poison Knife"
) {
api.applyEffect(targetId, "Weakness", 5000, { displayName: "Weakness", icon: "Weakness" });
api.applyEffect(targetId, "Poisoned", 2500, { displayName: "Poisoned", icon: "Poisoned" });
}
/* Wind Mace */
if (
heldItem.name === "Moonstone Mace" &&
heldItem.attributes &&
heldItem.attributes.customDisplayName === "Wind Mace"
) {
const attackerPos = api.getPosition(attackerId);
if (!attackerPos || !Array.isArray(attackerPos)) return;
const x = attackerPos[0];
const y = attackerPos[1];
const z = attackerPos[2];
if (y - Math.floor(y) > 0.1) {
api.applyHealthChange(targetId, -20, attackerId);
api.applyEffect(targetId, "Slowness", 5000, {
icon: "Slowness",
displayName: "Slammed",
inbuiltLevel: 2
});
api.setVelocity(attackerId, 0, 20, 0);
/* FIXED: Fully restored all array values to prevent unexpected comma crashes */
api.playParticleEffect({
dir1: [-3, -3, -3],
dir2: [3, 3, 3],
pos1: [x - 3, y, z - 3],
pos2: [x + 3, y + 3, z + 3],
texture: "glint",
minLifeTime: 0.3,
maxLifeTime: 1,
minEmitPower: 3,
maxEmitPower: 5,
minSize: 0.3,
maxSize: 0.7,
manualEmitCount: 100,
gravity: [0, -5, 0],
colorGradients: [
{
timeFraction: 0,
minColor: [200, 200, 255],
maxColor: [255, 255, 255]
}
],
velocityGradients: [
{
timeFraction: 0,
factor: 1,
factor2: 1
}
],
blendMode: 1
});
return "preventDamage";
}
}
} catch (err) {
api.log("Error in Weapon Script: " + err);
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter