Synthe1 Posted September 14, 2019 Share Posted September 14, 2019 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
Furzy Posted September 14, 2019 Share Posted September 14, 2019 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 1 Link to comment
Synthe1 Posted September 14, 2019 Author Share Posted September 14, 2019 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
Furzy Posted September 14, 2019 Share Posted September 14, 2019 try client side and remove getRootElement() from outputChatBox, or change localPlayer to thePlayer function element(thePlayer,cm,lang) 1 Link to comment
Synthe1 Posted September 14, 2019 Author Share Posted September 14, 2019 Oh bro. thank u very much. Link to comment
Synthe1 Posted September 14, 2019 Author Share Posted September 14, 2019 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. Link to comment
Moderators IIYAMA Posted September 14, 2019 Moderators Share Posted September 14, 2019 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. 1 1 Link to comment
Furzy Posted September 14, 2019 Share Posted September 14, 2019 (edited) yeah , xml Edited September 14, 2019 by Furzy Link to comment
Synthe1 Posted September 15, 2019 Author Share Posted September 15, 2019 (edited) I got it, thanks, I have last question, how i can use that language 'system' for serverside? Edited September 15, 2019 by Synthe1 Link to comment
Moderators IIYAMA Posted September 15, 2019 Moderators Share Posted September 15, 2019 (edited) 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 September 15, 2019 by IIYAMA Link to comment
Synthe1 Posted September 15, 2019 Author Share Posted September 15, 2019 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 IIYAMA Posted September 15, 2019 Moderators Share Posted September 15, 2019 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 1 Link to comment
Synthe1 Posted September 15, 2019 Author Share Posted September 15, 2019 Oh my iq droped. Thank u very much!! 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now