• Tables - Check ID?
    5 replies, posted
Hey there, So for example, if I have a table like this: [lua] local table = { ["some steamid"] = "something else", ["some steamid"] = "something else", } [/lua] How could I then do a check, such as table.HasValue() but on the Identifier itself?
[QUOTE=jimbodude;28438516]Hey there, So for example, if I have a table like this: [lua] local table = { ["some steamid"] = "something else", ["some steamid"] = "something else", } [/lua] How could I then do a check, such as table.HasValue() but on the Identifier itself?[/QUOTE] [lua]tbl["some steamid"][/lua]
So, taking that table as an example, if I did [lua] table["some invalid steamid"] [/lua] it would return nil, right? So I could then simply do: [lua] if table[ply:SteamID()] then -- do stuff using the value in the table end [/lua] right?
Yup.
Im sorry if im hijacking your thread here but i have a quick question which is basicly what you are asking. If i did [lua] local table = { ["some steamid"], ["some steamid"], } [/lua] And then [lua] if table[pl:SteamID()] then pl:SetTeam(1337) end [/lua] Would that be correct? (Sorry for sorta stealing your thread, just asking a simular question to make sure im doing this right)
You have to set the value to be something, like a simple true: [lua]local table = { ["some steamid"] = true, ["some steamid"] = true }[/lua] If you have multiple teams, it would probably be better to store the player's team there instead and do this: [lua]local table = { ["some steamid"] = 1337, ["some steamid"] = 1234 } local plteam = table[pl:SteamID()]; if(plteam) then pl:SetTeam(plteam); end[/lua]
Sorry, you need to Log In to post a reply to this thread.