0

几天前一切正常,从昨天开始,我的 FiveM 服务器上出现此错误。

所以我知道错误来自jquery,因此我去看了相关文件。我们在报错信息中可以看到,错误在inventory.js文件的第9行和第94行,稍微看一下可以认为Jquery的变量$没有定义是因为调用不好,奇怪的是它一直工作到昨天,但为什么不呢,所以让我们在 html 文件中查看我们的调用是否正确。

当我们查看 html 文件时,我们可以看到 Jquery 在我们的 inventory.js 文件之前被调用,但是 $ 没有定义所以我尝试放置一个 $ (document) .ready (function () {}); 这将包含所有有错误的部分,但这次是 $ of $ (document) 未定义,因此问题不来自那里。

我还尝试更新 Jquery 没有成功,我也尝试更新我的脚本也没有成功。

而且我尝试将 Jquery 放入 Dur 中的时间比放入 CDN 中的时间早,但它再次不起作用。

所以我试图备份它何时工作的备份,以便我可以找到问题所在,但令我遗憾的是备份也没有工作。

如果您认为您可以帮助我,请不要犹豫,我根本不知道该怎么做。

我在下面为您提供所有有用的信息,以更好地理解问题。

问候

var type = "normal";
var disabled = false;

window.addEventListener("message", function (event) {
    if (event.data.action == "display") {
        type = event.data.type
        disabled = false;

        if (type === "normal") { $(".info-div").hide();} 
        
        else if (type === "trunk") { $(".info-div").show();} 
        
        else if (type === "property") { $(".info-div").hide();} 
        
        else if (type === "glovebox") { $(".info-div").show();} 
        
        else if (type === "vault") { $(".info-div").hide();} 
        
        else if (type === "player") { $(".info-div").show();}

        $(".ui").fadeIn();
    } else if (event.data.action == "hide") {
        $("#dialog").dialog("close");
        $(".ui").fadeOut();
        $(".item").remove();
        $("#otherInventory").html("<div id=\"noSecondInventoryMessage\"></div>");
        $("#noSecondInventoryMessage").html(invLocale.secondInventoryNotAvailable);
    } else if (event.data.action == "setItems") {
        inventorySetup(event.data.itemList);

        $('.item').draggable({
            helper: 'clone',
            appendTo: 'body',
            zIndex: 99999,
            revert: 'invalid',
            start: function (event, ui) {
                if (disabled) {
                    return false;
                }

                $(this).css('background-image', 'none');
                itemData = $(this).data("item");

                if (!itemData.canRemove) {
                    $("#drop").addClass("disabled");
                    $("#give").addClass("disabled");
                }

                if (!itemData.usable) {
                    $("#use").addClass("disabled");
                }
            },
            stop: function () {
                itemData = $(this).data("item");

                if (itemData !== undefined && itemData.name !== undefined) {
                    $(this).css('background-image', 'url(\'img/items/' + itemData.name + '.png\'');
                    $("#drop").removeClass("disabled");
                    $("#use").removeClass("disabled");
                    $("#give").removeClass("disabled");
                }
            }
        });
    } else if (event.data.action == "setSecondInventoryItems") {
        secondInventorySetup(event.data.itemList);
    } else if (event.data.action == "setInfoText") {
        $(".info-div").html(event.data.text);
    } else if (event.data.action == "nearPlayers") {
        $("#nearPlayers").html("");

        $.each(event.data.players, function (index, player) {
            $("#nearPlayers").append('<button class="nearbyPlayerButton" data-player="' + player.player + '">' + player.label + ' (' + player.player + ')</button>');
        });

        $("#dialog").dialog("open");

        $(".nearbyPlayerButton").click(function () {
            $("#dialog").dialog("close");
            player = $(this).data("player");
            $.post("http://esx_inventoryhud/GiveItem", JSON.stringify({
                player: player,
                item: event.data.item,
                number: parseInt($("#count").val())
            }));
        });
    }
});

function closeInventory() {
    $.post("http://esx_inventoryhud/NUIFocusOff", JSON.stringify({}));
}

