【问题标题】:LUA: Using multiple variables in an if-not then statement?LUA:在 if-not then 语句中使用多个变量?
【发布时间】:2020-08-24 17:22:22
【问题描述】:

我正在为一个 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("You've chopped a car.")
        end)
    end 

最初它是if ent:GetModel() ~= "models/mafia2/shubert_taxi.mdl",效果很好,但是我想限制 3 个单独的模型。有人知道怎么做吗?

【问题讨论】:

    标签: lua garrys-mod


    【解决方案1】:

    你可以使用table.hasValue函数:

    if ent:IsVehicle() then
        local models = { "models/mafia2/shubert_taxi.mdl", "models/mafia2/parry_bus.mdl", "models/mafia2/smith_200_p_pha.mdl" }
    
        -- Notice the not keyword.
        if not table.hasValue(models, ent:GetModel()) then
        ....
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 2013-03-05
      • 2021-02-02
      • 1970-01-01
      • 2022-06-10
      相关资源
      最近更新 更多