Issue with GLua: "GetModel() is not part of the string library"

134 Views Asked by At

I need upgrade item "spawned_weapon" from darkrp with moving from point A to point B. But I have error if using function:

attempt to index a string value with bad key ('GetModel' is not part of the string library)

Point A is local items = ents.FindInBox(fst_pos, scnd_pos)
Point B is weapon:SetPos(output)

local items_table = { -- radnom item after upgtade
    "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 -- check input items
                item_class = table.Random(items_table)

                print("customitem > " .. item_class)

                -- Create teleported item
                local weapon = ents.Create("spawned_weapon")

                -- ERROR LINE
                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
1

There are 1 best solutions below

0
On

You are currently getting a Random String from a Table. What you could do for example is that you loop through all entities and compare entity classes and get the model from there.