Jump to content

[HELP] another language for outputchatbox


Synthe1

Recommended Posts

Hello, i need help with more languages in outputchatbox.

For example, u can choose ur lang with command /setlanguage english or another language, then it will show outputchatbox lang with ur language.

Something like this : 

    outputChatBox("#123456[!] [DM]: #FFFFFF"..getPlayerName(killer).." #123456KILLED #FFFFFF"..getPlayerName(source).." #123456!", getRootElement(), 255, 0, 0, true)  ----- English language

    outputChatBox("#123456[!] [DM]: #FFFFFF"..getPlayerName(killer).." #123456Zabil si #FFFFFF"..getPlayerName(source).." #123456!", getRootElement(), 255, 0, 0, true)  ----- another language 

Thanks for answer. 

Link to comment
local lang1 = "english"
local lang2 = "polski"

function element(cm,lang)
if lang then
if lang == tostring(lang1) then
setElementData(localPlayer,"language",lang1)
elseif lang == tostring(lang2) then
setElementData(localPlayer,"language",lang2) 
end
end
end

addCommandHandler("setlanguage",element)

function chatbox()
 if getElementData(localPlayer,"language") == lang1 then
 outputChatBox("#123456[!] [DM]: #FFFFFF"..getPlayerName(killer).." #123456KILLED #FFFFFF"..getPlayerName(source).." #123456!", getRootElement(), 255, 0, 0, true)  ----- English language
elseif getElementData(localPlayer,"language") == lang2 then
    outputChatBox("#123456[!] [DM]: #FFFFFF"..getPlayerName(killer).." #123456Zabil si #FFFFFF"..getPlayerName(source).." #123456!", getRootElement(), 255, 0, 0, true)
end 
end

 

  • Thanks 1
Link to comment

Hey,  thanks for answer but It doesnt work.  There is no error in debugscript.

 

my code

 

local lang1 = "en"
local lang2 = "cz"

function element(cm,lang)
if lang then
if lang == tostring(lang1) then
setElementData(localPlayer,"language",lang1)
elseif lang == tostring(lang2) then
setElementData(localPlayer,"language",lang2) 
end
end
end
addCommandHandler("setlanguage",element)


function w1 ()
if getElementData(localPlayer,"language") == lang1 then
outputChatBox("#bcff00[!] Don't forget to visit us in our forum", getRootElement(), 255, 255, 255, true)
elseif getElementData(localPlayer,"language") == lang2 then
outputChatBox("#bcff00[!] Nezapomen nas navštivit i na našem foře", getRootElement(), 255, 255, 255, true)
end
end
setTimer(w1, 2000, 0)      

 

Link to comment
  • Moderators
2 minutes ago, Synthe1 said:

Sorry but I have another problem with that.

 

How i can save it?

I mean, when I go reconnect I have to set the language again. 

 

You could save it in to an XML file > clientside

 

There is a resource that does that automatic for you:

https://community.multitheftauto.com/index.php?p=resources&s=details&id=16187

Including a wiki guide:

https://wiki.multitheftauto.com/wiki/XmlSaveData

 

 

No need for saving such data in to a database, as the user wants to have this info when he joins and not when he logins.

 

  • Like 1
  • Thanks 1
Link to comment
  • Moderators
2 hours ago, Synthe1 said:

I got it, thanks, I have last question,  how i can use that language 'system' for serverside? 

You are already using elementdata, in the most possible global way. So the selected language is also available there.

 

Edited by IIYAMA
Link to comment

I tried this

function(message,type) 
if (string.find(message, "!skills")) and not (string.find(message, " !skills")) then   
    local account = getPlayerAccount(source)
	local kills = (getAccountData(account, "kills") or 0)
    local nick = getPlayerName(source)
    local nickA = string.gsub(nick, "#%x%x%x%x%x%x", "")
if (string.find(message, "!skills")) and not (string.find(message, " !skills")) then   
    local account = getPlayerAccount(source)
	local kills = (getAccountData(account, "kills") or 0)
    local nick = getPlayerName(source)
    local nickA = string.gsub(nick, "#%x%x%x%x%x%x", "")
	if getElementData(localPlayer,"language") == lang1 then
    outputChatBox("#FFFFFF "..nickA.. " #00CC40killed #FFFFFF ["..kills.."] #00CC40players!",255,0,0,true)
	elseif  getElementData(localPlayer,"language") == lang1 then
    outputChatBox("#FFFFFF "..nickA.. " #00CC40zabil #FFFFFF ["..kills.."] #00CC40hračov na CW!",255,0,0,true)

Its server side but it doesnt work. Can u help me with this last thing please? 

Link to comment
  • Moderators
12 minutes ago, Synthe1 said:

Its server side but it doesnt work. Can u help me with this last thing please? 

  • localPlayer doesn't exist on serverside. It only exist on your own MTA san application, which is clientside.
  • You need to define which player is going to receive the message on serverside.
  • You wrote two times lang1.
  • You forgot to write a fallback when no language is selected.

 

local language = getElementData(source,"language") 
if not language or language == lang1 then
	outputChatBox("#FFFFFF "..nickA.. " #00CC40killed #FFFFFF ["..kills.."] #00CC40players!", source,255,0,0,true)
elseif language == lang2 then
	outputChatBox("#FFFFFF "..nickA.. " #00CC40zabil #FFFFFF ["..kills.."] #00CC40hračov na CW!", source,255,0,0,true)
end

 

  • Thanks 1
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...