Jump to content

Teamchat shows to all.


~Air

Recommended Posts

Hey guys,

I got again a problem.

So a player that hasn't got a chatcolor and writes in the teamchat, the message will be displayed to everyone.

Only if a player has got a chatcolor the message will be only shown on the teamchat.

Could someone help me please? :S

  
local function teamChat(message, messageType) 
    if messageType == 2 then  
        cancelEvent() 
        local acc = getPlayerAccount(source) 
        if not isGuestAccount(acc) then 
             if getAccountData(acc,"chatc") and getElementData(source, "Vip") == true then 
                local color = getAccountData(acc,"chatc") 
                local team = getPlayerTeam ( source ) 
                if ( not team ) then 
                    return 
                end 
                 for _, team in ipairs ( getPlayersInTeam ( team ) ) do 
                outputChatBox("(TEAM): " ..getPlayerName(source)..": "..color..""..message, team, 255, 255, 255, true ) 
                end 
            else 
                outputChatBox("(TEAM): " ..getPlayerName(source)..": #FFFFFF"..message, team, 255, 255, 255, true ) 
            end 
        else 
            outputChatBox("(TEAM): "..getPlayerName(source)..": #FFFFFF"..message, team, 255, 255, 255, true ) 
        end 
        outputServerLog("CHAT: "..getPlayerName(source)..": "..message) 
    end 
 end 
addEventHandler("onPlayerChat", root, teamChat) 

Link to comment

You're defining local team variable in line 9 and it only exists in that scope. For more information check this http://lua-users.org/wiki/ScopeTutorial

The for loop is unnecessary. My suggestion is to put lines 9-12 just after "local acc..." so all of your code that depends on "team" is in the same scope. Also the for loop needs to be repeated two more times.

  
  
local function teamChat(message, messageType) 
    if messageType == 2 then 
        cancelEvent() 
        local acc = getPlayerAccount(source) 
        local team = getPlayerTeam ( source ) 
        if ( not team ) then 
            return 
        end 
        
        if not isGuestAccount(acc) then 
            if getAccountData(acc,"chatc") and getElementData(source, "Vip") == true then 
                local color = getAccountData(acc,"chatc") 
                for _, player in ipairs(getPlayersInTeam(team)) do 
                    outputChatBox("(TEAM): " .. getPlayerName(source) .. ": " .. color .. message, player, 255, 255, 255, true) 
                end 
            else 
                for _, player in ipairs(getPlayersInTeam(team)) do 
                    outputChatBox("(TEAM): " .. getPlayerName(source) .. ": #FFFFFF" .. message, player, 255, 255, 255, true) 
                end 
            end 
        else 
            for _, player in ipairs(getPlayersInTeam(team)) do 
                outputChatBox("(TEAM): " .. getPlayerName(source) .. ": #FFFFFF" .. message, player, 255, 255, 255, true ) 
            end 
        end 
        outputServerLog("CHAT: "..getPlayerName(source)..": "..message) 
    end 
end 
addEventHandler("onPlayerChat", root, teamChat) 
  

Edited by Guest
Link to comment
outputChatBox doesn't seems to work with team element, therefore you will have to make the loop.

Oops! You're right, my bad. I've been always using custom team elements and forgot that this doesn't work by default. I'll edit the code.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...