Lua脚本的问题

Lua脚本的问题,lua,garrys-mod,Lua,Garrys Mod,我真的希望我就在这里,因为在discord服务器上,没有人出于某种原因想帮助我 我们为一款名为Garry's Mod的游戏运行了一个项目,目前正试图让一个“毒气”脚本正常工作 但我们面临以下问题 [ERROR]gamemodes/zombierp/plugins/toxicgas/sh_plugin.lua:44:尝试索引本地“项”(布尔值) 1.IsEquippingGasmask-gamemodes/zombierp/plugins/toxicgas/sh_plugin.lua:44 2.v

我真的希望我就在这里,因为在discord服务器上,没有人出于某种原因想帮助我

我们为一款名为Garry's Mod的游戏运行了一个项目,目前正试图让一个“毒气”脚本正常工作

但我们面临以下问题

[ERROR]gamemodes/zombierp/plugins/toxicgas/sh_plugin.lua:44:尝试索引本地“项”(布尔值)
1.IsEquippingGasmask-gamemodes/zombierp/plugins/toxicgas/sh_plugin.lua:44
2.v-gamemodes/zombierp/plugins/toxicgas/sh_plugin.lua:121
3.未知-gamemodes/helix/gamemode/core/libs/sh_plugin.lua:477
而我是Lua的新手,我只是完全困惑,不知道如何修复它

这是完整的脚本

local config = {
    smokeColor = Color(63, 127, 0),
    smokeAlpha = 110,
    maskItem = "gasmask",
    smokeSpawnerDistance = 100 -- distance between the smoke emitters on the box line
}

local PLUGIN = PLUGIN

PLUGIN.name = "Toxic Gas"
PLUGIN.author = ""
PLUGIN.description = ""

PLUGIN.positions = PLUGIN.positions or {}
PLUGIN.smokeStacks = PLUGIN.smokeStacks or {}

function PLUGIN:LoadData()
    PLUGIN.positions = self:GetData()
    self:UpdateWorldData()
end

function PLUGIN:SaveData()
    self:SetData(PLUGIN.positions)
    self:UpdateWorldData()
end

function PLUGIN:UpdateWorldData()
    SetNetVar("toxicGasPositions", PLUGIN.positions)
    -- global netvar doesn't seem to sync without this
    for _, ply in pairs(player.GetAll()) do
        ply:SyncVars()
    end
end

function PLUGIN:IsEquippingGasmask(ply)
    local character = ply:GetCharacter()
    if not character then return false end

    local inventoryID = character:GetInventory():GetID()
    local inventory = ix.item.inventories[inventoryID]

    for x, items in pairs(inventory.slots) do
        for y, item in pairs(items) do
            if item.uniqueID == config.maskItem
            and item:GetData("equip") == true then
                return true
            end
        end
    end

    return false
end

local function GetBoxLine(min, max)
    local deltaX = math.abs(min.x - max.x)
    local deltaY = math.abs(min.y - max.y)

    local lineStart, lineEnd

    if deltaX < deltaY then
        lineStart = Vector(min.x + (max.x - min.x) / 2, min.y, min.z)
        lineEnd = Vector(min.x + (max.x - min.x) / 2, min.y + (max.y - min.y), min.z)
    else
        lineStart = Vector(min.x, min.y + (max.y - min.y) / 2, min.z)
        lineEnd = Vector(min.x + (max.x - min.x), min.y + (max.y - min.y) / 2, min.z)
    end

    return lineStart, lineEnd
end

