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