Custom admin "Kick" feature

I’m making a custom admin system and, i can’t get the kick button to work lemme show you what i have so far

[lua]
local Permanent2 = vgui.Create(“DButton”, Kick_Options)
Permanent2:SetSize(289.5, 42)
Permanent2:SetPos(297, 26.5)
Permanent2:SetText(“General Asshole”)
Permanent2.DoClick = function()
RunConsoleCommand(“kick”, DComboBox.GetSelected)
end
[/lua]
Do i need to set up a serverside file for the kick command?
[EDITLINE]8:43[/EDITLINE]
The reason i ask is because i made a server sided file for ban, but then i realized kick is already a command, so i got lost.

[editline]10:10AM[/editline]

Anyone?

You need to make a serverside part. So make a console command serverside and make the button run that console command.

[lua]
concommand.Add(“myadmin_kick”, function(ply, cmd, args) if ply:IsAdmin() then player.GetByUserID(args[1]):Kick(“KICKED MOFO”) end end)[/lua]

Thanks

[EDITLINE]5:04[/EDITLINE]
player.GetByID not player.GetByUserID?

[EDITLINE]5:45[/EDITLINE]
That didn’t work by the way


autorun/server/Hammer_Kick_args.lua:2: attempt to call method 'Kick' (a nil value)

the server sided code I’m using is
[lua]concommand.Add(“GAKICK”, function(ply, cmd, args) if ply:IsAdmin() then player.GetByID(args[1]):Kick(“Stop Being An Asshole”) end end)[/lua]

GetById doesn’t search for a name, it finds the player based on the ID, aka when you type status in console and it says a number before a name.

Then what would i use for getting the players name?

Any ideas?

v:Nick()

**[Player.GetByID

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.GetByID)**

EntIndex, not UserID. :eng101:

You’ll have to make a function for yourself if you want to find a player by his userid.
[lua]
function player.GetByUserID(uid)
for k,v in pairs(player.GetAll()) do
if v:UserID() == uid then return v end
end

return false

end[/lua]

Nah, I want to make one that finds him by his nickname, because I’m using the DComboBox, unless the combobox is just showing my their name but using there ID in the background or something :stuck_out_tongue:

Here ya go.
[lua]
function GetPlayer(Name)
for k, v in pairs(player.GetAll()) do
if (string.Find(v:Name():lower(), Name:lower())) then
return v
end
end
return false
end
[/lua]

[lua]function player.GetByName(name)
for k,v in pairs(player.GetAll()) do
if string.find(v:Nick(), name, 1, true) then
return v
end
end
return false
end[/lua]
It’s the same concept.

[editline]11:43PM[/editline]

Ninja’d

Haha the funny part is both of you are in my friends list, but either way thank you both. NINJA =]

Have you considered the fact that 2 people may have the same name?

Rawr >_<, I guess your right, I could probably go back to kicking by ID…but it’s pretty unlikely that they will have the same name (exactly the same, letter for letter).

Not impossible though. Kicking by ID is better.

Actually I think it is impossible. One person would show up as yakahughes, and the other would show as yakahughes(2).

It is still better to kick by id though, because if there were two people named yakahughes and yakahughes(2), you would probably want to type yaka instead of the entire name, which could kick the wrong person. You could fix this by iterating over all the players and adding the players that have names that match your string inserted into a table, and if the length of the table is not exactly one at the end of the search, error.

I’m sure you can have two names the same. Or, you used to be able too.

Don’t think they can be the exact same. But you can use Invisible characters behind the name so it looks like its the same. (Might be wrong)