Need some help with GM:PlayerSay


I try to write a gamemode and in my init.lua i’ve this:

function GM:PlayerSay( ply, text, team, death )
	return "[""]: "..text;

But when i say something i’ve the error:

ERROR: GAMEMODE:‘PlayerSay’ Failed: GRProject\gamemode\init.lua:69: attempt to index local ‘team’ (a boolean value)
Error: hook->PlayerSay returned a non-string!

The line 69 is that line:

return “[”…team.GetName(ply:Team())…"]: "…text;

I have searched on the wiki but i dont see what is wrong with my code. And yes i’m in a team when i test this.

I know is noobish question but i’m stuck with this stupid error.


Ok but on the wiki i read this:

--This function tells the player what team he is on every time he spawns.
function Spawn( ply )
ply:ChatPrint( "You are on team "..ply:Team().." (" ply:Team() )..")" )
hook.Add( "PlayerSpawn", "playerSpawn", Spawn )


So. How i can get the TeamName of the player ?

I want to modify the saying (text) by something like that:

[Team] Playername: Text of the player

Sorry, I didn’t look at your code properly, your second argument is overriding the global library called team in your function. Just rename the second argument.


[lua]function GM:PlayerSay( ply, text, toteam, death )
return “[”…team.GetName(ply:Team())…"]: "…text;

Oh thanks that work fine.

But now i see that i’ve do is not i want. Do you know how i can modify the player name ?

I want when a player say somthing, the gamemode display something like that:

[Team]PlayerName: Text

With the string “[Team]PlayerName:” coloured with the team color. (like the playername is coloured)

PS: sorry for my poorly english


Think thats what your looking for


Maybe is because my english is bad…

When i use the PlayerSay() function, that should say the text in white and don’t modify the name of the player.

I want to change de player name, for exemple Xarik, to [Team]Xarik.

Your English is fine. This may be of use to you.

return “[”…team.GetName(ply:Team())…"]"…ply:Nick()…": "…text;

That’s don’t work, with this ingame that do:

Xarik: [Team]: Bla

With only my name coloured.

I want when a player say something that do that:

[Team]Player: Bla

With the “[Team]Player” coloured.

I think that just need to change the playername with teamname before, Xarik => [Team]Xarik


Yes exactly that i need (i think), thank you verry much.


Now i’ve this code:

function GM:PlayerSay( ply, text, toteam, death )
	ply:ChatPrint("[""]"..ply:Nick()..": "..tostring( text ) )
        return ""

I’ve the good printing ([Team]Xarik: What i said) but i’ve not the colour of the team.

And i wonder if there is no simpler than that:

To colour the playername with ChatPrint()


Ok after some test and some searching time, i’ve finaly found how todo that i want. It’s on the Client that !

In my cl_init.lua i’ve now this:

function GM:OnPlayerChat( player, strText, bTeamOnly, bPlayerIsDead )

	local tab = {}

	if ( IsValid( player ) ) then
		table.insert( tab, team.GetColor(player:Team()))
		table.insert( tab, tostring("[""]"))
		table.insert( tab, player )
		table.insert( tab, Color(255,125,0,255))

	table.insert( tab, ": "..strText )

	chat.AddText( unpack(tab) )

	return true


And that works perfectly !!