• 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+ tfs 1.3open label, type a name of vocation, and press OK

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
Hello Guys, i'm using tfs 1.3 for tibia 8.6.
I'm trying to make a script, that the player opens the label, write the name of the vocation you want to change and when he presses OK he changes his vocation, is it possible?

exemple: if a sorcerer open a label and type elite sorcerer (new voc of my game), his vocation will change when you press OK

1585498868411.png
 
Solution
Hi,
Try:
data/creaturescripts/scripts/label_vocation.lua
LUA:
function onTextEdit(player, item, text)
    if item:getId() == LABEL_ITEM_ID then
        if Vocation(text) then
            player:setVocation(text)
            item:remove()
            return true
        else
            --Vocation don't exist
            return false
        end
    end
    return true
end
data/creaturescripts/creaturescripts.xml
XML:
<event type="textedit " name="LabelVocation" script="label_vocation.lua" />
Remember to register the creaturescript to player. And put the id of label in label_vocation.lua.
Hi,
Try:
data/creaturescripts/scripts/label_vocation.lua
LUA:
function onTextEdit(player, item, text)
    if item:getId() == LABEL_ITEM_ID then
        if Vocation(text) then
            player:setVocation(text)
            item:remove()
            return true
        else
            --Vocation don't exist
            return false
        end
    end
    return true
end
data/creaturescripts/creaturescripts.xml
XML:
<event type="textedit " name="LabelVocation" script="label_vocation.lua" />
Remember to register the creaturescript to player. And put the id of label in label_vocation.lua.
 
Solution
Hi,
Try:
data/creaturescripts/scripts/label_vocation.lua
LUA:
function onTextEdit(player, item, text)
    if item:getId() == LABEL_ITEM_ID then
        if Vocation(text) then
            player:setVocation(text)
            item:remove()
            return true
        else
            --Vocation don't exist
            return false
        end
    end
    return true
end
data/creaturescripts/creaturescripts.xml
XML:
<event type="textedit " name="LabelVocation" script="label_vocation.lua" />
Remember to register the creaturescript to player. And put the id of label in label_vocation.lua.
is it possible to remove spaces from the end?
for exemple, if player put new voc, press enter, and after press ok, it make a space at end, look this print:
with this space at the end, he says that the typed vocation does not exist
1585508603814.png
1585508559334.png
 
replace line 4:
LUA:
local vocation = text:gsub('^%s*(.-)%s*$', '%1') -- trim the input text
if Vocation(vocation) then -- validate string
   player:setVocation(vocation) -- set vocation
else
   -- this vocation does not exist
end
 
Last edited:

Similar threads

Replies
11
Views
521
Xikini
X
Back
Top