• Steam ID tables
    34 replies, posted
I'm quite sure this has been asked already but my search doesn't seem to want to work, so here it goes. I would like to do a function for a player if players steam ID is in a defined table. Example thinking code: [lua] local IDs= { "STEAM_0:1:12345678", "STEAM_0:1:87654321" } function example if table(IDs) -- do stuff else pl:ChatPrint( "Not on the list" ) end [/lua]
[lua] local IDs= { "STEAM_0:1:12345678", "STEAM_0:1:87654321" } function Dipshit(steam)// zeh functio! if table.HasValue(IDs, steam) then //checking if it hazzzz // GOODIE! I FOUND IT! can i haz cookie noa? // NO for k,v in pairs(player.GetAll()) do // loop:D v:Kick("SteamID FOUND!") // kick :D end // end loopie end // end ifie end // end zeh functio! [/lua] There you go sire!
Thanks for the help Bromvelieg. Although those comments hurt my eyes really bad :)
[QUOTE=bromvlieg;21382591]local IDs= { "STEAM_0:1:12345678", "STEAM_0:1:87654321" } function Dipshit(steam)// zeh functio! if table.HasValue(IDs, steam) then //checking if it hazzzz // GOODIE! I FOUND IT! can i haz cookie noa? // NO for k,v in pairs(player.GetAll()) do // loop:D v:Kick("SteamID FOUND!") // kick :D end // end loopie end // end ifie end // end zeh functio! There you go sire![/QUOTE] there is no if's to check if the player is the one in the list... right now it kicks all players on the server if someone in the list joins
ohlawd how else could it be accomplished then?
[lua]local IDs= { "STEAM_0:1:12345678", "STEAM_0:1:87654321" } function PlayerSpawn(ply) if table.HasValue(IDs, ply:SteamID()) then ply:Health(200) else ply:ChatPrint( "Not on the list" ) ply:Health(100) end end[/lua] That should work. I wrote it in the chat box, so there is no tabs.
[lua] local IDs= { "STEAM_0:1:12345678", "STEAM_0:1:87654321" } function Dipshit(steam) if table.HasValue(IDs, steam) then for k,v in pairs(player.GetAll()) do if table.HasValue(IDs, v:SteamID()) then v:Kick("SteamID FOUND!") end end end end [/lua] EDIT -- Ninjad :(
[QUOTE=yuriman;21382753]there is no if's to check if the player is the one in the list... right now it kicks all players on the server if someone in the list joins[/QUOTE] You should go more offten to lua school! if table.HasValue(TABLE, VALUE) then that wil check IF the table HAS the value, if so return true Wola! so only IF the table HAS the value, it wil kick all the players, (wich was just a joke of me:P) and sint, your doing it wrong, why loop truw the table, to loop truw the players to loop truw the table!?
Change the kick code to [lua] ply:Kick() [/lua] :ninja:
My thanks to all. [QUOTE=bromvlieg;21383714]You should go more offten to lua school![/QUOTE] what.
[QUOTE=bromvlieg;21383714]You should go more offten to lua school! if table.HasValue(TABLE, VALUE) then that wil check IF the table HAS the value, if so return true Wola! so only IF the table HAS the value, it wil kick all the players, (wich was just a joke of me:P) and sint, your doing it wrong, why loop truw the table, to loop truw the players to loop truw the table!?[/QUOTE] i thought that if you do it with "for" function it will do it for each value in the table..
[QUOTE=101kl;21383853]what.[/QUOTE] was talking to yuriman :P
[lua]function ValidSteamID( steam ) local steamids = { "STEAM1", "STEAM2", } return table.HasValue( steamids, steam ) end[/lua] Derp. Just use that function with whatever you want to do.
of my understanding its like this. the second one is how i would do it. [PHP]local IDs= { "STEAM_0:1:12345678", "STEAM_0:1:87654321" } function Dipshit(steam)// zeh functio! if table.HasValue(IDs, steam) then //checking if it hazzzz // GOODIE! I FOUND IT! can i haz cookie noa? // NO for k,v in pairs(player.GetAll()) do // loop to check witch player thats in the list:D v:Kick("SteamID FOUND!") // will kick all playerr end // end loopie end // end ifie end // end zeh functio! Second code: local IDs= { "STEAM_0:1:12345678", "STEAM_0:1:87654321" } function Dipshit(steam)// zeh functio! if table.HasValue(IDs, steam) then //checking if it hazzzz // GOODIE! I FOUND IT! can i haz cookie noa? // NO for k,v in pairs(player.GetAll()) do // loop to check witch player thats in the list:D if table.HasValue(IDs, v:SteamID()) then v:Kick("SteamID FOUND!") // will kick all playerr end end // end loopie end // end ifie end // end zeh functio! [/PHP]
[QUOTE=Entoros;21383981][lua]function ValidSteamID( steam ) local steamids = { "STEAM1", "STEAM2", } return table.HasValue( steamids, steam ) end[/lua] Derp. Just use that function with whatever you want to do.[/QUOTE] Why are you creating the local table every time you call that function? Shouldn't you make it once outside of the function? [lua]local steamids = { "STEAM1", "STEAM2" } function ValidSteamID(steam) return table.HasValue(steamids, steam) end[/lua]
Yeah, I guess you could do that. I suppose I just don't really like having variables like that floating around.
[QUOTE=bromvlieg;21383714]You should go more offten to lua school! so only IF the table HAS the value, it wil kick all the players, (wich was just a joke of me:P) and sint, your doing it wrong, why loop truw the table, to loop truw the players to loop truw the table!?[/QUOTE] I was only kicking the person which had the steamID in the table. You was kicking everyone, why would that be useful?
-snip- I dont think i need to go in lua school i think you should.
[QUOTE=yuriman;21384162]So i was right?[/QUOTE] Yes, your first one will kick everyone if the SteamID is found and the second one will kick just the player with that steamID.
yeah i just posted it so people could compare. The second one is mine and the first one is his but i added some comments
The damn kick was just some random code jees, And still, why the FUCK are you dubble checking if the player is in the table? you only need to check ONCE if the player is in the table, if so, DO SOEMTHING i kicked all players, just cus he found that guy, its a damn example it can also give every one money, what ever! if table.HasValue < ITS IN THE FUCKING TABLE ply:WatEver() < ACTION
for k,v in pairs(player.GetAll()) do go throw each value in the table... in this case every players. so it will kick every player. Thats why you do a if statement to check if it is at the right value in the table... EDIT: You check the table first to see if the player exists in the table. Couse its just stupid to run something when it isnt there. Then you do the loop to check witch player has the right steamid and then it kicks the player with it. Its that simple Your not checking twice if the player is in the table your checking if the for loop is at the right value.
[url]http://wiki.garrysmod.com/?title=LUA:SQLite_Tutorial[/url] This tutorial may be of use to you.
[QUOTE=yuriman;21386421]for k,v in pairs(player.GetAll()) do go throw each value in the table... in this case every players. so it will kick every player. Thats why you do a if statement to check if it is at the right value in the table... EDIT: You check the table first to see if the player exists in the table. Couse its just stupid to run something when it isnt there. Then you do the loop to check witch player has the right steamid and then it kicks the player with it. Its that simple Your not checking twice if the player is in the table your checking if the for loop is at the right value.[/QUOTE] Notice how i said that the kick was a example of code wich you should put in there No need to put your teacher cap on becouse youve failed, end of disscuson.
It's also better to do this instead: [lua]local steamids = { ["STEAM_1"] = true, ["STEAM_2"] = true } function IsIDOnList( steamid ) return steamids[ steamid ] end[/lua] table.HasValue loops through the whole table, table lookups are much faster.
Why has this massive argument sprung from so simple a matter? Use thomasfn's code because he is correct, table indexes are much faster than loops, and /thread.
[QUOTE=bromvlieg;21386566]Notice how i said that the kick was a example of code wich you should put in there No need to put your teacher cap on becouse youve failed, end of disscuson.[/QUOTE] a question why did i even fail? you didnt seem to understand so i explained
[QUOTE=thomasfn;21386625]It's also better to do this instead: local steamids = { ["STEAM_1"] = true, ["STEAM_2"] = true } function IsIDOnList( steamid ) return steamids[ steamid ] end table.HasValue loops through the whole table, table lookups are much faster.[/QUOTE] True, however if it doenst exist it returns nil, not false or true :D
nil is false.
[QUOTE=bromvlieg;21387231]True, however if it doenst exist it returns nil, not false or true :D[/QUOTE] nil will result in false when used in an if statement.
Sorry, you need to Log In to post a reply to this thread.