Stevie
Stevie

Reputation: 1

LUA: Using multiple variables in an if-not then statement?

I'm working on a script for a garrysmod server and I'm completly blanking on this, I used to remember but now I can't.

I'm using this block of code,

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 

originally it was if ent:GetModel() ~= "models/mafia2/shubert_taxi.mdl" and that worked fine, however I want to restrict 3 seperate models. Does anybody know how to do this?

Upvotes: 0

Views: 294

Answers (1)

Ali Deym
Ali Deym

Reputation: 142

You can use table.hasValue function:

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
    ....

Upvotes: 1

Related Questions