Jump to content

get/setElementData question/problem


..:D&G:..

Recommended Posts

Hello guys, I am trying to make a small function to allow people select their own language on the server. I would like to use elementData and a command such as /eng to set the language of the player to english. I did something like:

languages = { 
    eng = "English", 
    ro = "Romanian", 
    sp = "Spanish", 
    it = "Italian", 
    fr = "French",  
} 
function setPlayerLanguage(thePlayer, language) 
    setElementData(thePlayer, language) 
    outputChatBox("Language set to "..language, thePlayer) 
    if getElementData(thePlayer, it) then 
        outputChatBox("Your language is already italian", thePlayer) 
    end 
end 
addCommandHandler("setlanguage", setPlayerLanguage) 

PS: Before someone comes and says "Retard, this script will not work, this is a mess, what kind of scripter are you?". I just made this in like 2 minutes, so I can give you guys an example to help me, because I want to do something like that.

Thank you.

Link to comment

Try this;

function languageCmd(player, cmd, language) 
    if cmd == "setlanguage" then 
        language  = tostring(language) 
        if language then 
            -- set player language 
        else 
            outputChatBox("[usage] /setlanguage [language]", player) 
        end 
    else 
        outputChatBox("[usage] /setlanguage [language]", player) 
    end 
end 
  
addCommandHandler("setlanguage", languageCmd) 

Not tested, never used the command with extra parameters but this is what I understand of it.

Link to comment
  
-- Currently enabled languages. 
languages = { 
    ["english"] = true, 
    ["romanian"] = true, 
    ["spanish"] = true, 
    ["italian"] = true, 
    ["french"] = true, 
} 
  
function languageCmd(player, cmd, language) 
   if not tostring(language) then 
       outputChatBox("[usage] /setlanguage [language]", player)   
       return 
    end 
       language  = string.lower(tostring(language)) 
       if languages[language] then 
           -- set player language 
       else 
            outputChatBox("Not a supported language type, you may choose from:", player) 
            for k, v in pairs(languages) do 
                 outputChatBox(k, player) 
            end 
       end 
end 
addCommandHandler("setlanguage", languageCmd) 
  

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...