LUA: 在 if-not then 语句中使用多个变量?

我正在为 garrysmod 服务器编写脚本,但我完全忘记了这个,我曾经记得,但现在我记不起来了。

我正在使用以下代码块,

if ent:IsVehicle() then
        if ent:GetModel() ~= { "models/mafia2/shubert_taxi.mdl", "models/mafia2/parry_bus.mdl", "models/mafia2/smith_200_p_pha.mdl" } then
        client:Freeze(true)
        self.Owner:setAction("Chopping", time, function()
            ent:Remove()
            nut.item.spawn("carparts", self:GetPos() + Vector(math.Rand(1,20), math.Rand(1,20),20), nil, Angle(0, 0, 0 ))
            client:Freeze(false)
            self.Owner:notify("你砍了一辆车。")
        end)
    end

最初是 if ent:GetModel() ~= "models/mafia2/shubert_taxi.mdl" ,这可以正常工作,但是我想限制 3 个不同的模型。有人知道如何做到这一点吗?

点赞
用户7652095
用户7652095

你可以使用 table.hasValue 函数:

如果 ent:IsVehicle() then
    local models = { "models/mafia2/shubert_taxi.mdl", "models/mafia2/parry_bus.mdl", "models/mafia2/smith_200_p_pha.mdl" }

    -- 注意 not 关键字。
    如果 not table.hasValue(models, ent:GetModel()) then
    ....
2020-05-10 05:23:13