Help with Advanced Chat Commands/Targeting players...

Alright, so I got this problem, this doesn’t seem to want to work…


--[[ Finding Matches ]]
--[[ --Blocked to I can fix it :/--
	function FindPLY(name)

		local matches = {}
		
		for k, v in pairs(player.GetAll() ) do
		
		if ( v:GetName():lower():match( name:lower() ) ) then
		
		table.insert(matches, v)
		
		
		end
		
	end
	
	if ( table.Count(matches) == ) then
	chat.AddText(Color(0, 120, 150), "[Server] ", Color(255, 255, 255), "Sorry! No players matching that name where found! ")
	return false
	end
	
	if (table.Count( matches ) > 1 ) then
	chat.AddText(Color(0, 120, 150), "[Server] ", Color(255, 255, 255), "Sorry! Multiple players found! ")
	return false
	
	end
	
	return matche[1]
	
end
]]--

--[[New Commands]]--
// Blocked out to I can get to fixing it.
	--[[hook.Add( 'playerSay', 'Random', function( ply, text, lsteam )
	
		text = string.lower( text )

		if ( string.sub( text, 0, 9 ) == "!setteam1" ) then
		
			text = string.Explode(" ", text)
			
			local victim = FindPLY( text [2] )
		
			if ( IsValid( victim ) ) then
			
			
			
				if ply:IsAdmin() then victim:ply:SetTeam(3)
				else
				chat.AddText(Color(0, 120, 150), "[Server] ", Color(255, 255, 255), ..ply:Nick().."You don't have the correct permissions to use this command! ")
			end

			return ""
			
		end
		
	end )	

And yes, I know I blocked it out. I was to stop the errors temp.

I put it in init.lua; aka sv_init.

Any ideas?

If it calls error then post that error.

[editline]10th May 2014[/editline]

[lua]–[[ Finding Matches ]]
–[[ --Blocked to I can fix it :/–
function FindPLY(name)

	local matches = {}
	
	for k, v in pairs(player.GetAll() ) do
	
	if ( v:GetName():lower():match( name:lower() ) ) then
	
	table.insert(matches, v)
	
	
	end
	
end

if ( table.Count(matches) == 0) then
BroadcastLua(chat.AddText(Color(0, 120, 150), "[Server] ", Color(255, 255, 255), "Sorry! No players matching that name where found! "))
return false
end

if (table.Count( matches ) > 1 ) then
BroadcastLua(chat.AddText(Color(0, 120, 150), "[Server] ", Color(255, 255, 255), "Sorry! Multiple players found! "))
return false

end

return matches[1]

end
]]–

–[[New Commands]]–
// Blocked out to I can get to fixing it.
[[hook.Add( ‘PlayerSay’, ‘Randomhhhh’, function( ply, text, lsteam )

	text = string.lower( text )

	if ( string.sub( text, 0, 9 ) == "!setteam1" ) then
	
		text = string.Explode(" ", text)
		
		local victim = FindPLY( text [2] )
	
		if ( IsValid( victim ) ) then
		
		
		
			if ply:IsAdmin() then victim:SetTeam(3)
			else
			BroadcastLua(chat.AddText(Color(0, 120, 150), "[Server] ", Color(255, 255, 255), ..ply:Nick().."You don't have the correct permissions to use this command! "))
		end

		return ""
		
	end
	
end )[/lua]

Used your code, and this happens…

[ERROR] gamemodes/swcw/gamemode/init.lua:157: unexpected symbol near ‘)’

  1. unknown - gamemodes/swcw/gamemode/init.lua:0

BroadcastLua needs a string, not Lua, so you need to figure out how to properly escape everything so that it is a string.

A lot of people over-complicate chat commands, here’s something simple: https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_commands/chat_commands.lua.html

Just add console commands from there.