Freeze a specified player?

I’m pretty new to scripting, so I was wondering…

How would I freeze a specified player?

I know how to create a chat command, I just need to know how to freeze them.

For example: /freeze bob would freeze the user “bob”

http://wiki.garrysmod.com/page/Player/Freeze

Should check the wiki next time, got pretty much everything you’ll ever need on there.

Whoops, I guess I didn’t explain it really well. Sorry.

In that wiki page, the example will freeze every player.

How would you make it so it only freezes the specified player?

In the example of chat commands we get it from the PlayerSay hook, the first argument given to that function is the player who sent the message.



hook.Add( "PlayerSay", "FreezePlayer", function( ply, text, tm)
	if ( text:lower() == "!freeze" ) then
		ply:Freeze()
		return ""
	end
end )


In this case it freezes the player who says “!freeze” in chat.

I know how to freeze yourself, and every player on the server, but how would you freeze a player that’s mentioned in chat?

Untested + This was off the top of my head


 hook.Add( "PlayerSay", "FreezePlayer", function( ply, text, tm )
	if ( string.sub( text, 1, 7 ) == "!freeze" ) then
		local elsa = string.Explode( " ", text )
		for k, v in pairs(player.GetAll()) do
			if v == elsa[2] && !v:IsFrozen() then v:Freeze(true) end
		end
	else return
	end
end )
-- I dont see this working if ply has space in name :D 

So I sat here for a while trying to figure out your problem (spoiler bosnian_cyco’s code doesn’t work) and I realised that ULX (a free script) has this command and many more.



string.right( text, string.len( text ) - 8 )