Por
MySticaL
Como funciona esse sistema?
R-> Simples caso seu otServ for para todos os players, de todos continentes e você não
queira deixar as funções em lua apenas em uma língua, você pode utilizar esse sistema.
Como usar?
R-> Após o sistema estar instalado 100%, vai ter 3 comandos: !lang en (setar a linguagem para english), !lang pt (setar a linguagem portuguese) &
!lang es (setar a linguagem espanõl).
Vamos começar, vai em data/lib/ e crie um arquivo chamado lang system.lua e coloque isto dentro:
function getPlayerLanguage(cid)
local Lang = db.getResult("SELECT `language` FROM `accounts` WHERE `id` = " .. getPlayerAccountId(cid) .. " LIMIT 1")
if Lang:getID() ~= LUA_ERROR then
local langid = Lang:getDataInt("language")
Lang:free()
return langid
end
return LUA_ERROR
end
function doPlayerSetLanguage(cid, new)
local acc = getPlayerAccountId(cid)
if new == 2 then
db.executeQuery("UPDATE `accounts` SET language = 2 WHERE `id` = " .. acc)
elseif new == 1 then
db.executeQuery("UPDATE `accounts` SET language = 1 WHERE `id` = " .. acc)
else
db.executeQuery("UPDATE `accounts` SET language = 0 WHERE `id` = " .. acc)
end
end
Ainda em data/lib encontre o arquivo 000-constant.lua e coloque ao final dele isto:
ENGLISH = 2
SPANISH = 1
PORTUGUES = 0
Agora execute este código na sua SQL:
ALTER TABLE `accounts` ADD `language` INT( 11 ) NOT NULL DEFAULT '0'
Pronto, o sistema está pronto agora vamos criar um comando para que troque a linguagem, vá em data/talkactions/scripts
e crie um arquivo chamado lang.lua e coloque isto dentro:
function onSay(cid, words, param)
if(param == '') then
return true
end
if(param == 'en') then
if getPlayerLanguage(cid) == 2 then
doPlayerSendTextMessage(cid, 20, "[Language System (Beta)] Your language is alredy set to english.")
return true
else
doPlayerSendTextMessage(cid, 27, "[Language System (Beta)] You have set english as your language.")
doPlayerSetLanguage(cid, 2)
return true
end
end
if(param == 'pt') then
if getPlayerLanguage(cid) == 0 then
doPlayerSendTextMessage(cid, 20, "[Language System (Beta)] Sua língua já está definida como português.")
return true
else
doPlayerSendTextMessage(cid, 27, "[Language System (Beta)] Você definiu o português como sua língua.")
doPlayerSetLanguage(cid, 0)
return true
end
end
if(param == 'es') then
if getPlayerLanguage(cid) == 1 then
doPlayerSendTextMessage(cid, 20, "[Language System (Beta)] Su lengua ya esta definida como español.")
return true
else
doPlayerSendTextMessage(cid, 27, "[Language System (Beta)] Tu definistes el español como tu lengua.")
doPlayerSetLanguage(cid, 1)
return true
end
end
end
E em data/talkactions abra o talkactions.xml e coloque está tag:
<talkaction log="yes" words="!lang" event="script" value="lang.lua"/>
Vou dar um exemplo de como usa-la em .lua:
if getPlayerLanguage(cid) == 2 then
doPlayerSendTextMessage(cid, 25, "This message will be displayed in English if the language of the player is in -en!")
end
if getPlayerLanguage(cid) == 0 then
doPlayerSendTextMessage(cid, 25, "Está mensagem será exibida em português se a linguagem do jogador estiver em -pt!")
end
if getPlayerLanguage(cid) == 1 then
doPlayerSendTextMessage(cid, 25, "Usted mensaje se mostrará en Espanõl si el jugador está en el lenguaje -es!")
end
Outro Exemplo:
function onLogin(cid)
local langmsg = {
[ENGLISH] = {"This message will be displayed in English if the language of the player is in -en!"}
[SPANISH] = {"Usted mensaje se mostrará en Espanõl si el jugador está en el lenguaje -es!"},
[PORTUGUES] = {"Está mensagem será exibida em português se a linguagem do jogador estiver em -pt!"},
}
doPlayerSendTextMessage(cid, 25, langmsg[getPlayerLanguage(cid)][1])
return true
end
Pronto, agora o sistema está perfeito, os comandos estão no começo do tópico em "Como usar?"
créditos:
Acubens
Drazyn1291
MySticaL
Posts Recomendados
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.