Checking if player has one of the SteamID's saved on a table.
11 replies, posted
local users ={ "SteamID 1", "SteamID 2", "SteamID 3" }
local function checkuser()
for i, table.Count( users )
if ply:SteamID(users[i]) then
Print ("The user is in the list!")
break
else
Print ("The user is not in the list!")
end
end
I was thinking on something like this, but it doesent works. The brak is for stopping the loop once the user is found on the table, if anyone has an idea please comment.
if (ply:SteamID() == users[i]) then
instead of
if ply:SteamID(users[i]) then
It didnt worked, heres a screenshot of my code.
local ONDUTYUserwhitelist = { "EXAMPLE", }
local function isuserwhitelist() --White-list players
for i, table.Count( ONDUTYUserwhitelist )
if ply:SteamID() == ONDUTYUserwhitelist[i] then
--Do nothing, player is in users white-list
PrintMessage( HUD_PRINTTALK, "white-listed" )
break --Stop at this step, dont run further checks
else
PrintMessage( HUD_PRINTTALK, "Not white-listed" )
isplayerimmune() --Check immunity next
end
end
end
https://files.facepunch.com/forum/upload/244726/bbd1216c-d08a-4e47-8b0a-792ac96d638e/1.jpg
https://files.facepunch.com/forum/upload/244726/746ebbeb-2f44-4fa9-a1e7-703267f39081/2.jpg
This is what I believe is a much more efficient way doing this
-- we set the key as the steam id so that all we have to do is insert it as a key and see if
-- it returns the contained "true"
local table = {["SteamID 1"] = true, ["SteamID 2"] = true, ["SteamID 3"] = true}
function checkUser(sid)
return table[sid] == true
end
function printListCheck(sid)
if checkUser(sid) then
Print("The user is in the list!")
else
Print("The user is not in the list!")
end
end
this is the same as:
table["SteamID 4"] = true
Do i have to replace "sid" for ply:GetSteamID?
Yes
I cant get it working
What's the context for the code? When should it check if the player is on the list? When the player joins the server, perhaps?
Could you explain what specifically do you not understand and cannot get to work? Can't guess what that is
I do believe using the method below is a lot faster and more efficient when checking the given table.
[CODE]
local users ={
["SteamID 1"] = true,
["SteamID 2"] = true,
["SteamID 3"] = true
}
if users[Player:SteamID()] then
Player:ChatPrint( tostring(Player:SteamID()) .. " exists inside the table!")
else
Player:ChatPrint( tostring(Player:SteamID()) .. " seems to not exist anywhere...")
end
[/CODE]
If he can't really just replace those strings, then he might be comparing steamid with steamid64
local table = { "steam id 1", "steam id " }
function checkSteamIDS( ply )
for _, id in pairs( table ) do
if ply:SteamID() == id then
ply:ChatPrint( "Whitelisted" )
break
else
ply:ChatPrint( "Not Whitelisted" )
end
end
end
Sorry, you need to Log In to post a reply to this thread.