Apply 10-block knockback and 2 damage on hit
// ==UserScript==
// @name Minefun Knockback 10 Blocks + 2 Damage
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Apply 10-block knockback and 2 damage on hit
// @match *://*.minefun.io/*
// @grant unsafeWindow
// @run-at document-idle
// @homepageURL https://greasyfork.org/en/scripts/12345-minefun-knockback-10-blocks
// ==/UserScript==
(function() {
'use strict';
// Knockback + Damage function
function applyKnockbackAndDamage(target, attacker, blocks, damage) {
// Calculate direction
let dx = target.x - attacker.x;
let dy = target.y - attacker.y;
let length = Math.sqrt(dx * dx + dy * dy);
dx /= length;
dy /= length;
// Knockback 10 blocks
target.x += dx * blocks;
target.y += dy * blocks;
// Apply 2 damage
if (typeof target.health !== "undefined") {
target.health -= damage;
if (target.health < 0) target.health = 0;
}
}
// Hook example: when player is hit
if (unsafeWindow.player) {
unsafeWindow.player.onHit = function(attacker) {
applyKnockbackAndDamage(unsafeWindow.player, attacker, 10, 2);
};
}
})();