// ==UserScript==
// @name Better player info, v0.3 (Part 1).
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Watching others resources made easier!
// @author Diamondkingx
// @match http://zombs.io/
// @icon https://www.google.com/s2/favicons?domain=zombs.io
// @grant none
// ==/UserScript==
var activePlayerUid = undefined,
displayDivMenu = false,
displayCustomDiv = "expired",
tooltipPlayerHealthP = document.createElement("p"),
allowMouseMove = false,
switchButtonClicked = true,
customDivBackActive = false;
tooltipPlayerHealthP.className = "tphp";
function inChat() { if (document.getElementsByClassName("hud")[0].getElementsByClassName("hud-chat")[0].className.includes("is-focused")) { return true } else { return false } }
function mouseMoveFunc(e) {
if (game.world.inWorld == true) {
if (customDivBackActive == false) {
document.getElementsByClassName("hud-building-overlay hud-tooltip hud-tooltip-top info-container")[0].style.opacity = "1"
customDiv.getElementsByClassName("hud-building-overlay hud-tooltip hud-tooltip-top info-container")[0].style.pointerEvents = "all";
};
window.mousePositionToWorld = game.ui.mousePosition;
let mpx = mousePositionToWorld.x;
let mpy = mousePositionToWorld.y;
window.MPX = game.renderer.screenToWorld(mpx, mpy).x;
window.MPY = game.renderer.screenToWorld(mpx, mpy).y;
Object.entries(game.world.entities).forEach((player => {
if (player[1].entityClass == "PlayerEntity") {
window.x = player[1].targetTick.position.x - MPX
window.y = player[1].targetTick.position.y - MPY
window.distance = Math.sqrt(x * x + y * y);
window.mouseDistFromPlayer = distance + player[1].currentModel.base.node.width;
if (mouseDistFromPlayer < 100) {
displayCustomDiv = "valid";
activePlayerUid = player[1].targetTick.uid;
var expiredTimeout = setTimeout(() => {
displayCustomDiv = "expired";
}, 10000);
clearInterval(expiredTimeout);
expiredTimeout = setTimeout(() => {
displayCustomDiv = "expired";
}, 10000);
window.ActivePlayerUid = activePlayerUid;
window.DisplayDivMenu = displayDivMenu;
}
}
}))
if (game.world.entities[activePlayerUid] !== undefined || activePlayerUid !== game.ui.playerTick.uid) {
if (game.world.entities[activePlayerUid] !== undefined) {
window.mousePositionToWorld2 = game.ui.mousePosition;
let mpx2 = mousePositionToWorld2.x;
let mpy2 = mousePositionToWorld2.y;
window.MPX2 = game.renderer.screenToWorld(mpx2, mpy2).x;
window.MPY2 = game.renderer.screenToWorld(mpx2, mpy2).y;
window.x2 = game.world.entities[activePlayerUid].targetTick.position.x - MPX2
window.y2 = game.world.entities[activePlayerUid].targetTick.position.y - MPY2
window.distance2 = Math.sqrt(x2 * x2 + y2 * y2);
window.mouseDistFromPlayer2 = distance2 + 80;
};
if (game.world.entities[activePlayerUid] !== undefined && mouseDistFromPlayer2 !== undefined) {
displayDivMenu = true;
if (game.world.entities[activePlayerUid] !== undefined) {
window.customLeft = game.renderer.worldToScreen(game.world.entities[activePlayerUid].targetTick.position.x, game.world.entities[activePlayerUid].targetTick.position.y).x - ((360 / 2) + 17) + "px";
window.customTop = game.renderer.worldToScreen(game.world.entities[activePlayerUid].targetTick.position.x, game.world.entities[activePlayerUid].targetTick.position.y).y - 300 + "px";
};
if (parseInt(customTop) < 0) {
customDiv.style.top = "-33px";
} else {
if (parseInt(customTop) > window.innerHeight - 230) {
customDiv.style.top = window.innerHeight - 230 + "px"
}
else {
customDiv.style.top = customTop;
}
}
if (parseInt(customLeft) < 0) {
customDiv.style.left = "-10px";
}
else {
if (parseInt(customLeft) > window.innerWidth - 360) {
customDiv.style.left = window.innerWidth - 360 + "px";
}
else {
customDiv.style.left = customLeft;
}
}
}
if (displayDivMenu == true && displayCustomDiv == "valid") {
document.getElementsByClassName("hud-building-overlay hud-tooltip hud-tooltip-top")[0].style.display = "none";
if (customDivBackActive == false) {
customDiv.style.transform = "scale(1) rotate(0deg)"
}
customDiv.style.pointerEvents = "all";
}
else if (displayDivMenu == false && displayCustomDiv == "expired") {
if (customDivBackActive == false) {
customDiv.style.transform = "scale(0) rotate(0deg)";
customDiv.style.pointerEvents = "none"
}
}
}
}
}
window.customDiv = document.createElement("div");
customDiv.innerHTML = `
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous">
<style>
.hud-building-overlay .hud-building-stats .hud-stats-values:first-child::after{
display: none;
}
.hud-tooltip-top::after{
display: none;
}
.hud-building-overlay .hud-tooltip-health::after{}
.tphp{
position: absolute;
top: 18%;
left: 41%;
line-height: 27px;
font-size: 12px;
font-family: 'Hammersmith One', sans-serif;
color: #eee;
text-shadow: 0 0 1px rgb(0 0 0 / 80%);
transform: translate(-50%, -50%);
display: none;
}
.switchButton{
position: absolute;
top: 95%;
left: 90%;
z-index: 100;
color: rgba(255, 255, 255, 0.7);
background-color: transparent;
border: none;
font-weight: bold;
font-family: Hammersmith One;
font-size: 20px;
transition: all 0.5s;
cursor: pointer;
outline: none;
width: 60px;
height: 40px;
}
.switchButton:hover{
color: rgba(255, 255, 255, 1);
}
.customDivBack{
background: rgba(0, 0, 0, 0.4);
position: absolute;
width: 100%;
height: 110%;
border-radius: 4px;
transform: translate(-50%, -50%) rotateY(180deg);
left: -47.2%;
top: 61.5%;
opacity: 0;
pointer-events: none;
transition: all 0.3s;
transfrom-style: preserve-3d;
color: rgba(255,255,255,0.8);
z-index: 1;
}
.partyBtn {
position: absolute;
left: 56.5%;
top: 40.5%;
display: inline-block;
height: 30px;
line-height: 30px;
padding: 0 15px;
background: #47950d;
color: #eee;
border: 0;
font-size: 14px;
vertical-align: top;
text-align: center;
text-decoration: none;
text-shadow: 0 1px 0 rgb(0 0 0 / 40%);
box-shadow: 0 2px 10px rgb(0 0 0 / 20%);
border-radius: 4px;
transition: all 0.15s ease-in-out;
cursor: pointer;
}
.partyBtn:hover {
filter: brightness(120%);
}
.petNotFound {
width: 100%;
height: 100%;
background-color: transparent;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
border-radius: 5px;
}
.spinner {
animation: spin 0.4s infinite ease-in-out;
}
@keyframes spin {
from{transform: rotate(0deg);}
to{transform: rotate(360deg);}
}
</style>
<button class="switchButton">></button>
<div id="hud-building-overlay" class="hud-building-overlay hud-tooltip hud-tooltip-top info-container" style="display: block; left: 10px; top: 10px; transition: all 0.4s;"><div class="hud-tooltip-building">
<h2 class="player-Name">undefined</h2>
<h3 style="position: relative; left: 0px;">Uid: <span class="hud-building-tier player-Uid">1</span></h3>
<div class="hud-tooltip-health">
<span class="hud-tooltip-health-bar" style="width:100%; transition: all 0.4s;"></span>
</div>
<div class="hud-tooltip-body">
<div class="hud-building-stats">
<div class="hud-stats-current hud-stats-values">
<p >Wood: <strong class="hud-stats-current player-Wood">undefined</strong></p><p>Stone: <strong class="hud-stats-current player-Stone">undefined</strong></p><p>Gold: <strong class="hud-stats-current player-Gold">undefined</strong></p>
</div>
<div class="hud-stats-next hud-stats-values">
<p>Tokens: <strong class="hud-stats-next player-Tokens">undefined</strong></p><p>Score: <strong class="hud-stats-next player-Score">undefined</strong></p><p style="display: block;">Health: <strong class="hud-stats-next player-Health">undefined</strong></p>
</div>
</div>
<p class="hud-building-actions" style="display: block;">
<span class="hud-building-dual-btn" style="display: none;"
</span>
</p>
</div>
</div></div>
<div class="customDivBack hud-building-overlay hud-tooltip hud-tooltip-top">
<div class="hud-tooltip-building" style="transition: transform 0.3s;">
<h2 class="pet-Name">Undefined</h2>
<h3 style="position: relative; left: 0px;">Uid: <span class="hud-building-tier pet-Uid">000000000</span></h3>
<div class="hud-tooltip-health">
<span class="hud-tooltip-health-bar" style="width:100%; transition: all 0.4s;"></span>
<p class="pet-health-bar"></p></div>
<div class="hud-tooltip-body">
<div class="hud-building-stats">
<button class="partyBtn" style="display: none;">Join</button>
<div class="hud-stats-current hud-stats-values">
<p>Health: <strong class="hud-stats-current pet-Health">Null</strong></p>
<p>Level/Tier: <strong class="hud-stats-current pet-Level/Tier">Null</strong></p>
<p>Experience: <strong class="hud-stats-current pet-Exp">Null</strong></p>
</div>
<div class="hud-stats-next hud-stats-values">
<p style="display: none">Party: <strong class="hud-stats-next party-Name">Null</strong></p>
</div>
</div>
<p class="hud-building-actions" style="display: block;">
<span class="hud-building-dual-btn" style="display: none;" <="" span="">
</span></p>
</div>
</div>
<div class="petNotFound">
<h2 align="center" style="margin-top: 15%; color: #B3353C;">Pet not found!</h2>
<p class="reasons"style="position: relative; color: #B3353C; font-weight: bold; margin-top: 0%; transition: all 0.3s;" align="center">Reasons: </p>
<h3 align="center" style="position: relative; color: #B3353C; font-weight: bold; margin-top: -2%; transition: all 0.3s;">Waiting for the pet... <i class="fas fa-circle-notch spinner"></i><h3>
</div>
`;
customDiv.className = "customDiv hud-tooltip-top";
customDiv.style.transition = "left 0.5s, transform 0.3s, top 0.5s";
customDiv.style.position = "relative";
customDiv.style.transform = "scale(0) rotateY(0deg)";
customDiv.style.zIndex = "5";
customDiv.style.width = "360px";
customDiv.style.height = "180px";
customDiv.style.pointerEvents = "all";
customDiv.style.transformStyle = "preserve-3d";
document.getElementsByClassName("hud")[0].append(customDiv)
customDiv.getElementsByClassName("hud-tooltip-health")[0].append(tooltipPlayerHealthP);
window.customDivBack = customDiv.getElementsByClassName("customDivBack")[0];
window.switchButton = customDiv.getElementsByClassName("switchButton")[0];
window.partyBtn = customDivBack.getElementsByClassName("partyBtn")[0];
window.reasons = customDivBack.getElementsByClassName("reasons")[0];
window.petNotFound = customDivBack.getElementsByClassName("petNotFound")[0];
function setTrue(e) {
var key = e.keyCode || e.whichKey;
if (key == 18 && allowMouseMove == false) {
e.preventDefault();
allowMouseMove = true;
document.addEventListener("mousemove", mouseMoveFunc);
}
else if (key == 16) {
if (inChat() == false) {
customDiv.style.transform = "scale(0)";
customDiv.style.pointerEvents = "none";
}
}
}
var liveUpdating = setInterval(() => {
if (game.world.inWorld == true) {
Object.entries(game.world.entities).forEach(player => {
if (activePlayerUid !== undefined && displayDivMenu == true) {
if (player[1].targetTick.uid == activePlayerUid) {
let customDivScale = customDiv.style.transform.match(/scale()/)["input"].match(/[0-9]/)[0]
if (customDivScale > 0) {
var playerName = customDiv.getElementsByClassName("player-Name")[0];
let maxLength = 12;
playerName.innerText = player[1].targetTick.name;
playerName.innerText.length > maxLength ? playerName.innerText = playerName.innerText.substr(0, maxLength) + "..." : playerName.innerText = player[1].targetTick.name;
customDiv.getElementsByClassName("player-Uid")[0].innerText = player[1].targetTick.uid;
customDiv.getElementsByClassName("player-Wood")[0].innerText = player[1].targetTick.wood;
customDiv.getElementsByClassName("player-Stone")[0].innerText = player[1].targetTick.stone;
customDiv.getElementsByClassName("player-Gold")[0].innerText = player[1].targetTick.gold;
customDiv.getElementsByClassName("player-Score")[0].innerText = player[1].targetTick.score;
customDiv.getElementsByClassName("player-Tokens")[0].innerText = player[1].targetTick.token;
customDiv.getElementsByClassName("player-Health")[0].innerText = player[1].targetTick.health;
customDiv.getElementsByClassName("hud-tooltip-health-bar")[0].style.width = 100 - ((player[1].targetTick.maxHealth - player[1].targetTick.health) / player[1].targetTick.maxHealth * 100) + "%";
//tooltipPlayerHealthP.innerText = player[1].targetTick.health;
}
}
}
})
}
}, 100)
window.addEventListener("mousedown", (e) => {
if (!customDiv.contains(e.target)) {
customDiv.style.transform = "scale(0) rotateY(0deg)";
customDivBack.style.left = "-47.2%";
customDivBack.style.opacity = "0";
customDivBack.style.pointerEvents = "none";
customDiv.style.pointerEvents = "none";
customDivBackActive = false;
}
})
switchButton.addEventListener("mousedown", (e) => {
e.preventDefault();
e.stopPropagation();
if (customDivBackActive == false) {
customDivBackActive = true;
customDiv.getElementsByClassName("hud-building-overlay hud-tooltip hud-tooltip-top info-container")[0].style.opacity = "0";
customDiv.getElementsByClassName("hud-building-overlay hud-tooltip hud-tooltip-top info-container")[0].style.pointerEvents = "none";
customDiv.style.transform = "scale(1) rotateY(180deg)";
customDivBack.style.left = "53%";
customDivBack.style.opacity = "1";
customDivBack.style.pointerEvents = "all";
}
else if (customDivBackActive == true) {
customDivBackActive = false;
document.getElementsByClassName("hud-building-overlay hud-tooltip hud-tooltip-top info-container")[0].style.opacity = "1"
customDiv.getElementsByClassName("hud-building-overlay hud-tooltip hud-tooltip-top info-container")[0].style.pointerEvents = "all";
customDiv.style.transform = "scale(1) rotateY(0deg)";
customDivBack.style.left = "-47.2%";
customDivBack.style.opacity = "0";
customDivBack.style.pointerEvents = "none";
}
})
function setFalse(e) {
var key = e.keyCode || e.whichKey;
if (key == 18 && allowMouseMove == true) {
e.preventDefault();
allowMouseMove = false;
document.removeEventListener("mousemove", mouseMoveFunc)
}
else if (key == 16) {
if (inChat() == false) {
customDiv.style.transform = "scale(0) rotateY(0deg)";
customDiv.style.pointerEvents = "none";
customDivBack.style.left = "-47.2%";
customDivBack.style.opacity = "0";
customDivBack.style.pointerEvents = "none";
customDivBackActive = false;
}
}
}
document.addEventListener("keydown", setTrue);
document.addEventListener("keyup", setFalse);
var getPetInfo = setInterval(() => {
if (game.world.inWorld == true) {
if (game.world.entities[activePlayerUid] !== undefined && activePlayerUid !== undefined) {
if (game.world.entities[game.world.entities[activePlayerUid].targetTick.petUid] !== undefined) {
if (game.world.entities[game.world.entities[activePlayerUid].targetTick.petUid].isInViewport() == true) {
var pet = game.world.entities[game.world.entities[activePlayerUid].targetTick.petUid];
petNotFound.style.opacity = "0";
petNotFound.style.pointerEvents = "none";
customDivBack.getElementsByClassName("hud-tooltip-building")[0].style.transform = "scale(1,1)";
customDivBack.getElementsByClassName("pet-Name")[0].innerText = pet.targetTick.model;
customDivBack.getElementsByClassName("pet-Uid")[0].innerText = pet.targetTick.uid;
customDivBack.getElementsByClassName("pet-Health")[0].innerText = pet.targetTick.health;
customDivBack.getElementsByClassName("pet-Level/Tier")[0].innerText = pet.currentModel.experienceBar.level + "/" + pet.targetTick.tier;
customDivBack.getElementsByClassName("pet-Exp")[0].innerText = pet.targetTick.experience;
customDivBack.getElementsByClassName("hud-tooltip-health-bar")[0].style.width = (100 - (pet.targetTick.maxHealth - pet.targetTick.health) / pet.targetTick.maxHealth * 100) + "%"
}
}
else {
if (activePlayerUid !== undefined) {
if (game.world.entities[game.world.entities[activePlayerUid].targetTick.petUid] == undefined) {
customDivBack.getElementsByClassName("hud-tooltip-building")[0].style.transform = "scale(1,0)";
petNotFound.style.pointerEvents = "all";
petNotFound.style.opacity = "1";
}
}
}
}
}
}, 100);
let reasonsArray = ["Pet is dead,", "He is out of your screen,", "Or the player doesn't have one yet."]
let i = 0;
var cycleReasons = setInterval(() => {
let customDivScale = customDiv.style.transform.match(/scale()/)["input"].match(/[0-9]/)[0];
if (customDivScale > 0) {
i < reasonsArray.length == false ? i = 0 : i = i;
if (i < reasonsArray.length) {
reasons.style.opacity = "0";
setTimeout(() => {
reasons.style.opacity = "1";
reasons.innerText = "Reasons: " + reasonsArray[i];
i++;
}, 300)
}
}
}, 3000);
var changeCUDzIndex = setInterval(() => {
inChat() == true ? customDiv.style.zIndex = "5" : customDiv.style.zIndex = "14";
}, 100)
var stopTowerTooltip = setInterval(() => {
let customDivScale = customDiv.style.transform.match(/scale()/)["input"].match(/[0-9]/)[0];
if(customDivScale > 0){
document.getElementsByClassName("hud-building-overlay hud-tooltip hud-tooltip-top")[0].style.display = "none";
}
}, 1)