#MTASA服务器错误:尝试为零值编制索引

问题描述 投票:0回答:1

我真的不知道这是怎么回事。这是我得到的错误:

s_interior_admin.lua:944:尝试索引局部'interiors'

这是我的代码:

local interiors = exports["official-interiors"].getInteriorsList() --/MAXIME
            interior = interiors[tonumber(interiorId)]
            if interior then
                local ix = interior[2]
                local iy = interior[3]
                local iz = interior[4]
                local optAngle = interior[5]
                local interiorw = interior[1]

                local rot = getPedRotation(thePlayer)
                local id = SmallestID()
                local query = mysql:query_free("INSERT INTO interiors SET creator='"..getElementData( thePlayer, "account:username" ).."', id=" .. id .. ",x='" .. x .. "', y='" .. y .."', z='" .. z .."', type='" .. inttype .. "', owner='" .. owner .. "', locked='" .. locked .. "', cost='" .. cost .. "', name='" .. mysql:escape_string( name) .. "', interior='" .. interiorw .. "', interiorx='" .. ix .. "', interiory='" .. iy .. "', interiorz='" .. iz .. "', dimensionwithin='" .. dimension .. "', interiorwithin='" .. interiorwithin .. "', angle='" .. optAngle .. "', angleexit='" .. rot .. "', createdDate=NOW()")

                if (query) then
                    if tonumber(inttype) == 1 then
                        mysql:query_free("INSERT INTO `interior_business` SET `intID`='"..id.."' ")
                    end

                    outputChatBox("Created Interior with ID " .. id .. ".", thePlayer, 255, 194, 14)
                    exports.logs:dbLog(thePlayer, 4, { "in"..tostring(id) } , "ADDINTERIOR T:".. inttype .." I:"..interiorId.." C:"..cost)
                    reloadOneInterior(id, false, false) 
                    local adminUsername = getElementData(thePlayer, "account:username")
                    local hiddenAdmin = getElementData(thePlayer, "hiddenadmin")
                    local adminTitle = exports.global:getPlayerAdminTitle(thePlayer)

                    if hiddenAdmin == 0 then
                        exports.global:sendMessageToAdmins("[INTERIOR]: "..adminTitle.." ".. getPlayerName(thePlayer):gsub("_", " ").. " ("..adminUsername..") has created Interior #"..id.." with name '"..name.."', type "..inttype..", price: $"..cost..").")
                    else
                        exports.global:sendMessageToAdmins("[INTERIOR]: A hidden admin has created Interior #"..id.." with name '"..name.."', type "..inttype..", price: $"..cost..").")
                    end

                    exports["interior-manager"]:addInteriorLogs(id, commandName.." - id "..interiorId.." - price $"..cost.." - name "..name, thePlayer)

                    return true
                else
                    outputChatBox("Failed to create interior - Invalid characters used in name of the interior.", thePlayer, 255, 0, 0)
                end
            else
                outputChatBox("Failed to create interior - There is no such interior (" .. ( interiorID or "??" ) .. ").", thePlayer, 255, 0, 0)
            end
        end
    end
end
lua mta
1个回答
0
投票
exports["official-interiors"].getInteriorsList() --/MAXIME

返回nil

因此

local interiors = exports["official-interiors"].getInteriorsList() --/MAXIME
interior = interiors[tonumber(interiorId)]

导致错误,因为不允许索引nil值。

© www.soinside.com 2019 - 2024. All rights reserved.