if SERVER then
    function PLUGIN:Think()
        for idx, gasBox in pairs(PLUGIN.positions) do
            if PLUGIN.smokeStacks[idx] == nil then
                local min, max = gasBox.min, gasBox.max

                local startSmoke, endSmoke = GetBoxLine(min, max)

                PLUGIN.smokeStacks[idx] = {
                    count = math.floor(startSmoke:Distance(endSmoke) / config.smokeSpawnerDistance),
                    stacks = {}
                }

                for i = 1, PLUGIN.smokeStacks[idx].count do
                    local smoke = ents.Create("env_smokestack")
                    smoke:SetPos(startSmoke + (endSmoke - startSmoke):GetNormalized() * (i) * config.smokeSpawnerDistance)
                    smoke:SetKeyValue("InitialState", "1")
                    smoke:SetKeyValue("WindAngle", "0 0 0")
                    smoke:SetKeyValue("WindSpeed", "0")
                    smoke:SetKeyValue("rendercolor", tostring(config.smokeColor))
                    smoke:SetKeyValue("renderamt", tostring(config.smokeAlpha))
                    smoke:SetKeyValue("SmokeMaterial", "particle/particle_smokegrenade.vmt")
                    smoke:SetKeyValue("BaseSpread", tostring(config.smokeSpawnerDistance))
                    smoke:SetKeyValue("SpreadSpeed", "10")
                    smoke:SetKeyValue("Speed", "32")
                    smoke:SetKeyValue("StartSize", "32")
                    smoke:SetKeyValue("EndSize", "32")
                    smoke:SetKeyValue("roll", "8")
                    smoke:SetKeyValue("Rate", "64")
                    smoke:SetKeyValue("JetLength", tostring(max.z - min.z))
                    smoke:SetKeyValue("twist", "6")
                    smoke:Spawn()
                    smoke:Activate()
                    smoke.Think = function()
                        if PLUGIN.positions[idx] == nil then
                            smoke:Remove()
                        end
                    end
                    PLUGIN.smokeStacks[idx].stacks[i] = smoke
                end
            end
        end

        for _, ply in pairs(player.GetAll()) do
            local pos = ply:EyePos()
            if not ply:Alive() then continue end

            local canBreathe = false
            
            if not canBreathe then
                canBreathe = self:IsEquippingGasmask(ply)
            end

            if not canBreathe then
                for _, gasBox in pairs(PLUGIN.positions) do
                    if pos:WithinAABox(gasBox.min, gasBox.max) then
                        ply.nextGasDamage = ply.nextGasDamage or CurTime()

                        if CurTime() >= ply.nextGasDamage then
                            ply.nextGasDamage = CurTime() + .75
                            ply:TakeDamage(6)
                            ix.util.Notify("You are choking. You need a gas mask.", ply)
                        end

                        break
                    end
                end
            end
        end
    end
end

if CLIENT then
    -- toggles showing toxic gas boxes when in noclip/observer
    CreateConVar("ix_toxicgas_observer", "0", FCVAR_ARCHIVE)

    local function IsInRange(min, max, scale)
        local localPos = LocalPlayer():GetPos()

        local distance = min:Distance(max)

        if localPos:Distance(min + ((max - min) / 2)) <= distance * scale then
            return true
        end

        return false
    end

    function PLUGIN:PostDrawTranslucentRenderables()
        local toxicGasPositions = GetNetVar("toxicGasPositions")

        if toxicGasPositions == nil then return end

        for _, gasBox in pairs(toxicGasPositions) do
            local min, max = gasBox.min, gasBox.max

            if not IsInRange(min, max, 3) then continue end

            local observerCvar = GetConVar("ix_toxicgas_observer")

            if LocalPlayer():IsAdmin()
            and LocalPlayer():GetMoveType() == MOVETYPE_NOCLIP
            and observerCvar and observerCvar:GetBool() then
                render.DrawWireframeBox(min, Angle(), Vector(0, 0, 0), max - min, Color(142, 222, 131, 255), false)
                local startSmoke, endSmoke = GetBoxLine(min, max)
                render.DrawLine(startSmoke, endSmoke, Color(0, 255, 0), false)
            end
        end
    end

    function PLUGIN:HUDPaint()
        -- this is an FPS killer tbh
        --[[
        local toxicGasPositions = game.GetWorld():GetNetVar("toxicGasPositions")

        if toxicGasPositions == nil then return end

        local inToxicGas = false
        local center
        local cornerDist

        for _, gasBox in pairs(toxicGasPositions) do
            local min, max = gasBox.min, gasBox.max
            center = min + ((max - min) / 2)
            cornerDist = min:Distance(max)

            if LocalPlayer():EyePos():WithinAABox(min, max) then 
                inToxicGas = true
                continue 
            end
        end

        if inToxicGas then
            local isEquippingGasmask = self:IsEquippingGasmask(LocalPlayer())

            local distance = LocalPlayer():EyePos():Distance(center)

            ix.util.DrawBlurAt(0, 0, ScrW(), ScrH(), 1, 0.2, isEquippingGasmask and 50 or 255)
        end
        ]]
    end