function inventorySetup(items) {
    $("#playerInventory").html("");
    $.each(items, function (index, item) {
        count = setCount(item);

        $("#playerInventory").append('<div class="slot"><div id="item-' + index + '" class="item" style = "background-image: url(\'img/items/' + item.name + '.png\')">' +
            '<div class="item-count">' + count + '</div> <div class="item-name">' + item.label + '</div> </div ><div class="item-name-bg"></div></div>');
        $('#item-' + index).data('item', item);
        $('#item-' + index).data('inventory', "main");
    });
}

function secondInventorySetup(items) {
    $("#otherInventory").html("");
    $.each(items, function (index, item) {
        count = setCount(item);

        $("#otherInventory").append('<div class="slot"><div id="itemOther-' + index + '" class="item" style = "background-image: url(\'img/items/' + item.name + '.png\')">' +
            '<div class="item-count">' + count + '</div> <div class="item-name">' + item.label + '</div> </div ><div class="item-name-bg"></div></div>');
        $('#itemOther-' + index).data('item', item);
        $('#itemOther-' + index).data('inventory', "second");
    });
}

function disableInventory(ms) {
    disabled = true;

    setInterval(function () {
        disabled = false;
    }, ms);
}

function setCount(item) {
    count = item.count

    if (item.limit > 0) {
        count = item.count + " / " + item.limit
    }

    if (item.type === "item_weapon") {
        if (count == 0) {
            count = "";
        } else {
            count = '<img src="img/bullet.png" class="ammoIcon"> ' + item.count;
        }
    }

    if (item.type === "item_account" || item.type === "item_money") {
        count = formatMoney(item.count);
    }

    return count;
}

function formatMoney(n, c, d, t) {
    var c = isNaN(c = Math.abs(c)) ? 2 : c,
        d = d == undefined ? "." : d,
        t = t == undefined ? "," : t,
        s = n < 0 ? "-" : "",
        i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))),
        j = (j = i.length) > 3 ? j % 3 : 0;

    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t);
};

$(document).ready(function () {
    $("#count").focus(function () {
        $(this).val("")
    }).blur(function () {
        if ($(this).val() == "") {
            $(this).val("1")
        }
    });

    $("body").on("keyup", function (key) {
        if (Config.closeKeys.includes(key.which)) {
            closeInventory();
        }
    });

    $('#use').droppable({
        hoverClass: 'hoverControl',
        drop: function (event, ui) {
            itemData = ui.draggable.data("item");
            if (itemData.usable) {
                $.post("http://esx_inventoryhud/UseItem", JSON.stringify({
                    item: itemData
                }));
            }
        }
    });

    $('#give').droppable({
        hoverClass: 'hoverControl',
        drop: function (event, ui) {
            itemData = ui.draggable.data("item");
            if (itemData.canRemove) {
                $.post("http://esx_inventoryhud/GetNearPlayers", JSON.stringify({
                    item: itemData
                }));
            }
        }
    });

    $('#drop').droppable({
        hoverClass: 'hoverControl',
        drop: function (event, ui) {
            itemData = ui.draggable.data("item");
            if (itemData.canRemove) {
                $.post("http://esx_inventoryhud/DropItem", JSON.stringify({
                    item: itemData,
                    number: parseInt($("#count").val())
                }));
            }
        }
    });

    $('#playerInventory').droppable({
        drop: function (event, ui) {
            itemData = ui.draggable.data("item");
            itemInventory = ui.draggable.data("inventory");

            if (type === "trunk" && itemInventory === "second") {
                disableInventory(500);
                $.post("http://esx_inventoryhud/TakeFromTrunk", JSON.stringify({
                    item: itemData,
                    number: parseInt($("#count").val())
                }));
            } else if (type === "property" && itemInventory === "second") {
                disableInventory(500);
                $.post("http://esx_inventoryhud/TakeFromProperty", JSON.stringify({
                    item: itemData,
                    number: parseInt($("#count").val())
                }));
            } else if (type === "glovebox" && itemInventory === "second") {
                disableInventory(500);
                $.post("http://esx_inventoryhud/TakeFromGlovebox", JSON.stringify({
                    item: itemData,
                    number: parseInt($("#count").val())
                }));
            } else if (type === "vault" && itemInventory === "second") {
                disableInventory(500);
                $.post("http://esx_inventoryhud/TakeFromVault", JSON.stringify({
                    item: itemData,
                    number: parseInt($("#count").val())
                }));
            } else if (type === "player" && itemInventory === "second") {
                disableInventory(500);
                $.post("http://esx_inventoryhud/TakeFromPlayer", JSON.stringify({
                    item: itemData,
                    number: parseInt($("#count").val())
                }));
            }
        }
    });

    $('#otherInventory').droppable({ drop: function (event, ui) { itemData = ui.draggable.data("item"); itemInventory = ui.draggable.data("inventory");

    if (type === "trunk" && itemInventory === "main") {
        disableInventory(500);
        $.post("http://esx_inventoryhud/PutIntoTrunk", JSON.stringify({
            item: itemData,
            number: parseInt($("#count").val())
        }));
    } else if (type === "property" && itemInventory === "main") {
        disableInventory(500);
        $.post("http://esx_inventoryhud/PutIntoProperty", JSON.stringify({
            item: itemData,
            number: parseInt($("#count").val())
        }));
    } else if (type === "glovebox" && itemInventory === "main") {
        disableInventory(500);
        $.post("http://esx_inventoryhud/PutIntoGlovebox", JSON.stringify({
            item: itemData,
            number: parseInt($("#count").val())
        }));
    } else if (type === "vault" && itemInventory === "main") {
        disableInventory(500);
        $.post("http://esx_inventoryhud/PutIntoVault", JSON.stringify({
            item: itemData,
            number: parseInt($("#count").val())
        }));
    } else if (type === "player" && itemInventory === "main") {
        disableInventory(500);
        $.post("http://esx_inventoryhud/PutIntoPlayer", JSON.stringify({
            item: itemData,
            number: parseInt($("#count").val())
        }));
    }
}
});

    $("#count").on("keypress keyup blur", function (event) {
        $(this).val($(this).val().replace(/[^\d].+/, ""));
        if ((event.which < 48 || event.which > 57)) {
            event.preventDefault();
        }
    });
});

