import InputHelper from '../../inputhelper';

export default function inventory(globalData: GlobalData) {
    var q;
    var qw = 0;


    var show = false; //ob das Inventar dem Spieler gezeigt wird.
    var showAdmin = false; //ob das Inventar eines Spielers dem Admin gezeigt wird
    const { x: screenX, y: screenY } = mp.game.graphics.getScreenActiveResolution(0, 0);
    let rxC = 0.5; //Breitenpositionierung des Inventars auf Screen-(C)enter
    let ryC = 0.4; //Höhenpositionierung des Inventars auf Screen-(C)enter
    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 aspectRatioFactor = screenX / screenY; //Höhenmultiplikator (damit Quadrate anstatt Rechtecke der einzelnen Slots entstehen)
    let sizeMulx = 0.08; //Größenmultiplikator (GUI Skalierung)
    let sizeMuly = sizeMulx * aspectRatioFactor; //Größenmultiplikator (GUI Skalierung)
    let sizeMulxHalf = sizeMulx / 2;
    let sizeMulyHalf = sizeMuly / 2;
    var targetPlayerName; //Der Spieler der den Handel anfragt
    let closePos = [0.7125, 0.17] //Position des X für Adminansicht
    let tradeBoxPos = [0.7125, 0.82] //Center der Handelsbox
    var clickTime; //Für Berechnung wie lange der Mausklick-Handler zwischen Aktionen benötigt
    var itemRadial = false; //Ob das Item-Radialmenü gezeigt wird
    var hoverGrid; //Ob man über einem Gridfeld hovert
    var radialSelect = "none"; //Auswahl des Radialmenüs
    var clickedItem; //Das angeklickte Item für das Radialmenü
    //let aspectRatioFactor = ; //Seitenverhältnis des Bildschirms (Entspricht yMul aufgerundet)
    var upRColor = 222; //Standard Transparenzen für das Hovern über der Radialauswahl
    var downRColor = 222; //Standard Transparenzen für das Hovern über der Radialauswahl
    var leftRColor = 222; //Standard Transparenzen für das Hovern über der Radialauswahl
    var rightRColor = 222; //Standard Transparenzen für das Hovern über der Radialauswahl
    var radialDescription; //Radialbeschreibung die über dem Mauszeiger angezeigt wird wenn man hovert.
    var tradePartner = "Keinem"; //Der Spieler mit dem man Handeln möchte
    var tradePrize = 0; //Der Preis welcher dem Handelempfänger angezeigt wird
    var tradeConfirm = false; //Ob der Handelspartner den Handel akzeptiert
    var isTrading = false; //Bestimmt ob das Handelsfenster unten angezeigt wird
    var isTradingResult = false;
    var dragTradeItem = null; //Ob aktuell ein Item aus dem Handelfenster gezogen wird
    var spriteScaleX = rWidth / 8;
    var spriteScaleY = rWidth / 8 * aspectRatioFactor;
    var syncStatus = false; //Synchronisation mit der Datenbank
    var syncCount = 0; //Wieviele Slots noch gesynced werden müssen
    var syncDeg = 0;

    var inventoryWeight; //Das aktuelle Inventargewicht, berechnet aus allen Metainfos des items[[]] Array
    var items = [[]]; //Items aus der Datenbank
    var tradeItems = []; //Handelsitems aus der aktuellen Handelssession
    var tradeResultItems = [[]];

    var grid = [];
    grid[0] = [0.3375, 0.205]
    grid[1] = [0.4195, 0.205]
    grid[2] = [0.5015, 0.205]
    grid[3] = [0.5835, 0.205]
    grid[4] = [0.6655, 0.205]
    grid[5] = [0.3375, 0.355]
    grid[6] = [0.4195, 0.355]
    grid[7] = [0.5015, 0.355]
    grid[8] = [0.5835, 0.355]
    grid[9] = [0.6655, 0.355]
    grid[10] = [0.3375, 0.505]
    grid[11] = [0.4195, 0.505]
    grid[12] = [0.5015, 0.505]
    grid[13] = [0.5835, 0.505]
    grid[14] = [0.6655, 0.505]
    grid[15] = [0.3375, 0.655]
    grid[16] = [0.4195, 0.655]
    grid[17] = [0.5015, 0.655]
    grid[18] = [0.5835, 0.655]
    grid[19] = [0.6655, 0.655]

    var tradeGrid = [];
    tradeGrid[0] = [0.3375, 0.925]
    tradeGrid[1] = [0.4195, 0.925]
    tradeGrid[2] = [0.5015, 0.925]
    tradeGrid[3] = [0.5835, 0.925]
    tradeGrid[4] = [0.6655, 0.925]

    var mouseLDown = false; //Ob die Linke Maustaste gedrückt wird (while)
    var mouseRDown = false; //Ob die Rechte Maustaste gedrückt wird (while)
    var hoverItem; //Das Item über welches der Mauszeiger schwebt
    var dragItem = null; //Das Item das aktuell gezogen wird
    var oldDragSlot; //Ursprungsslot des gezogenen Items
    var actFreeSlot; //Ob der aktuelle Hover-Slot während des Item-ziehens frei ist
    var actFreeTradeSlot; //Ob der aktuelle TradeInventar-Hover-Slot während des Item-ziehens frei ist
    var bufferItem = [];
    var stackToItem; //Der Slot zu dem das aktuelle Item gestackt würde, wenn man die Maustaste loslässt
    var stackToTradeItem; //Der Handels-Slot zu dem das aktuelle Item gestackt würde, wenn man die Maustaste loslässt

    mp.events.add("showInventory", (invWeight, itemArr) => {
        if (show === false) {
            //mp.gui.chat.activate(false);
            
            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;
            syncCount++;
            mp.game.graphics.setStreamedTextureDictAsNoLongerNeeded("itemimages");
            inventoryWeight = 0;
            items = null;
            itemRadial = false;
            if (tradeItems.length === 0) {
                isTrading = false;
            }
        }
    });

    //Zeigt dem Handelsanfragenden das Handelsinventar
    mp.events.add("openTradeMenu", (tradePartnerName) => {
        tradePartner = tradePartnerName;
        isTrading = true;
    });

    //Zeigt dem Handelspartner das Fenster zur Annahme oder Verweigerung des Handels
    mp.events.add("showTradeRequest", () => {
        show = false;
    });

    //Zeigt dem Admin das Inventar eines Spielers
    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;
        }
    });

    //Falls das Inventar aktuell offen ist und ein neues hinzugefügt wird, wird dieses Live angezeigt.
    mp.events.add("addItem", (item) => {
        if (show) {
            items.push(JSON.parse(item));
        }
    });

    //Löscht die Handelsitems beim Handelsanfragenden
    mp.events.add("clearTradeItems", () => {
        tradeConfirm = false;
        tradeItems.splice(0, tradeItems.length);
        tradePartner = "Keinem";
        tradePrize = 0;
    });


    //Zeigt dem Handelspartner die zu handelnden Items unter seinem Inventar an.
    mp.events.add("showTradeItems", (tradeResultItemArray) => {
        //for (var i = 0; i < tradeResultItemArray.length; i++) {

        //    tradeItems.push(tradeResultItemArray[i]);
        //}
        tradeItems = JSON.parse(tradeResultItemArray);
        isTrading = true;
    });

    //Entsperrt beim Handelsanfragenden die Items aus dem Handelsfenster
    mp.events.add("unlockTradeItems", () => {
        tradeConfirm = false;
        tradePartner = "Keinem";
        tradePrize = 0;
    });

    //Falls ein Item administrativ entfernt wird, würde auch dies Live angezeigt.
    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("SERVER:INVENTORY_SYNC", () => {
        syncCount--;
    });

    mp.events.add("render", () => {
        var pos;
        if (show === true) {
            pos = mp.gui.cursor.position;

            for (q = 0; q < items.length; q++) {
                mp.game.graphics.drawText("[" + items[q][0] + "]" + "[" + items[q][2] + "]" + "[" + items[q][3] + "]" + "[" + items[q][4] + "]" + "[" + items[q][5] + "]", [0.1, 0.4 + qw], {
                //mp.game.graphics.drawText("(MOIN)", [0.1, 0.4 + qw], {
                    font: 4,
                    color: [255, 255, 255, 254],
                    scale: [0.4, 0.4],
                    outline: true,
                    centre: false
                });
                qw += 0.025;
            }

            mp.game.graphics.set2dLayer(1); //#            
            mp.game.graphics.drawRect(rxC, ryC, 0.45, 0.7, 255, 255, 255, 200); //INVENTARHINTERGRUND    
            
            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,
                centre: false
            });

            if (syncCount != 0) {
                syncDeg += 3;
                if (syncDeg === 360) syncDeg = 0;

                mp.game.graphics.drawText("~s~synchronisiere ~g~ " + syncCount, [rxC + 0.165, ryC - (rWidth / 1.20) + 0.035], {
                    font: 7,
                    color: [112, 128, 144, 254],
                    scale: [0.4, 0.4],
                    outline: true,
                    centre: false
                });
                mp.game.graphics.drawSprite("itemimages", "refresh", rxC + 0.165, ryC - (rWidth / 1.20) + 0.01, spriteScaleX * 0.4, spriteScaleY * 0.4, syncDeg, 255, 255, 255, 255);
            } else {
                mp.game.graphics.drawText("~s~synchronisiert", [rxC + 0.165, ryC - (rWidth / 1.20) + 0.035], {
                    font: 7,
                    color: [112, 128, 144, 254],
                    scale: [0.4, 0.4],
                    outline: true,
                    centre: false
                });
            }

            //SLOTS [RECHTECKE] [SLOTZAHLEN]

            var slots;
            var tempSlot;
            for (slots = 0; slots < grid.length; slots++) {
                mp.game.graphics.drawRect(grid[slots][0], grid[slots][1], sizeMulx, sizeMuly, 112, 128, 144, 254);
                mp.game.graphics.drawText(tempSlot = slots + 1, [grid[slots][0] - sizeMulxHalf + 0.006, grid[slots][1] - (sizeMulxHalf * aspectRatioFactor)], {
                    font: 7,
                    color: [255, 69, 0, 254],
                    scale: [0.3, 0.3],
                    outline: true,
                    centre: false
                });
            }

            mp.game.graphics.set2dLayer(3); //###

            var currentItem;

            //SPRITES + ITEMANZAHL
            for (currentItem = 0; currentItem < items.length; currentItem++) {
                if (items[currentItem][4] !== "-1") {
                    mp.game.graphics.drawSprite("itemimages", items[currentItem][0].toLowerCase(), grid[items[currentItem][4] - 1][0], grid[items[currentItem][4] - 1][1], spriteScaleX, spriteScaleY, 0, 255, 255, 255, 255);
                    mp.game.graphics.drawText("(~y~" + items[currentItem][3] + "~s~)", [grid[items[currentItem][4] - 1][0] + sizeMulxHalf - 0.008, grid[items[currentItem][4] - 1][1] + 0.05], {
                        font: 0,
                        color: [255, 255, 255, 255],
                        scale: [0.25, 0.25],
                        outline: true,
                        centre: false
                    });
                }
            }

            var hoverItemP;

            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);

                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,
                    centre: false
                });

                //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,
                    centre: false
                });

                //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,
                    centre: false
                });
            }

            //WENN MOUSE DOWN
            if (mouseLDown && dragItem !== null || mouseRDown && dragItem !== null) {

                if (isMouseOverFreeSlot(pos[0], pos[1]) || isMouseOverFreeTradeSlot(pos[0], pos[1]) || isItemOverSameItem(pos[0], pos[1]) || isItemOverSameTradeItem(pos[0], pos[1])) {
                    if (dragTradeItem === false) {
                        mp.game.graphics.drawSprite("itemimages", items[dragItem][0].toLowerCase(), pos[0] / screenX, pos[1] / screenY, spriteScaleX, spriteScaleY, 0, 100, 255, 100, 255);
                    } else {
                        mp.game.graphics.drawSprite("itemimages", tradeItems[dragItem][0].toLowerCase(), pos[0] / screenX, pos[1] / screenY, spriteScaleX, spriteScaleY, 0, 100, 255, 100, 255);
                    }
                } else {
                    if (dragTradeItem === false) {
                        mp.game.graphics.drawSprite("itemimages", items[dragItem][0].toLowerCase(), pos[0] / screenX, pos[1] / screenY, spriteScaleX, spriteScaleY, 0, 255, 100, 100, 255);
                    } else {
                        mp.game.graphics.drawSprite("itemimages", tradeItems[dragItem][0].toLowerCase(), pos[0] / screenX, pos[1] / screenY, spriteScaleX, spriteScaleY, 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.5, 0.5],
                    outline: true,
                    centre: false
                });
            }
            if (isTrading) {
                mp.game.graphics.set2dLayer(1);
                mp.game.graphics.drawRect(rxC, 0.925, 0.45, 0.25, 255, 255, 255, 200);
                mp.game.graphics.set2dLayer(2);
                var tempSlot2;
                for (slots = 0; slots < tradeGrid.length; slots++) {
                    mp.game.graphics.drawRect(tradeGrid[slots][0], tradeGrid[slots][1], sizeMulx, sizeMuly, 112, 128, 144, 254);
                    mp.game.graphics.drawText(tempSlot2 = slots + 1, [tradeGrid[slots][0] - sizeMulxHalf + 0.006, tradeGrid[slots][1] - (sizeMulxHalf * aspectRatioFactor)], {
                        font: 7,
                        color: [69, 255, 0, 254],
                        scale: [0.3, 0.3],
                        outline: true,
                        centre: false
                    });
                }

                mp.game.graphics.set2dLayer(3);

                //SPRITES + ITEMANZAHL
                if (tradeItems.length !== 0) {
                    for (currentItem = 0; currentItem < tradeItems.length; currentItem++) {
                        if (tradeItems[currentItem][4] !== "-1") {
                            mp.game.graphics.drawSprite("itemimages", tradeItems[currentItem][0].toLowerCase(), tradeGrid[tradeItems[currentItem][4] - 1][0], tradeGrid[tradeItems[currentItem][4] - 1][1], spriteScaleX, spriteScaleY, 0, 255, 255, 255, 255);
                            mp.game.graphics.drawText("(~y~" + tradeItems[currentItem][3] + "~s~)", [tradeGrid[tradeItems[currentItem][4] - 1][0] + sizeMulxHalf - 0.008, tradeGrid[tradeItems[currentItem][4] - 1][1] + 0.05], {
                                font: 0,
                                color: [255, 255, 255, 255],
                                scale: [0.25, 0.25],
                                outline: true,
                                centre: false
                            });
                            if (tradeConfirm === true) {
                                mp.game.graphics.drawSprite("itemimages", "lock", tradeGrid[tradeItems[currentItem][4] - 1][0], tradeGrid[tradeItems[currentItem][4] - 1][1], spriteScaleX / 2, spriteScaleY / 2, 0, 255, 255, 255, 255);
                            }
                        }
                    }
                }
                //} else {
                //    if (tradeResultItems.length !== 0) {
                //        for (var currentItem = 0; currentItem < tradeResultItems.length; currentItem++) {
                //            mp.game.graphics.drawSprite("itemimages", tradeResultItems[currentItem][0].toLowerCase(), tradeGrid[parseInt(tradeResultItems[currentItem][4] - 1)][0], tradeGrid[parseInt(tradeResultItems[currentItem][4] - 1)][1], spriteScaleX, spriteScaleY, 0, 255, 255, 255, 255);
                //            mp.game.graphics.drawText("(~y~" + tradeResultItems[currentItem][3] + "~s~)", [tradeGrid[parseInt(tradeResultItems[currentItem][4] - 1)][0] + (sizeMul / 2) - 0.008, tradeGrid[parseInt(tradeResultItems[currentItem][4] - 1)][1] + 0.05], {
                //                font: 0,
                //                color: [255, 255, 255, 255],
                //                scale: [0.25, 0.25],
                //                outline: true,
                //            });
                //        }
                //    }
                //}

                mp.game.graphics.drawText("Handel mit ~y~" + tradePartner + " ~s~ für ~g~ " + tradePrize + "$", [rxC, 0.81], {
                    font: 7,
                    color: [112, 128, 144, 254],
                    scale: [0.6, 0.6],
                    outline: true,
                    centre: false
                });
                mp.game.graphics.set2dLayer(4);
                if (tradeConfirm === false) {
                    mp.game.graphics.drawSprite("itemimages", "box", tradeBoxPos[0], tradeBoxPos[1], 0.02, 0.035, 0, 255, 255, 255, 255);
                } else {
                    mp.game.graphics.drawSprite("itemimages", "boxticked", tradeBoxPos[0], tradeBoxPos[1], 0.02, 0.035, 0, 255, 255, 255, 255);
                }
                mp.game.graphics.drawSprite("itemimages", "dollar", tradeBoxPos[0] - 0.025, tradeBoxPos[1], 0.02, 0.035, 0, 255, 255, 255, 255);

                if (isMouseOverTradeDollar(pos[0], pos[1])) {
                    mp.game.graphics.drawText("~g~ Preis festlegen", [pos[0] / screenX, pos[1] / screenY - 0.033], {
                        font: 4,
                        color: [255, 255, 255, 255],
                        scale: [0.5, 0.5],
                        outline: true,
                        centre: false
                    });
                }
                if (isMouseOverTradeBox(pos[0], pos[1])) {
                    mp.game.graphics.drawText("~g~Handelsanfrage absenden", [pos[0] / screenX, pos[1] / screenY - 0.033], {
                        font: 4,
                        color: [255, 255, 255, 255],
                        scale: [0.5, 0.5],
                        outline: true,
                        centre: false
                    });
                }

                mp.game.graphics.set2dLayer(5);
                if (isMouseOverTradeItem(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);

                    hoverItemP = [tradeItems[hoverItem][0], tradeItems[hoverItem][1], tradeItems[hoverItem][2], tradeItems[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,
                        centre: false
                    });

                    //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,
                        centre: false
                    });

                    //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,
                        centre: false
                    });
                }                     
            }

            

            ////--------------------------------------------------------------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
            //mp.game.graphics.drawText((pos[0] / screenX).toFixed(3) + " / " + (pos[1] / screenY).toFixed(3) + "   " + tradeItems.length, [pos[0] / screenX, pos[1] / screenY - 0.02], {
            //    font: 4,
            //    color: [255, 255, 255, 255],
            //    scale: [0.4, 0.4],
            //    outline: true,
            //});
            ////----------------------------------------------------------DEBUG END
        }
        qw = 0;
        if (showAdmin === true) {
            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,
                centre: false
            });

            //SLOTS [RECHTECKE] [SLOTZAHLEN]
            for (slots = 0; slots < grid.length; slots++) {
                mp.game.graphics.drawRect(grid[slots][0], grid[slots][1], sizeMulx, sizeMuly, 112, 128, 144, 254);
                mp.game.graphics.drawText(tempSlot = slots + 1, [grid[slots][0] - sizeMulxHalf + 0.006, grid[slots][1] - (sizeMulxHalf * aspectRatioFactor)], {
                    font: 7,
                    color: [255, 69, 0, 254],
                    scale: [0.3, 0.3],
                    outline: true,
                    centre: false
                });
            }

            mp.game.graphics.set2dLayer(3);
            //SPRITES + ITEMANZAHL
            for (currentItem = 0; currentItem < items.length; currentItem++) {
                if (items[currentItem][4] !== "-1") {
                    mp.game.graphics.drawSprite("itemimages", items[currentItem][0].toLowerCase(), grid[items[currentItem][4] - 1][0], grid[items[currentItem][4] - 1][1], spriteScaleX, spriteScaleY, 0, 255, 255, 255, 255);
                    mp.game.graphics.drawText("(~y~" + items[currentItem][3] + "~s~)", [grid[items[currentItem][4] - 1][0] + sizeMulxHalf - 0.008, grid[items[currentItem][4] - 1][1] + 0.05], {
                        font: 0,
                        color: [255, 255, 255, 255],
                        scale: [0.25, 0.25],
                        outline: true,
                        centre: false
                    });
                }
            }

            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);

                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,
                    centre: false
                });

                //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,
                    centre: false
                });

                //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,
                    centre: false
                });
            }

            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) {

        var x, y, a, b, c, s, invSlot;
        x = cX / screenX;
        y = cY / screenY;
        
        if (dragItem === null) {
            for (s = 0; s < 20; s++) {
                a = grid[s][0] - x;
                b = grid[s][1] - y;
                c = Math.sqrt(a * a + b * b);
                invSlot = (s + 1);
                if (c < sizeMulxHalf) {
                    for (var i = 0; i < items.length; i++) {
                        if (parseInt(items[i][4]) === invSlot) {
                            hoverItem = i;
                            return true;
                        }
                    }
                }
            }
        } else {
            if (itemRadial === false) {               
                for (s = 0; s < 20; s++) {
                    a = grid[s][0] - x;
                    b = grid[s][1] - y;
                    c = Math.sqrt(a * a + b * b);
                    invSlot = (s + 1);
                    if (c < sizeMulxHalf) {
                        for (i = 0; i < items.length; i++) {
                            if (parseInt(items[i][4]) === invSlot) {
                                hoverGrid = s;
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    function isMouseOverTradeItem(cX, cY) {

        if (dragItem === null && isTrading) {

            var x = cX / screenX;
            var y = cY / screenY;
            var a;
            var b;
            var c;

            for (var s = 0; s < 5; s++) {
                a = tradeGrid[s][0] - x;
                b = tradeGrid[s][1] - y;
                c = Math.sqrt(a * a + b * b);

                var invSlot = (s + 1);

                if (c < sizeMulxHalf) {
                    for (var i = 0; i < tradeItems.length; i++) {
                        if (parseInt(tradeItems[i][4]) === invSlot) {
                            hoverItem = i;
                            return true;
                        }
                    }
                }
            }
        }
    }

    function isMouseOverFreeSlot(cX2, cY2) {

        var x = cX2 / screenX;
        var y = cY2 / screenY;
        var isItemOnSlot = 0;

        for (var s = 0; s < 20; s++) {
            var invSlot = (s + 1);

            if (x > grid[s][0] - sizeMulxHalf && x < grid[s][0] + sizeMulxHalf && y > grid[s][1] - sizeMulxHalf * aspectRatioFactor && y < grid[s][1] + sizeMulxHalf * aspectRatioFactor) {
                for (var i = 0; i < items.length; i++) {
                    if (parseInt(items[i][4]) === invSlot) {
                        isItemOnSlot++;
                    }
                }
                if (isItemOnSlot === 0) {
                    actFreeSlot = s + 1;
                    return true;
                }
            }
        }
    }

    function isMouseOverFreeTradeSlot(cX2, cY2) {

        if (tradeConfirm === false) {
            var x = cX2 / screenX;
            var y = cY2 / screenY;
            var isItemOnSlot = 0;

            for (var s = 0; s < 5; s++) {
                var invSlot = (s + 1);

                if (x > tradeGrid[s][0] - sizeMulxHalf && x < tradeGrid[s][0] + sizeMulxHalf && y > tradeGrid[s][1] - sizeMulxHalf * aspectRatioFactor && y < tradeGrid[s][1] + sizeMulxHalf * aspectRatioFactor) {
                    for (var i = 0; i < tradeItems.length; i++) {
                        if (parseInt(tradeItems[i][4]) === invSlot) {
                            isItemOnSlot++;
                        }
                    }
                    if (isItemOnSlot === 0) {
                        actFreeTradeSlot = s + 1;
                        return true;
                    }
                }
            }
        }
    }

    function isItemOverSameItem(cX2, cY2) {

        if (dragItem !== null && items.length > 0) {
            var x = cX2 / screenX;
            var y = cY2 / screenY;

            for (var s = 0; s < 20; s++) {
                var invSlot = (s + 1);

                if (x > grid[s][0] - sizeMulxHalf && x < grid[s][0] + sizeMulxHalf && y > grid[s][1] - sizeMulxHalf * aspectRatioFactor && y < grid[s][1] + sizeMulxHalf * aspectRatioFactor) {

                    for (var i = 0; i < items.length; i++) {
                        if (dragTradeItem === false) {
                            if (items[dragItem][0] === items[i][0] && parseInt(items[i][4]) === invSlot && items[hoverItem][4] !== items[i][4]) {
                                stackToItem = i;
                                return true;
                            }
                        } else {
                            if (tradeItems[dragItem][0] === items[i][0] && parseInt(items[i][4]) === invSlot) {
                                stackToItem = i;
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }

    function isItemOverSameTradeItem(cX2, cY2) {

        if (dragItem !== null && tradeItems.length > 0) {
            var x = cX2 / screenX;
            var y = cY2 / screenY;
            for (var s = 0; s < 5; s++) {
                var invSlot = (s + 1);

                if (x > tradeGrid[s][0] - sizeMulxHalf && x < tradeGrid[s][0] + sizeMulxHalf && y > tradeGrid[s][1] - sizeMulxHalf * aspectRatioFactor && y < tradeGrid[s][1] + sizeMulxHalf * aspectRatioFactor) {

                    for (var i = 0; i < tradeItems.length; i++) {
                        if (dragTradeItem === false) {
                            if (items[dragItem][0] === tradeItems[i][0] && parseInt(tradeItems[i][4]) === invSlot) {
                                stackToTradeItem = i;
                                return true;
                            }
                        } else {
                            if (tradeItems[dragItem][0] === tradeItems[i][0] && parseInt(tradeItems[i][4]) === invSlot && tradeItems[hoverItem][4] !== tradeItems[i][4]) {
                                stackToTradeItem = i;
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }

    function isMouseOverX(cX2, cY2) {
        if (showAdmin) {
            var x = cX2 / screenX;
            var y = cY2 / screenY;

            if (x > closePos[0] - 0.01 && x < closePos[0] + 0.01 && y > closePos[1] - 0.0175 && y < closePos[1] + 0.0175) {
                return true;
            }
        }
    }

    function isMouseOverTradeBox(cX2, cY2) {
        if (show && tradeConfirm === false) {
            var x = cX2 / screenX;
            var y = cY2 / screenY;

            if (x > tradeBoxPos[0] - 0.01 && x < tradeBoxPos[0] + 0.01 && y > tradeBoxPos[1] - 0.0175 && y < tradeBoxPos[1] + 0.0175) {
                return true;
            }
        }
    }

    function isMouseOverTradeDollar(cX2, cY2) {
        if (show && tradeConfirm === false) {
            var x = cX2 / screenX;
            var y = cY2 / screenY;

            if (x > (tradeBoxPos[0] - 0.025) - 0.01 && x < (tradeBoxPos[0] - 0.025) + 0.01 && y > tradeBoxPos[1] - 0.0175 && y < tradeBoxPos[1] + 0.0175) {
                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;
            }
        }
    }


    //Mausklick Events
    mp.events.add('click', (x, y, upOrDown, leftOrRight, relativeX, relativeY, worldPosition, hitEntity) => {

        if (show) {
            //LINKE MAUSTASTE
            //RUNTER
            if (upOrDown === "down" && leftOrRight === "left" && mouseLDown === false && mouseRDown === false) {

                mouseLDown = true;

                //Wenn Maus über grünen Haken
                if (isTrading && isMouseOverTradeBox(x, y) && tradePrize > 0) {
                    tradeConfirm = true;
                    mp.events.callRemote('sendTradeItemsToPartner', JSON.stringify(tradeItems), tradePrize, tradePartner);
                }

                //Wenn Maus über Dollar Zeichen
                if (isTrading && isMouseOverTradeDollar(x, y)) {
                    var tradeMoney = new InputHelper("Wie viel $ möchtest du für deine Items haben?", globalData);
                    tradeMoney.show();
                    tradeMoney.getValue((data) => {
                        var amount = parseInt(data);
                        if (isNaN(amount) || amount < 0) {
                            mp.game.graphics.notify('~r~Du musst eine Zahl größer als 0 eingeben!');
                            return;
                        }
                        tradePrize = amount;
                    });
                }
                
                //Wenn Maus über Item
                if (isMouseOverItem(x, y) && dragItem === null && itemRadial === false) {
                    dragItem = hoverItem;
                    oldDragSlot = items[dragItem][4];
                    items[dragItem][4] = "-1";
                    dragTradeItem = false;
                }
                //wenn Maus über Radialmenü
                if (ifMouseSelectRadial(x, y)) {
                    switch (radialSelect) {
                        case "up":
                            var dropInput = new InputHelper("Wie viel Items möchtest du wegwerfen?", globalData);
                            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 (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], 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;
                    }
                }
                //Wenn Maus über Tradeitem
                if (isMouseOverTradeItem(x, y) && dragItem === null && itemRadial === false && tradeConfirm === false) {
                    dragItem = hoverItem;
                    oldDragSlot = tradeItems[dragItem][4];
                    tradeItems[dragItem][4] = "-1";
                    dragTradeItem = true;
                }
            }

            //HOCH
            if (upOrDown === "up" && leftOrRight === "left" && mouseLDown === true && itemRadial === false) {

                mouseLDown = false;

                if (dragItem !== null) {
                    var newAmount;

                    //wenn Maus über freien Slot
                    if (isMouseOverFreeSlot(x, y)) {
                        if (dragTradeItem === false) {
                            items[dragItem][4] = actFreeSlot;
                        } else {
                            items.push([tradeItems[dragItem][0], tradeItems[dragItem][1], tradeItems[dragItem][2], tradeItems[dragItem][3], actFreeSlot.toString(), tradeItems[dragItem][5]]);
                            tradeItems.splice(dragItem, 1);                           
                        }
                        syncCount++;
                        mp.events.callRemote('saveInventory', JSON.stringify(items));
                        oldDragSlot = null;
                        dragItem = null;
                        hoverItem = null;
                    } else if (isItemOverSameItem(x, y)) {
                        if (dragTradeItem === false) {
                            newAmount = parseInt(items[stackToItem][3]) + parseInt(items[dragItem][3]);
                            items[stackToItem][3] = newAmount.toString();
                            items[dragItem][4] = "-1";
                        } else {
                            newAmount = parseInt(items[stackToItem][3]) + parseInt(tradeItems[dragItem][3]);
                            items[stackToItem][3] = newAmount.toString();
                            tradeItems.splice(dragItem, 1);
                        }
                        syncCount++;
                        mp.events.callRemote('saveInventory', JSON.stringify(items));
                        oldDragSlot = null;
                        dragItem = null;
                        hoverItem = null;
                    } else if (isItemOverSameTradeItem(x, y)) {
                        if (dragTradeItem === false) {
                            newAmount = parseInt(tradeItems[stackToTradeItem][3]) + parseInt(items[dragItem][3]);
                            tradeItems[stackToTradeItem][3] = newAmount.toString();
                            items[dragItem][4] = "-1";
                        } else {
                            newAmount = parseInt(tradeItems[stackToTradeItem][3]) + parseInt(tradeItems[dragItem][3]);
                            tradeItems[stackToTradeItem][3] = newAmount.toString();
                            tradeItems[dragItem][4] = "-1";
                        }
                        syncCount++;
                        mp.events.callRemote('saveInventory', JSON.stringify(items));
                        oldDragSlot = null;
                        dragItem = null;
                        hoverItem = null;
                    } else if (isMouseOverFreeTradeSlot(x, y)) {
                        if (dragTradeItem === false) {
                            tradeItems.push([items[dragItem][0], items[dragItem][1], items[dragItem][2], items[dragItem][3], actFreeTradeSlot.toString(), items[dragItem][5]]);
                            items.splice(dragItem, 1);
                        } else {
                            tradeItems[dragItem][4] = actFreeTradeSlot;
                        }
                        syncCount++;
                        mp.events.callRemote('saveInventory', JSON.stringify(items));
                        oldDragSlot = null;
                        dragItem = null;
                        hoverItem = null;
                    } else {
                        if (dragTradeItem === false) {
                            items[dragItem][4] = oldDragSlot;
                        } else {
                            tradeItems[dragItem][4] = oldDragSlot;
                        }
                        oldDragSlot = null;
                        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]--;
                    dragTradeItem = false;
                } else if (isMouseOverTradeItem(x, y) && dragItem === null && tradeConfirm === false) {
                    dragItem = hoverItem;
                    oldDragSlot = tradeItems[hoverItem][4];
                    bufferItem = [tradeItems[hoverItem][0], tradeItems[hoverItem][1], tradeItems[hoverItem][2], tradeItems[hoverItem][3], tradeItems[hoverItem][4], tradeItems[hoverItem][5]];
                    tradeItems[hoverItem][3]--;
                    dragTradeItem = true;
                }
            }

            //HOCH
            if (upOrDown === "up" && leftOrRight === "right" && mouseRDown === true && itemRadial === false) {
                mouseRDown = false;
                if (Date.now() - clickTime < 100 && isMouseOverItem(x, y)) {
                    clickedItem = hoverItem;
                    items[hoverItem][3]++;
                    itemRadial = true;
                    hoverItem = null;
                    dragItem = null;
                    clickTime = null;
                } else {
                    if (dragItem !== null) {
                        if (isMouseOverFreeSlot(x, y)) {
                            if (dragTradeItem === false) {
                                items.push([items[dragItem][0], items[dragItem][1], items[dragItem][2], "1", actFreeSlot.toString(), "-1"]);
                                if (items[hoverItem][3] === 0) {
                                    items[hoverItem][4] = "-1";
                                    items.splice(hoverItem, 1);
                                }
                            } else {
                                items.push([tradeItems[dragItem][0], tradeItems[dragItem][1], tradeItems[dragItem][2], "1", actFreeSlot.toString(), "-1"]);
                                if (tradeItems[hoverItem][3] === 0) {
                                    tradeItems.splice(hoverItem, 1);
                                }
                            }
                            syncCount++;
                            mp.events.callRemote('saveInventory', JSON.stringify(items));
                            oldDragSlot = null;
                            dragItem = null;
                            hoverItem = null;
                        } else if (isItemOverSameItem(x, y)) {
                            items[stackToItem][3]++;
                            if (dragTradeItem === false) {
                                if (items[hoverItem][3] === 0) {
                                    items[hoverItem][4] = "-1";
                                }
                            } else {
                                if (tradeItems[hoverItem][3] === 0) {
                                    tradeItems.splice(hoverItem, 1);
                                }
                            }
                            syncCount++;
                            mp.events.callRemote('saveInventory', JSON.stringify(items));
                            bufferItem = null;
                            dragItem = null;
                            hoverItem = null;
                            oldDragSlot = null;
                        } else if (isItemOverSameTradeItem(x, y)) {
                            tradeItems[stackToTradeItem][3]++;
                            if (dragTradeItem === false) {
                                if (items[hoverItem][3] === 0) {
                                    items[hoverItem][4] = "-1";
                                }
                            } else {
                                if (tradeItems[hoverItem][3] === 0) {
                                    tradeItems[hoverItem][4] = "-1";
                                }
                            }
                            syncCount++;
                            mp.events.callRemote('saveInventory', JSON.stringify(items));
                            oldDragSlot = null;
                            bufferItem = null;
                            dragItem = null;
                            hoverItem = null;
                        } else if (isMouseOverFreeTradeSlot(x, y)) {
                            if (dragTradeItem === false) {
                                tradeItems.push([items[dragItem][0], items[dragItem][1], items[dragItem][2], "1", actFreeTradeSlot.toString(), "-1"]);
                                if (items[hoverItem][3] === 0) {
                                    items[hoverItem][4] = "-1";
                                }
                            } else {
                                tradeItems.push([tradeItems[dragItem][0], tradeItems[dragItem][1], tradeItems[dragItem][2], "1", actFreeTradeSlot.toString(), "-1"]);
                                if (tradeItems[hoverItem][3] === 0) {
                                    tradeItems[hoverItem][4] = "-1";
                                }
                            }
                            syncCount++;
                            mp.events.callRemote('saveInventory', JSON.stringify(items));
                            oldDragSlot = null;
                            dragItem = null;
                            hoverItem = null;
                        } else {
                            if (dragTradeItem === false) {
                                items[hoverItem][3]++;
                            } else {
                                tradeItems[hoverItem][3]++;
                            }
                            oldDragSlot = null;
                            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);
                } else 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;
                }
            }

            //RECHTE MAUSTASTE
            //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];
                }
            }           
        }
    });
}