Jump to content

Language


Whit3

Recommended Posts

I have a problem.

I would like that when a player writes for example joinen (joinenglish) and press L, can talk to your chat

client

function joinSpanish() 
outputChatBox("Has elegido el idioma español.", 0, 255, 0, false) 
setElementData(localPlayer, "Language", "Español") 
   end 
addCommandHandler("joinsp", joinSpanish) 
  
function joinEnglish() 
outputChatBox("You have just selected the language english.", 0, 255, 0, false) 
setElementData(localPlayer, "Language", "English") 
end 
addCommandHandler("joinen", joinEnglish) 
  

Server

function languageChat (thePlayer, cmd, ...) 
local name = getPlayerName(thePlayer) 
if messageType == 0 then 
cancelEvent() 
end 
    if ( isPlayerOnGroupSpanish ( source ) ) then 
       local msg = table.concat({...}, " ") 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            if ( isPlayerOnGroupSpanish ( player ) ) then 
               if (msg and msg ~= "") then 
                outputChatBox("#FF0000[spanish]"..name..": #FFFFFF"..msg.."",players,r, g, b,true) 
  
                end 
            end 
end 
    elseif ( isPlayerOnGroupEnglish ( source ) ) then 
                local msge = table.concat({...}, " ") 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            if ( isPlayerOnGroupEnglish ( player ) ) then 
                           if (msge and msge ~= "") then 
                outputChatBox("#FF0000[English]"..name..": #FFFFFF"..msge.."",players,r, g, b,true) 
  
            end 
        end 
    end 
end 
end 
  
addCommandHandler("Language",languageChat) 
--addEventHandler("onPlayerChat", root, languageChat) 
  
  
  
addEventHandler("onPlayerJoin",root, 
    function () 
        exports.scoreboard:scoreboardAddColumn ( "Language" )  
        bindKey(source,"L","down","chatbox","Language", languageChat) 
    end 
) 
  
  
function isPlayerOnGroupSpanish ( thePlayer ) 
    local inGroupSpanish = false 
    for _, player in ipairs(getElementsByType("player")) do 
        if (getElementData(player, "Language") == "Español") then 
            inGroupSpanish = true 
            break 
        end 
         
    end 
    return inGroupSpanish 
    end 
  
function isPlayerOnGroupEnglish ( thePlayer ) 
    local inGroupEnglish = false 
    for _, player in ipairs(getElementsByType("player")) do 
    if (getElementData(player, "Language") == "English") then 
            inGroupEnglish = true 
            break 
        end 
    end 
    return inGroupEnglish 
    end 
  

Link to comment

You had an unnecessary end, wrong arguments, wrong elements and generally you forgot to re-check the code.

function languageChat(player, cmd, ...) 
    if (not ...) then return end 
    local msg = table.concat({...}, " ") 
    if (#msg <= 0) then return end 
    for _,languagePlayer in ipairs(getElementsByType("player")) do 
         if (getPlayerLanguage(languagePlayer) == getPlayerLanguage(player)) then 
              outputChatBox("#FF0000[" .. getPlayerLanguage(player) .. "] " .. getPlayerName(player) .. ": #FFFFFF" .. msg, languagePlayer, 255, 255, 255, true) 
         end 
    end 
end 
addCommandHandler("Language", languageChat) 
  
addEventHandler("onPlayerJoin", root, 
    function() 
        exports.scoreboard:scoreboardAddColumn("Language") 
        bindKey(source, "L", "down", "chatbox", "Language") 
    end 
) 
  
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        for _,player in ipairs(getElementsByType("player")) do 
             bindKey(player, "L", "down", "chatbox", "Language") 
        end 
    end 
) 
  
function getPlayerLanguage(player) 
    if (getElementData(player, "Language")) then 
         return getElementData(player, "Language") 
    else 
         return false 
    end 
end 
  
function isPlayerOnGroupSpanish(player) 
    if (getPlayerLanguage(player) == "Español") then 
         return true 
    else 
         return false 
    end 
end 
  
function isPlayerOnGroupEnglish(player) 
    if (getPlayerLanguage(player) == "English") then 
         return true 
    else 
         return false 
    end 
end 

Edited by Guest
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...