Hi
I try to write a gamemode and in my init.lua i've this:
[code]
function GM:PlayerSay( ply, text, team, death )
return "["..team.GetName(ply:Team()).."]: "..text;
end
[/code]
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:
[code]
--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 )
[/code]
url: [url]http://wiki.garrysmod.com/?title=Player.Team[/url]
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
[b][url=wiki.garrysmod.com/?title=Team.GetColor]Team.GetColor [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Think thats what your looking for
[QUOTE=*Fish*;19996675][b][url=wiki.garrysmod.com/?title=Team.GetColor]Team.GetColor [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Think thats what your looking for[/QUOTE]
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.
[QUOTE=Xarik;19996885]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.[/QUOTE]
Your English is fine. [url="http://www.facepunch.com/showthread.php?t=768062"]This[/url] may be of use to you.
[QUOTE=Averice;19997279]return "["..team.GetName(ply:Team()).."]"..ply:Nick()..": "..text;[/QUOTE]
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]
[QUOTE=Skondra;19997161]Your English is fine. [url="http://www.facepunch.com/showthread.php?t=768062"]This[/url] may be of use to you.[/QUOTE]
Yes exactly that i need (i think), thank you verry much.
[editline]09:30PM[/editline]
Now i've this code:
[code]
function GM:PlayerSay( ply, text, toteam, death )
ply:ChatPrint("["..team.GetName(ply:Team()).."]"..ply:Nick()..": "..tostring( text ) )
return ""
end
[/code]
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: [url]http://www.facepunch.com/showthread.php?t=768062[/url]
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:
[code]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[/code]
And that works perfectly !!
Sorry, you need to Log In to post a reply to this thread.