Jump to content

Table Creation


ksTakor

Recommended Posts

Hi, i am trying to learn tables but so far no success kk

I wish to learn then I tried to pass this id's and the check if is one of then but i had no success

if not  getElementModel(veh) == 417 or getElementModel(veh) == 593 or getElementModel(veh) == 493 or getElementModel(veh) == 509 or getElementModel(veh) == 487 or getElementModel(veh) == 497 then 

Thanks in advanced

and sorry for the english

Link to comment
  • MTA Team
function containsNumber(what, ...) 
    for index, value in pairs({...}) do 
        if value == what then 
            return true 
        end 
    end 
    return false 
end 
  
if containsNumber(getElementModel(veh), 417, 593, 493, 509, 487, 497) then 
    -- do something 
end 
  

Link to comment

thanks Necktrox

wow, this table is different from what i have seen, I only see tables more like that

local VehiclesID = { 
  {417}, 
  {593}, 
  {493}, 
  {509}, 
  {487}, 
  {497} 
} 

how can i check for the id's in this type of table?

I wish to learn this way too

Link to comment
  • MTA Team

I showed you the (probably) easiest way.

local models = { [417] = true, [593] = true, [493] = true, [509] = true, [487] = true, [497] = true } 
  
if models[getElementModel(veh)] then 
    -- do something 
end 

local models = { 417, 593, 493, 509, 487, 497 } 
local vehmodel = getElementModel(veh) 
  
for index, model in pairs(models) do 
    if vehmodel == model then 
        -- do something 
        break 
    end 
end 
  
function hasModel(vehmodel) 
    for index, model in pairs(models) do 
        if vehmodel == model then 
            return true 
        end 
    end 
    return false 
end 
  
if hasModel(getElementModel(veh)) then 
    -- do something 
end 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...