• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ Vocation(id or name)

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
I created a code where the player writes in a letter the vocation he wants to be.
LUA:
function onTextEdit(player, item, text)
        if Vocation(text) then
            player:setVocation(text)
        else
            --Vocation don't exist
            return false
        end
    return true
end

but if player open a label, and write wrong vocation, it dont return false, it return error, exemple, if a player write "Sorqcerer".
Error is here, if text isnt a valid vocation, it dont return 'nil', it return error
LUA:
Vocation(text)
1585537500498.png
1585537485493.png
 
No need to open up another support thread.

 
No need to open up another support thread.

Because i cant remove "solved" for another thread
 
So it should be working.
It just throws the warning.

Validate vocations a different way then:
LUA:
local validVocations = {
    "sorcerer",
    "druid",
    "paladin",
    "knight",
    "master sorcerer",
    "elder druid",
    "royal paladin",
    "elite knight",
}
function onTextEdit(player, item, text)
    local vocation = text:gsub('^%s*(.-)%s*$', '%1'):lower() -- trim the input text and convert to lower-case
    if table.contains(validVocations, vocation) then
        player:setVocation(vocation)
    else
        --Vocation don't exist
        return false
    end
    return true
end

 
Last edited:
So it should be working.
It just throws the warning.

Validate vocations a different way then:

I liked your post because it really is one way to solve it.
But I believe that the most certain thing would be to make Vocation (invalidVoc) return false or 'nil', let's see if anyone can help us.
 
Last edited:
Vocation(invalidVoc) will return a warning every single time, you cannot work around this in lua.
You would need to edit sources to remove the warning or re-write how it handles invalid params:
I will try to rewrite, if I can I post here, if anyone wants to help, feel free
 
Back
Top