• Erm... chat.AddText... user-error.
    7 replies, posted
I don't see anything wrong here, but garrysmod does, meaning it's a user-error and my code is wrong. Any help? [php] function chatspeak if (local plteam( ) == 2 or TEAM_HUMAN) then chat.AddText( player, Color( 1, 15, 255 ), "(Survivor)", strText ) elseif (local plteam( ) == 1 or TEAM_ZOMBIE) then chat.AddText( player, Color( 255, 15, 1 ), "(Infected)", strText ) end end [/php]
Where is the 'player' variable declared? Is this inside a client or a server file? You should delete the 'or TEAM_HUMAN' and the 'or TEAM_ZOMBIE' The or operator is not for comparing values of the same variable, but for comparing 2 different results. For example: [code] if testVar == 1 or testVar == 2 then print("text") end [/code] If this were to be [code] if testVar == 1 or 2 then print("text") end [/code] it would cause an error
[QUOTE=c0baltha1l;24149470] [code] if testVar == 1 or 2 then print("text") end [/code]it would cause an error[/QUOTE] Doubt it. That statement would pretty much be equal to this: [lua] if (maybe true) or true then print("text"); end [/lua] So it would always be true.
Oh, I see the error. You are missile colons in your if statements. Plus Team() should be capitalized
There is so much wrong with the original code you posted, I don't even know where to begin; bear in mind that I do not have access to the wiki right now so I can only guess... [lua]function chatspeak(ply, strText, teamchat, dead) if (ply:Team(TEAM_HUMAN)) then chat.AddText( Color( 1, 15, 255 ), "(Survivor)", ply, Color(255,255,255,255), strText ) elseif (ply:Team(TEAM_ZOMBIE)) then chat.AddText( Color( 255, 15, 1 ), "(Infected)", ply, Color(255,255,255,255), strText ) end end hook.Add("OnPlayerChat", "myChatHook", chatspeak)[/lua]
The code you provided works, although it breaks the chat into two seperate lines, such as: [code] Calmon: What? (Survivor)CalmonWhat? [/code] Both lines show, but I only want the bottom one to.
add 'return false'.
if ply:Team() == TEAM_HUMAN then There you go.
Sorry, you need to Log In to post a reply to this thread.