Need some help with GM:PlayerSay

Hi

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



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


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.

-snip-

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().." ("..team.GetName( ply:Team() )..")" )
end
 
hook.Add( "PlayerSpawn", "playerSpawn", Spawn )
 


url: http://wiki.garrysmod.com/?title=Player.Team

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.

[editline]05:10PM[/editline]

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

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

**[Team.GetColor

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Team.GetColor)**

Think thats what your looking for

No.

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

[editline]09:10PM[/editline]

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

[editline]09:30PM[/editline]

Now i’ve this code:



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


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: http://www.facepunch.com/showthread.php?t=768062

To colour the playername with ChatPrint()

[editline]10:08PM[/editline]

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("["..team.GetName(player:Team()).."]"))
		table.insert( tab, player )
		table.insert( tab, Color(255,125,0,255))
	end


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

	chat.AddText( unpack(tab) )

	return true

end

And that works perfectly !!