$.widget('ui.dialog', $.ui.dialog, {
    options: {
        // Determine if clicking outside the dialog shall close it
        clickOutside: false,
        // Element (id or class) that triggers the dialog opening 
        clickOutsideTrigger: ''
    },
    open: function () {
        var clickOutsideTriggerEl = $(this.options.clickOutsideTrigger),
            that = this;
        if (this.options.clickOutside) {
            // Add document wide click handler for the current dialog namespace
            $(document).on('click.ui.dialogClickOutside' + that.eventNamespace, function (event) {
                var $target = $(event.target);
                if ($target.closest($(clickOutsideTriggerEl)).length === 0 &&
                    $target.closest($(that.uiDialog)).length === 0) {
                    that.close();
                }
            });
        }
        // Invoke parent open method
        this._super();
    },
    close: function () {
        // Remove document wide click handler for the current dialog
        $(document).off('click.ui.dialogClickOutside' + this.eventNamespace);
        // Invoke parent close method 
        this._super();
    },
});
<!DOCTYPE html>
<html>

<head>
    <title>ESX INVENTORY HUD BY TRSAK</title>
    <link href="https://fonts.googleapis.com/css?family=Signika" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="css/ui.css">
    <link rel="stylesheet" type="text/css" href="css/jquery-ui.css">
</head>

<body>
    <script src="js/config.js"></script>
    <script src="locales/fr.js"></script>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
    <script src="js/inventory.js"></script>
    <script>
        $(function () {
            $("#dialog").dialog({
                autoOpen: false,
                clickOutside: true
            });
        });
    </script>

    <div class="ui">
        <div class="inventory">
            <div id="playerInventory">
            </div>
            <div id="controls">
                <div class="info-div"></div>
                <div class="controls-div">
                    <input type="number" class="control" id="count" value="1">
                    <div class="control" id="use"></div>
                    <div class="control" id="give"></div>
                    <div class="control" id="drop"></div>
                </div>
            </div>
            <div id="otherInventory">
                <div id="noSecondInventoryMessage">
                </div>
            </div>
        </div>
    </div>

    <div id="dialog">
        <div id="nearPlayers">
        </div>
    </div>

</body>

<script>
    $(document).ready(function () {
        $("#use").html(invLocale.useItem);
        $("#give").html(invLocale.giveItem);
        $("#drop").html(invLocale.dropItem);
        $("#noSecondInventoryMessage").html(invLocale.secondInventoryNotAvailable);
    });
</script>

</html>

在此处输入图像描述

4

0 回答 0