• "whitelist" code?
    12 replies, posted
Im trying to create a "Whitelist" type of addon, the problem is, it wont return true no matter what. i try to collect the steamids in a table, heres the code: [CODE] Whitelist = { "STEAM_0:0:55864032", "Steam_0:0:0" } function inWhitelist() if ply:SteamID() == Whitelist then return true end end [/CODE] inWhitelist() is a Check function, the real function just creates a white box in the center of the screen if the function returns true.
if table.HasValue( Whitelist, ply:SteamID() ) then return true end What you are checking for is: If SteamID string equals to a table then do shit, and a string will never be equal to a table. [editline]27th August 2014[/editline] Or even [code] function inWhitelist() return table.HasValue( Whitelist, ply:SteamID() ) end[/code]
Isn't HasValue really slow compared to direct access
it isn't really slow, but is slower than doing: [code] local Whitelist = { ["STEAM_0:0:55864032"] = true, ["Steam_0:0:0"] = true } function inWhitelist() return Whitelist[ ply:SteamID() ] end[/code]
That won't work because you're comparing a string to a table. Set each table element to true, then send the SteamID into the table and see if it's true. [editline]27th August 2014[/editline] Ninja'd
Now it keeps being true, even when i comment it out ,_,
[QUOTE=tomhillepille;45815397]Now it keeps being true, even when i comment it out ,_,[/QUOTE] Maybe because your SteamID is in there? Post the code.
i said, "Even when i comment it out" [code] local Whitelist = { --["STEAM_0:0:55864032"] = true, --["Steam_0:0:0"] = true } function inWhitelist() return Whitelist[ ply:SteamID() ] end [/code] [code] local Whitelist = { ["STEAM_0:0:55864032"] = true, ["Steam_0:0:0"] = true } function inWhitelist() return Whitelist[ ply:SteamID() ] end [/code] [editline]27th August 2014[/editline] Somehow it works without being inside {}
[QUOTE=tomhillepille;45815426]i said, "Even when i comment it out" [code] local Whitelist = { --["STEAM_0:0:55864032"] = true, --["Steam_0:0:0"] = true } function inWhitelist() return Whitelist[ ply:SteamID() ] end [/code] [code] local Whitelist = { ["STEAM_0:0:55864032"] = true, ["Steam_0:0:0"] = true } function inWhitelist() return Whitelist[ ply:SteamID() ] end [/code] [editline]27th August 2014[/editline] Somehow it works without being inside {}[/QUOTE] ply isn't valid. You'll want function inWhitelist(ply). [code] local Whitelist = { ["STEAM_0:0:55864032"] = true, ["Steam_0:0:0"] = true } function inWhitelist(ply) return Whitelist[ ply:SteamID() ] end [/code] Then call it with the player as an argument.
An small update, Would it work if i do like for k in pairs? like [code] local whitelist = { "steamidhere" } for k in pairs(whitelist) do if ply:SteamID() == k then --func if in whitelist end [/code]
You are wasting code: [code] local whitelist = { "steamidhere" } if table.HasValue( whitelist, ply:SteamID() ) then --func if in whitelist end [/code]
snip
[QUOTE=circuitbawx;45815372]Isn't HasValue really slow compared to direct access[/QUOTE] It's only bad to use when using hooks that are run ever frame and such. When it is just called once, when someone connects, it's fine and as Robotboy said it is much easier to do that instead of adding trues.
Sorry, you need to Log In to post a reply to this thread.