Gamemode: Use console commands (on other players)

Hi guys,
I’m wondering if there is a way I can make a script which makes it so that say I type team_4 in the console,
that effect will happen to another person. Basically, this is to demote/promote a person on my server.
For example, say I created a command called team_n, and did team_n <steamname>
Also, how can I block people from using the same command on my gamemode besides me? That way I don’t have 10 admins on my server :v:

Thanks guys!

[lua]

// serverside script

function FindPlyByName(who)

if who == nil then return false end
who = string.lower(who) // make it lowercase

Found = {}

for _,ply in pairs(player.GetAll()) do
	if string.find(string.lower(ply:Nick()),who) != nil then 
		table.insert(Found,ply) // if the name matches add it to the table
	end
end

if #Found == 0 then // if no players was found
	return false
elseif #Found == 1 then // if there was one match
	return Found[1]
else // if there were more than one match
	return false 
end

Found = nil

end

concommand.Add(“team_4”,function(ply,_,args)

if args[1] == nil then return end // if there is no arguments
if !ply:IsAdmin() then ply:ChatPrint("You are not admin!") return end // if player is not admin then stop the code

local findply = FindPlyByName(args[1]) // find the player by first argument ("team_4 playername")
if findply == false then return end // if the player was not found then stop the code

findply:Kill() // replace this with your demote code.

end)

[/lua]

I tested it, works fine.

Im sorry, but I am not entirely certain as to what this does.
Does this let me type any console command and apply it to another player?
Sorry, I am dumb with lua :pwn:

Follow the comments he added and you should understand it all. If not try reading it all again.

Just run the script serverside, then run “team_4 anyplayername” in console.
Also like brandon said, read all the comments.