• Kick one specific player!
    10 replies, posted
How do I make this scrpit so it kicks one one player not all of them? [CODE]for _, v in pairs(player.GetAll()) do v:Kick("I don't need to give you a reason!") end[/CODE]
[lua] for _,v in pairs(player.GetAll()) do v:Kick("I don't need to give you a reason!") break end [/lua]
Are you wanting to kick by name or by steamid or just a random person?
Ok the only change made was "break" is that the playername? [editline]10th August 2013[/editline] I want to make it so that it kicks a specific person every time they join the server.
Well I would just ban them but... First you will want to use a for loop on the [url=http://wiki.garrysmod.com/page/player/GetHumans]player.GetHumans[/url] and then for each player object I would recommend checking their [url=http://wiki.garrysmod.com/page/Player/SteamID]SteamID[/url] instead of their nickname. Then if the steamid matches the unwanted players steamid just call whatever player class functions you want on them and break the loop. I would hook this function to [url=http://wiki.garrysmod.com/page/GM/PlayerSpawn]GM:PlayerSpawn[/url] so they get kicked as they spawn. I would highly disdain from using player nicks to kick though. But its a similar process of looping though all the players and calling [url=http://wiki.garrysmod.com/page/Player/Nick]Nick[/url] on each one then call [url=http://wiki.garrysmod.com/page/string/find]string.find[/url] on the players nick to see if it matches. Keep in mind that this will kick anyone that contains the 'needle' search string in their nick.
I know I can ban them but they can ddos the server so I want to make it seem like theres a problem with them connecting to the server.
You wern't specific for what you were asking for so that is what I gave you. "break" simply stops the loop from running any further so with that code, the first value which is the player would be kicked and the loop would stop. With this code i'm just about to post, the key in the table is the SteamID of the player you want to kick from your server when they are authenticated. [lua] local dontAllowJoin = { ["STEAM_0:1:34139937"] = true, ["STEAM_0:1:34139938"] = true } hook.Add("PlayerAuthed", "PlayerAuthed", function(ply, sID, unID) local canJoin = dontAllowJoin[sID] if canJoin then ply:Kick("Server shutting down") end end) [/lua]
So do I just put there steamid In the slots.
[QUOTE=gmanc2;41789884]So do I just put there steamid In the slots.[/QUOTE] [QUOTE]The key in the table is the SteamID of the player you want to prevent from joining your server.[/QUOTE] [lua] local t = { [key] = value } [/lua]
? ok what is the full code? and what do you mean by key cant I just put there steamid in the slots?
[QUOTE=gmanc2;41789978]? ok what is the full code?[/QUOTE] [lua] local dontAllowJoin = { ["PutTheirSteamIDHere"] = true } hook.Add("PlayerAuthed", "PlayerAuthed", function(ply, sID, unID) local canJoin = dontAllowJoin[sID] if canJoin then ply:Kick("Server shutting down") end end) [/lua]
Sorry, you need to Log In to post a reply to this thread.