end

ix.command.Add("AddToxicGas", {
    description = "Adds a toxic gas box from where you're standing and where you're looking at.",
    adminOnly = true,
    OnRun = function(self, client)
        local pos = client:GetPos()
        
        local tr = client:GetEyeTrace()
        if not tr then return end
        
        local hitPos = tr.HitPos

        table.insert(PLUGIN.positions, {
            min = pos, max = hitPos
        })

        PLUGIN:SaveData()

        return "Added toxic gas."
    end
})

ix.command.Add("RemoveToxicGas", {
    description = "Removes the closest toxic gas point relative to you.",
    adminOnly = true,
    OnRun = function(self, client)
        local closestDistance = -1
        local closestIndex = -1
        
        for idx, gasBox in pairs(PLUGIN.positions) do
            local min, max = gasBox.min, gasBox.max

            local center = min + ((max - min) / 2)

            local distance = client:GetPos():Distance(center) 
            if closestDistance == -1 or distance < closestDistance then
                closestDistance = distance
                closestIndex = idx
            end
        end

        if closestIndex ~= -1 then
            table.remove(PLUGIN.positions, closestIndex)

            if PLUGIN.smokeStacks[closestIndex] then
                for k, v in pairs(PLUGIN.smokeStacks[closestIndex].stacks) do
                    v:Remove()
                end
                table.remove(PLUGIN.smokeStacks, closestIndex)
            end
            
            PLUGIN:SaveData()

            return "Removed 1 toxic gas box."
        else
            return "Could not find any toxic gas to remove!"
        end
    end
})

本地配置={
smokeColor=颜色(63127,0),
α=110,
maskItem=“防毒面具”,
SmokeBownerDistance=100——箱线上烟雾发射器之间的距离
}
本地插件=插件
PLUGIN.name=“有毒气体”
PLUGIN.author=“”
PLUGIN.description=“”
PLUGIN.positions=PLUGIN.positions或{}
PLUGIN.smokeStacks=PLUGIN.smokeStacks或{}
函数插件:LoadData()
PLUGIN.positions=self:GetData()
self:UpdateWorldData()
结束
函数插件:SaveData()
self:SetData(PLUGIN.positions)
self:UpdateWorldData()
结束
函数插件:UpdateWorldData()
SetNetVar(“toxicGasPositions”,PLUGIN.positions)
--如果没有这个,全局netvar似乎无法同步
对于u,成对铺设(player.GetAll())do
ply:SyncVars()
结束
结束
功能插件:iSequippingAsmask(ply)
本地字符=ply:GetCharacter()
如果不是字符,则返回false end
本地inventoryID=字符:GetInventory():GetID()
本地库存=ix.item.inventory[库存ID]
对于x,成对的项目(inventory.slots)可以
对于y,项目成对(项目)执行
如果item.uniqueID==config.maskItem
和item:GetData(“装备”)==true然后
返回真值
结束
结束
结束
返回错误
结束
本地函数GetBoxLine(最小值、最大值)
本地deltaX=math.abs(最小x-最大x)
局部增量=数学绝对值(最小y-最大y)
本地行开始,行结束
如果deltaX=ply.nextgsdamage,则
ply.nextgsdamage=CurTime()+0.75
帘布层:损坏(6)
ix.util.Notify(“你噎住了。你需要一个防毒面具。”,ply)
结束
打破
结束
结束
结束
结束
结束
结束
如果是客户,那么
--在noclip/observer中显示有毒气体盒的开关
CreateConVar(“ix_toxicgas_observer”,“0”,FCVAR_存档)
局部函数IsInRange(最小值、最大值、刻度)
localPos=LocalPlayer():GetPos()
本地距离=最小:距离(最大)

如果localPos:Distance(min+((max-min)/2))尝试将y的
项成对(items)替换为
项成对(items)
if item.uniqueID == config.maskItem  
if type(item) ~= 'boolean' and item.uniqueID == config.maskItem  
if type(item) == 'table' and item.uniqueID == config.maskItem