Command NickName

I am pretty new to Lua, but I am getting a hang of it.
At the moment I have just been testing out Derma and console commands.

I want to take it to a higher level, which for me would be a console command who can target the player to type the nick of.

For example:

concommand.Add( “freeze”, function(ply)
ply:Freeze( true )

So this freeze me when I type freeze in console. I want it to be freeze PlayerName. So I can freeze players by commands.
This would help me with future work, so please help me.

Thank you,

  • Due

concommands have 3 parameters. Player, Command, and Arguments. Player is the person who ran the command, so right now you are freezing
What you will want is to pass the players name in as an argument and then search for the player by name. So something similar to this: (untested! )
concommand.Add( “freeze”, function( ply, cmd, args )
if not args[1] then return end – No argument was passed in for the player name
local name = string.lower( args[1] )
local plyFound = nil
for k, v in pairs( player.GetAll() ) do
if string.find( string.lower( v:Nick() ), name, 1, true ) then
plyFound = v
if not plyFound then
ply:ChatPrint( “Player not found” )
end )

This should get you started but there are some things you’ll need to do. First off, this will freeze the FIRST player found with the specified name. So if you have SW and SWS and you want to freeze SW, it could very will freeze SWS instead as it just picks the first name t finds with the substring SW. You’ll probably want something to count how many people have the specified substring in their name and warn the user accordingly.
Another issue is that if you have a name with a space this will not work as expected. if you type in “freeze George Foreman” it will only search for George, because Foreman is actually a second argument. So you’ll want to concatenate the arguments together and search on that.

I have something on my server which handles all that but this is a learning experience for you, so you should figure that out yourself. The code I posted above should be a good starting point.