GLua问题:"GetModel()不是字符串库的一部分"

我需要将darkrp中的物品"spawned_weapon"从点A移动到点B进行升级。但是如果使用以下函数,我会遇到错误:

尝试用坏键索引字符串值('GetModel'不是字符串库的一部分)

点A为local items = ents.FindInBox(fst_pos,scnd_pos)

点B为weapon:SetPos(output)

local items_table = { -- 升级后的随机物品
    "customitem_test1",
    "customitem_test2",
    "customitem_test3",
}

local items = ents.FindInBox(fst_pos,scnd_pos)
for k,v in pairs(items) do
    if IsValid(v) then
        if v:GetClass() == "spawned_weapon" then
            if table.HasValue(WEAPON_SHIELD, v:GetWeaponClass()) then -- 检查输入物品
                item_class = table.Random(items_table)

                print("customitem > " .. item_class)

                -- 创建传送物品
                local weapon = ents.Create("spawned_weapon")

                -- 错误行
                local model = (item_class:GetModel() == "models/weapons/v_physcannon.mdl" and "models/weapons/w_physics.mdl") or item_class:GetModel()
                model = util.IsValidModel(model) and model or "models/weapons/w_rif_ak47.mdl"

                weapon:SetPos(output)
                weapon:SetModel(model)
                weapon:SetSkin(item_class:GetSkin() or 0)
                weapon:SetWeaponClass(item_class:GetClass())
                weapon.nodupe = true
                weapon:Spawn()
            end
        end
    end
end
点赞
用户16234509
用户16234509

你现在正在从表中获取一个随机字符串。

举个例子,你可以通过遍历所有实体,比较实体类并从中获取模型。

2021-11-17 21:50:58