const InputHelper = require("inputhelper"); var show = false; var showAdmin = false; var trading = false; const { x: screenX, y: screenY } = mp.game.graphics.getScreenActiveResolution(0, 0); let rxC = 0.5; let ryC = 0.5; let rWidth = 0.4; let sX = (screenX * 0.1 / 1000); let sY = (screenY * 0.1 / 1000); let eX = sX - 0.1; let eY = sY - 0.1; let sizeMul = 0.08; let yMul = 1.8; var targetPlayerName; let closePos = [0.7125, 0.17] var clickTime; var itemRadial = false; var hoverGrid; var radialSelect = "none"; var clickedItem; let aspectRatioFactor = screenX / screenY; var upRColor = 222; var downRColor = 222; var leftRColor = 222; var rightRColor = 222; var radialDescription; var inventoryWeight; var items = [[]]; var grid = []; grid[0] = [0.3375, 0.305] grid[1] = [0.4195, 0.305] grid[2] = [0.5015, 0.305] grid[3] = [0.5835, 0.305] grid[4] = [0.6655, 0.305] grid[5] = [0.3375, 0.455] grid[6] = [0.4195, 0.455] grid[7] = [0.5015, 0.455] grid[8] = [0.5835, 0.455] grid[9] = [0.6655, 0.455] grid[10] = [0.3375, 0.605] grid[11] = [0.4195, 0.605] grid[12] = [0.5015, 0.605] grid[13] = [0.5835, 0.605] grid[14] = [0.6655, 0.605] grid[15] = [0.3375, 0.755] grid[16] = [0.4195, 0.755] grid[17] = [0.5015, 0.755] grid[18] = [0.5835, 0.755] grid[19] = [0.6655, 0.755] var mouseLDown = false; var mouseRDown = false; var hoverItem; var dragItem = null; var oldDragSlot; var actFreeSlot; var bufferItem = []; var stackToItem; mp.events.add("showInventory", (invWeight, itemArr) => { if (show === false) { //mp.gui.chat.activate(false); setInterval() mp.gui.cursor.show(true, true); inventoryWeight = invWeight; items = itemArr; show = true; mp.game.graphics.requestStreamedTextureDict("itemimages", true); } else { mp.events.callRemote('saveInventory', JSON.stringify(items)); mp.gui.chat.activate(true); mp.gui.cursor.show(false, false); show = false; mp.game.graphics.setStreamedTextureDictAsNoLongerNeeded("itemimages"); inventoryWeight = 0; items = null; itemRadial = false; } }); mp.events.add("showInventoryToAdmin", (pName, invWeight, itemArr) => { if (showAdmin === false) { targetPlayerName = pName; mp.gui.chat.activate(false); inventoryWeight = invWeight; items = itemArr; mp.game.graphics.requestStreamedTextureDict("itemimages", true); setTimeout(() => mp.gui.cursor.show(true, true), 100); showAdmin = true; } }); mp.events.add("addItem", (item) => { if (show) { items.push(JSON.parse(item)); } }); mp.events.add("removeItem", (userItemId, amount) => { if (show) { var arrIndex; for (var i = 0; i < items.length; i++) { if (items[i][5] === userItemId) { arrIndex = i; } } inventoryWeight -= parseInt(items[arrIndex][2]) * amount; items[arrIndex][3] -= amount; if (items[arrIndex][3] === 0) { items.splice(arrIndex, 1); } } }); mp.events.add("render", () => { if (show === true) { var pos = mp.gui.cursor.position; mp.game.graphics.set2dLayer(1); //INVENTARHINTERGRUND mp.game.graphics.drawRect(rxC, ryC, 0.45, 0.7, 255, 255, 255, 200); mp.game.graphics.set2dLayer(2); //INVENTARÜBERSCHRIFT mp.game.graphics.drawText("Inventar ~g~" + inventoryWeight + "/40000g", [rxC, ryC - (rWidth / 1.20)], { font: 7, color: [112, 128, 144, 254], scale: [0.7, 0.7], outline: true, }); //SLOTS [RECHTECKE] [SLOTZAHLEN] var tempSlot; for (var slots = 0; slots < grid.length; slots++) { mp.game.graphics.drawRect(grid[slots][0], grid[slots][1], sizeMul, sizeMul * yMul, 112, 128, 144, 254); mp.game.graphics.drawText(tempSlot = slots + 1, [grid[slots][0] - (sizeMul / 2) + 0.006, grid[slots][1] - (sizeMul / 2 * yMul)], { font: 7, color: [255, 69, 0, 254], scale: [0.3, 0.3], outline: true, }); } mp.game.graphics.set2dLayer(3); //SPRITES + ITEMANZAHL for (var currentItem = 0; currentItem < items.length; currentItem++) { if (items[currentItem][4] !== "-1") { mp.game.graphics.drawSprite("itemimages", items[currentItem][0].toLowerCase(), grid[parseInt(items[currentItem][4] - 1)][0], grid[parseInt(items[currentItem][4] - 1)][1], rWidth / 8, rWidth / 5, 0, 255, 255, 255, 255); mp.game.graphics.drawText("(~y~" + items[currentItem][3] + "~s~)", [grid[parseInt(items[currentItem][4] - 1)][0] + (sizeMul / 2) - 0.008, grid[parseInt(items[currentItem][4] - 1)][1] + 0.05], { font: 0, color: [255, 255, 255, 255], scale: [0.25, 0.25], outline: true, }); } } mp.game.graphics.set2dLayer(4); //WENN MAUS ÜBER ITEM if (isMouseOverItem(pos[0], pos[1]) && dragItem === null && itemRadial === false) { mp.game.graphics.drawRect(pos[0] / screenX, pos[1] / screenY + 0.055, 0.14, 0.08, 0, 0, 0, 220); var hoverItemP = [items[hoverItem][0], items[hoverItem][1], items[hoverItem][2], items[hoverItem][3]]; //NAME mp.game.graphics.drawText("~g~" + hoverItemP[0], [pos[0] / screenX, pos[1] / screenY + 0.02], { font: 4, color: [255, 255, 255, 255], scale: [0.4, 0.4], outline: true, }); //BESCHREIBUNG mp.game.graphics.drawText(hoverItemP[1], [pos[0] / screenX, pos[1] / screenY + 0.04], { font: 4, color: [255, 255, 255, 255], scale: [0.35, 0.35], outline: true, }); //EINZELGEWICHT mp.game.graphics.drawText("~y~" + hoverItemP[2] + "g~s~ * " + hoverItemP[3] + "~s~ = ~y~" + hoverItemP[2] * hoverItemP[3] + "g", [pos[0] / screenX, pos[1] / screenY + 0.06], { font: 4, color: [255, 255, 255, 255], scale: [0.35, 0.35], outline: true, }); } //WENN MOUSE DOWN if (mouseLDown && dragItem !== null || mouseRDown && dragItem !== null) { if (isMouseOverFreeSlot(pos[0], pos[1]) || isItemOverSameItem(pos[0], pos[1])) { mp.game.graphics.drawSprite("itemimages", items[dragItem][0].toLowerCase(), pos[0] / screenX, pos[1] / screenY, rWidth / 8, rWidth / 5, 0, 100, 255, 100, 255); } else { mp.game.graphics.drawSprite("itemimages", items[dragItem][0].toLowerCase(), pos[0] / screenX, pos[1] / screenY, rWidth / 8, rWidth / 5, 0, 255, 100, 100, 255); } } mp.game.graphics.set2dLayer(5); if (itemRadial === true) { mp.game.graphics.drawSprite("itemimages", "radialsplit", grid[hoverGrid][0], grid[hoverGrid][1], rWidth / aspectRatioFactor, rWidth, 0, 0, 0, 0, 255); mp.game.graphics.drawSprite("itemimages", "radialup", grid[hoverGrid][0], grid[hoverGrid][1], rWidth / aspectRatioFactor, rWidth, 0, 222, upRColor, 222, upRColor); mp.game.graphics.drawSprite("itemimages", "radialdown", grid[hoverGrid][0], grid[hoverGrid][1], rWidth / aspectRatioFactor, rWidth, 0, 222, downRColor, 222, downRColor); //mp.game.graphics.drawSprite("itemimages", "radialleft", grid[hoverGrid][0], grid[hoverGrid][1], rWidth / aspectRatioFactor, rWidth, 0, 222, leftRColor, 222, leftRColor); //mp.game.graphics.drawSprite("itemimages", "radialright", grid[hoverGrid][0], grid[hoverGrid][1], rWidth / aspectRatioFactor, rWidth, 0, 222, rightRColor, 222, rightRColor); mp.game.graphics.set2dLayer(6); mp.game.graphics.drawSprite("itemimages", "radialdrop", grid[hoverGrid][0], grid[hoverGrid][1], rWidth / aspectRatioFactor, rWidth, 0, 255, 255, 255, 255); mp.game.graphics.drawSprite("itemimages", "radialuse", grid[hoverGrid][0], grid[hoverGrid][1], rWidth / aspectRatioFactor, rWidth, 0, 255, 255, 255, 255); } mp.game.graphics.set2dLayer(7); if (ifMouseSelectRadial(pos[0], pos[1])) { //mp.game.graphics.drawRect(pos[0] / screenX, pos[1] / screenY - 0.02, 0.08, 0.03, 0, 0, 0, 255); mp.game.graphics.drawText("~g~" + radialDescription, [pos[0] / screenX, pos[1] / screenY - 0.033], { font: 4, color: [255, 255, 255, 255], scale: [0.4, 0.4], outline: true, }); } ////--------------------------------------------------------------DEBUG //mp.game.graphics.drawText(itemRadial.toString() + " ~y~" + radialSelect, [0.5, 0.05], { // font: 7, // color: [255, 0, 0, 255], // scale: [0.7, 0.7], // outline: true, //}); ////KOORDINATEN //if (ifMouseSelectRadial(pos[0], pos[1])) { // mp.game.graphics.drawText((pos[0] / screenX).toFixed(3) + " / " + (pos[1] / screenY).toFixed(3), [pos[0] / screenX, pos[1] / screenY - 0.02], { // font: 4, // color: [255, 255, 255, 255], // scale: [0.4, 0.4], // outline: true, // }); //} ////----------------------------------------------------------DEBUG END } if (showAdmin === true) { var pos = mp.gui.cursor.position; mp.game.graphics.set2dLayer(1); //INVENTARHINTERGRUND mp.game.graphics.drawRect(rxC, ryC, 0.45, 0.7, 255, 255, 255, 200); mp.game.graphics.set2dLayer(2); //INVENTARÜBERSCHRIFT mp.game.graphics.drawText("Inventar von ~y~" + targetPlayerName + " ~g~" + inventoryWeight + "/40000g", [rxC, ryC - (rWidth / 1.20)], { font: 7, color: [112, 128, 144, 254], scale: [0.7, 0.7], outline: true, }); //SLOTS [RECHTECKE] [SLOTZAHLEN] var tempSlot; for (var slots = 0; slots < grid.length; slots++) { mp.game.graphics.drawRect(grid[slots][0], grid[slots][1], sizeMul, sizeMul * yMul, 112, 128, 144, 254); mp.game.graphics.drawText(tempSlot = slots + 1, [grid[slots][0] - (sizeMul / 2) + 0.006, grid[slots][1] - (sizeMul / 2 * yMul)], { font: 7, color: [255, 69, 0, 254], scale: [0.3, 0.3], outline: true, }); } mp.game.graphics.set2dLayer(3); //SPRITES + ITEMANZAHL for (var currentItem = 0; currentItem < items.length; currentItem++) { if (items[currentItem][4] !== "-1") { mp.game.graphics.drawSprite("itemimages", items[currentItem][0].toLowerCase(), grid[parseInt(items[currentItem][4] - 1)][0], grid[parseInt(items[currentItem][4] - 1)][1], rWidth / 8, rWidth / 5, 0, 255, 255, 255, 255); mp.game.graphics.drawText("(~y~" + items[currentItem][3] + "~s~)", [grid[parseInt(items[currentItem][4] - 1)][0] + (sizeMul / 2) - 0.008, grid[parseInt(items[currentItem][4] - 1)][1] + 0.05], { font: 0, color: [255, 255, 255, 255], scale: [0.25, 0.25], outline: true, }); } } mp.game.graphics.set2dLayer(4); //WENN MAUS ÜBER ITEM if (isMouseOverItem(pos[0], pos[1]) && dragItem === null && itemRadial === false) { mp.game.graphics.drawRect(pos[0] / screenX, pos[1] / screenY + 0.055, 0.14, 0.08, 0, 0, 0, 220); var hoverItemP = [items[hoverItem][0], items[hoverItem][1], items[hoverItem][2], items[hoverItem][3]]; //NAME mp.game.graphics.drawText("~g~" + hoverItemP[0], [pos[0] / screenX, pos[1] / screenY + 0.02], { font: 4, color: [255, 255, 255, 255], scale: [0.4, 0.4], outline: true, }); //BESCHREIBUNG mp.game.graphics.drawText(hoverItemP[1], [pos[0] / screenX, pos[1] / screenY + 0.04], { font: 4, color: [255, 255, 255, 255], scale: [0.35, 0.35], outline: true, }); //EINZELGEWICHT mp.game.graphics.drawText("~y~" + hoverItemP[2] + "g~s~ * " + hoverItemP[3] + "~s~ = ~y~" + hoverItemP[2] * hoverItemP[3] + "g", [pos[0] / screenX, pos[1] / screenY + 0.06], { font: 4, color: [255, 255, 255, 255], scale: [0.35, 0.35], outline: true, }); } if (isMouseOverX(pos[0], pos[1])) { mp.game.graphics.drawSprite("itemimages", "x", closePos[0], closePos[1], 0.02, 0.035, 0, 220, 20, 60, 255); } else { mp.game.graphics.drawSprite("itemimages", "x", closePos[0], closePos[1], 0.02, 0.035, 0, 255, 255, 255, 255); } } }); function isMouseOverItem(cX, cY) { if (dragItem === null) { var x = cX / screenX; var y = cY / screenY; var a; var b; var c; for (var s = 0; s < 20; s++) { a = grid[s][0] - x; b = grid[s][1] - y; c = Math.sqrt(a * a + b * b); var invSlot = (s + 1); if (c < sizeMul / 2) { for (i = 0; i < items.length; i++) { if (parseInt(items[i][4]) === invSlot) { hoverItem = i; return true; } } } } } else { if (itemRadial === false) { var x = cX / screenX; var y = cY / screenY; var a; var b; var c; for (var s = 0; s < 20; s++) { a = grid[s][0] - x; b = grid[s][1] - y; c = Math.sqrt(a * a + b * b); var invSlot = (s + 1); if (c < sizeMul / 2) { for (i = 0; i < items.length; i++) { if (parseInt(items[i][4]) === invSlot) { hoverGrid = s; return true; } } } } } } } function isMouseOverFreeSlot(cX2, cY2) { var x = cX2 / screenX; var y = cY2 / screenY; var a; var b; var c; var isItemOnSlot = 0; for (var s = 0; s < 20; s++) { a = grid[s][0] - x; b = grid[s][1] - y; c = Math.sqrt(a * a + b * b); var invSlot = (s + 1); if (c < sizeMul / 2) { for (i = 0; i < items.length; i++) { if (parseInt(items[i][4]) === invSlot) { isItemOnSlot++; } } if (isItemOnSlot === 0) { actFreeSlot = s + 1; return true; } } } } function isItemOverSameItem(cX2, cY2) { if (dragItem !== null) { var x = cX2 / screenX; var y = cY2 / screenY; var a; var b; var c; for (var s = 0; s < 20; s++) { a = grid[s][0] - x; b = grid[s][1] - y; c = Math.sqrt(a * a + b * b); var invSlot = (s + 1); if (c < sizeMul / 2) { for (i = 0; i < items.length; i++) { if (items[dragItem][0] === items[i][0] && parseInt(items[i][4]) === invSlot && items[hoverItem][4] !== items[i][4]) { stackToItem = i; return true; } } } } } } function isMouseOverX(cX2, cY2) { if (showAdmin) { var x = cX2 / screenX; var y = cY2 / screenY; var a; var b; var c; a = closePos[0] - x; b = closePos[1] - y; c = Math.sqrt(a * a + b * b); if (c < 0.018) { return true; } } } function ifMouseSelectRadial(cX2, cY2) { if (show && itemRadial === true) { var x = cX2 / screenX; var y = cY2 / screenY; var a; var b; var c; //OBEN if (x > grid[hoverGrid][0] - 0.0255 / aspectRatioFactor && x < grid[hoverGrid][0] + 0.0255 / aspectRatioFactor && y < grid[hoverGrid][1] - 0.065 && y > grid[hoverGrid][1] - 0.2) { radialSelect = "up"; radialDescription = "Wegwerfen"; upRColor = 255; return true; } //UNTEN else if (x > grid[hoverGrid][0] - 0.0255 / aspectRatioFactor && x < grid[hoverGrid][0] + 0.0255 / aspectRatioFactor && y > grid[hoverGrid][1] + 0.065 && y < grid[hoverGrid][1] + 0.2) { radialSelect = "down"; radialDescription = "Benutzen / Essen"; downRColor = 255; return true; } ////LINKS //else if (x > grid[hoverGrid][0] - 0.2 / aspectRatioFactor && x < grid[hoverGrid][0] - 0.065 / aspectRatioFactor && y < grid[hoverGrid][1] + 0.0255 && y > grid[hoverGrid][1] - 0.0255) { // radialSelect = "left"; // leftRColor = 255; // return true; //} ////RECHTS //else if (x < grid[hoverGrid][0] + 0.2 / aspectRatioFactor && x > grid[hoverGrid][0] + 0.065 / aspectRatioFactor && y < grid[hoverGrid][1] + 0.0255 && y > grid[hoverGrid][1] - 0.0255) { // radialSelect = "right"; // rightRColor = 255; // return true; else { upRColor = 222; downRColor = 222; leftRColor = 222; rightRColor = 222; } } } mp.events.add('click', (x, y, upOrDown, leftOrRight, relativeX, relativeY, worldPosition, hitEntity) => { var cX = x / screenX; var cY = y / screenY; //if (upOrDown === "down" && leftOrRight === "left") { // clickTimeL = Date.now(); // if (mouseActive === false) { // if (clickTimeR !== null && Date.now() - clickTimeR < 100) { // mouseActive = true; // mp.gui.cursor.show(true, true); // clickTimeL = null; // clickTimeR = null; // } // } // else { // if (clickTimeR !== null && Date.now() - clickTimeR < 100) { // mouseActive = false; // mp.gui.cursor.show(false, false); // clickTimeL = null; // clickTimeR = null; // } else { // mp.gui.chat.push("~r~" + worldPosition.x.toFixed(3).toString() + ", ~g~" + worldPosition.y.toFixed(3).toString() + ", ~b~" + worldPosition.z.toFixed(3).toString()); // } // } //} //if (upOrDown === "down" && leftOrRight === "right") { // clickTimeR = Date.now(); // if (mouseActive === false) { // if (clickTimeL !== null && Date.now() - clickTimeL < 100) { // mouseActive = true; // mp.gui.cursor.show(true, true); // clickTimeL = null; // clickTimeR = null; // } // } else { // if (clickTimeL !== null && Date.now() - clickTimeL < 100) { // mouseActive = false; // mp.gui.cursor.show(false, false); // clickTimeL = null; // clickTimeR = null; // } // } //} if (show) { //LINKE MAUSTASTE //RUNTER if (upOrDown === "down" && leftOrRight === "left" && mouseLDown === false && mouseRDown === false) { mouseLDown = true; if (isMouseOverItem(x, y) && dragItem === null && itemRadial === false) { dragItem = hoverItem; oldDragSlot = items[dragItem][4]; items[dragItem][4] = "-1"; } else if (ifMouseSelectRadial(x, y)) { switch (radialSelect) { case "up": var dropInput = new InputHelper("Wie viel Items möchtest du wegwerfen?"); dropInput.show(); dropInput.getValue((data) => { var amount = parseInt(data); if (isNaN(amount) || amount < 1) { mp.game.graphics.notify('~r~Du musst eine Zahl größer als 0 eingeben!'); return; } else if (parseInt(amount) > parseInt(items[clickedItem][3])) { mp.game.graphics.notify('~r~So viele Items hast du nicht!'); return; } mp.events.callRemote('itemInteract', "drop", items[clickedItem][5], parseInt(amount)); }); itemRadial = false; break; case "down": mp.events.callRemote('itemInteract', "use", items[clickedItem][5], 1); itemRadial = false; break; case "left": itemRadial = false; break; case "right": itemRadial = false; break; } } } //HOCH if (upOrDown === "up" && leftOrRight === "left" && mouseLDown === true && itemRadial === false) { mouseLDown = false; if (dragItem !== null) { if (isMouseOverFreeSlot(x, y)) { items[dragItem][4] = actFreeSlot; oldDragSlot = null; dragItem = null; hoverItem = null; } else if (isItemOverSameItem(x, y)) { var newAmount = parseInt(items[stackToItem][3]) + parseInt(items[dragItem][3]); items[stackToItem][3] = newAmount.toString(); items[dragItem][4] = "-1"; dragItem = null; hoverItem = null; } else { items[dragItem][4] = oldDragSlot; dragItem = null; hoverItem = null; } } } //RECHTE MAUSTASTE //RUNTER if (upOrDown === "down" && leftOrRight === "right" && mouseLDown === false && mouseRDown === false && itemRadial === false) { clickTime = Date.now(); mouseRDown = true; if (isMouseOverItem(x, y) && dragItem === null) { dragItem = hoverItem; oldDragSlot = items[hoverItem][4]; bufferItem = [items[hoverItem][0], items[hoverItem][1], items[hoverItem][2], items[hoverItem][3], items[hoverItem][4], items[hoverItem][5]]; items[hoverItem][3]--; } } //HOCH if (upOrDown === "up" && leftOrRight === "right" && mouseRDown === true && itemRadial === false) { mouseRDown = false; if (Date.now() - clickTime < 300 && isMouseOverItem(x, y)) { clickedItem = hoverItem; items[hoverItem][3]++; itemRadial = true; hoverItem = null; dragItem = null; clickTime = null; } else { if (dragItem !== null) { if (isMouseOverFreeSlot(x, y)) { items.push([items[dragItem][0], items[dragItem][1], items[dragItem][2], "1", actFreeSlot.toString(), "-1"]); if (items[hoverItem][3] === 0) { items[hoverItem][4] = "-1"; } dragItem = null; hoverItem = null; } else if (isItemOverSameItem(x, y)) { items[stackToItem][3]++; if (items[hoverItem][3] === 0) { items[hoverItem][4] = "-1"; } bufferItem = null; dragItem = null; hoverItem = null; } else { items[hoverItem][3]++; bufferItem = null; dragItem = null; hoverItem = null; } } } } } if (showAdmin) { //LINKE MAUSTASTE //RUNTER if (upOrDown === "down" && leftOrRight === "left" && mouseLDown === false && mouseRDown === false) { if (isMouseOverItem(x, y)) { items[hoverItem][4] = "-1" inventoryWeight -= parseInt(items[hoverItem][2]) * parseInt(items[hoverItem][3]); mp.events.callRemote('removeItemAsAdmin', "stack", items[hoverItem][5], targetPlayerName); } } //RECHTE MAUSTASTEshowAdmin = true; //RUNTER if (upOrDown === "down" && leftOrRight === "right" && mouseLDown === false && mouseRDown === false) { if (isMouseOverItem(x, y)) { items[hoverItem][3]--; mp.events.callRemote('removeItemAsAdmin', "one", items[hoverItem][5], targetPlayerName); if (items[hoverItem][3] === 0) { items[hoverItem][4] = "-1"; } inventoryWeight -= items[hoverItem][2]; } } if (upOrDown === "down" && leftOrRight === "left" && mouseLDown === false && mouseRDown === false) { if (isMouseOverX(x, y)) { mp.gui.chat.activate(true); mp.gui.cursor.show(false, false); showAdmin = false; mp.game.graphics.setStreamedTextureDictAsNoLongerNeeded("itemimages"); inventoryWeight = 0; items = null; } } } });