• 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+ I want to learn basic TFS 1X functions

Mateus Robeerto

Excellent OT User
Joined
Jun 5, 2016
Messages
1,337
Solutions
71
Reaction score
697
Location
ლ(ಠ益ಠლ)
Good morning, can someone teach me how to use the function by NPC? I just want to learn how this function works. For example, an NPC with Master Sorcerer ID 5 and who switches to Nova with Supreme Sorcerer ID 9, as I have 4 different vocations. Can someone explain the basics of functions?


I found these functions in lib/compat: 'getPlayerVocation', 'getVocation' and 'setVocation'. I also found another function called 'getVocation'. I want to create a table with the following correspondences: id 5-9, 6-10, 7-11 and 8-12. However, I can't add the function that allows switching to new vocations. I tried to add another function that increases +4 in vocations using 'getPlayerVocation(cid)+4' but it didn't work. Can someone explain just these functions?
Post automatically merged:

Can someone help me try to put a table by vocation? I want something similar to this table that I put, but so far nothing is working


Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

local vocations = {
    [5] = {id = 9, name = "Supreme Sorcerer"},
    [6] = {id = 10, name = "Supreme Druid"},
    [7] = {id = 11, name = "Supreme Paladin"},
    [8] = {id = 12, name = "Supreme Knight"},
}

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg)
end

function onThink()
    npcHandler:onThink()
end

function creatureSayCallback(cid, type, msg)
    local pid = getPlayerGUID(cid)

    if (not npcHandler:isFocused(cid)) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if (msgcontains(msg, 'supreme') or msgcontains(msg, 'voc')) then
         selfSay('Considering all the presented information, do you really want to perform a Master Reset? This process costs 100 vip coins and is irreversible! Say {yes} to confirm.', cid)
        talkState[talkUser] = 1
    elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if doPlayerRemoveItem(cid, 6527, 100) then
            -- Set health to 185
            doCreatureAddHealth(cid, -getCreatureHealth(cid) + 185)
            setCreatureMaxHealth(cid, 185)
            -- Set mana to 35
            doCreatureAddMana(cid, -getCreatureMana(cid) + 35)
            setCreatureMaxMana(cid, 35)
            doTeleportThing(cid, getTownTemplePosition(1))
            doRemoveCreature(cid)
            local reset_level = "UPDATE players SET level = 30 WHERE id = " .. pid .. ";"
            local reset_query = "UPDATE players SET reset = 0 WHERE id = " .. pid .. ";"
            local reset_exp = "UPDATE players SET experience = 4200 WHERE id = " .. pid .. ";"
            db.query(reset_exp)
            db.query(reset_query)
            db.query(reset_level)

            local newVocation = vocations[getPlayerVocation(cid)]
            if newVocation ~= nil then
                doPlayerSetVocation(cid, newVocation.id)
                selfSay("Congratulations! You have successfully reborn and your new vocation is " .. newVocation.name .. ".", cid)
            else
                selfSay("Congratulations! You have successfully reborn.", cid)
            end
        else
            selfSay("You don't have 100 event tokens", cid)
        end

        talkState[talkUser] = 0
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
What's wrong actually ? You have the table containing 5-9, 6-10, 7-11 and 8-12 in "vocations".
I just tested it in LUA editor without tfs and its working. If getPlayerVocation(cid) returns a proper ID like 5 you will get a ID 9 in "newVocation.id"

Lua:
local vocations = {
    [5] = { id = 9, name = "Supreme Sorcerer" },
    [6] = { id = 10, name = "Supreme Druid" },
    [7] = { id = 11, name = "Supreme Paladin" },
    [8] = { id = 12, name = "Supreme Knight" },
}

local voc = 5 --const for getPlayerVocation(cid)

local newVocation = vocations[voc]
if newVocation ~= nil then
    print(newVocation.id)
    print(newVocation.name)
end

Output:
Code:
9
Supreme Sorcerer
 
What's wrong actually ? You have the table containing 5-9, 6-10, 7-11 and 8-12 in "vocations".
I just tested it in LUA editor without tfs and its working. If getPlayerVocation(cid) returns a proper ID like 5 you will get a ID 9 in "newVocation.id"

Lua:
local vocations = {
    [5] = { id = 9, name = "Supreme Sorcerer" },
    [6] = { id = 10, name = "Supreme Druid" },
    [7] = { id = 11, name = "Supreme Paladin" },
    [8] = { id = 12, name = "Supreme Knight" },
}

local voc = 5 --const for getPlayerVocation(cid)

local newVocation = vocations[voc]
if newVocation ~= nil then
    print(newVocation.id)
    print(newVocation.name)
end

Output:
Code:
9
Supreme Sorcerer
vocation promotion is always player:getVocation():getId() + 4 = promoted same vocation, why bother with a table? when you can use also Vocation((player:getVocation():getId() + 4)):getName() <-- whenever you need the name
 
vocation promotion is always player:getVocation():getId() + 4 = promoted same vocation, why bother with a table? when you can use also Vocation((player:getVocation():getId() + 4)):getName() <-- whenever you need the name
he wanted to have it this way not me :D i just wanted to explain that it should work either way.
 
a promoção de vocação é sempre player:getVocation():getId() + 4 = promoveu a mesma vocação, por que se preocupar com uma tabela? quando você pode usar também Vocation((player:getVocation():getId() + 4)):getName() <-- sempre que precisar do nome
So I promoted wrongly to the same vocation +4, wouldn't it be +8?
vocações locais = { [5] = { id = 9, nome = "Feiticeiro Supremo" }, [6] = { id = 10, nome = "Druida Supremo" }, [7] = { id = 11, nome = " Paladino Supremo" }, [8] = { id = 12, name = "Cavaleiro Supremo" }, } local voc = 5 --const for getPlayerVocation(cid) local newVocation = vocations[voc] if newVocation ~= nil then print( newVocation.id) print(newVocation.name) end
Hmm, I'll check that later. Thanks
 
Last edited:
Então fiz promoção errada para a mesma vocação +4, não seria +8?

Hmm, vou verificar isso mais tarde. Obrigado
Post automatically merged:
English please, as it is the main language of the community anyway i used translator to understand you +8 would be 2 promotion if you have a third promotion so if the player is a knight its 4, elite knight is 8, supreme knight is 12 so from normal knight to supreme is +8.

not sure if that what you meant translator seems to be tricky
 
Or you can do that so it's not necessary + 4, in case you'd like to have more than 4 base vocations, but you need to make sure all vocations are correctly configured in vocation.xml (code not tested):

Lua:
local player = Player(cid)
local vocation = player:getVocation()
local baseVocation = vocation:getBase()
local promotedVocation = vocation:getPromotion()
local newVocation = baseVocation ~= vocation and promotedVocation or nil

if newVocation then
    player:setVocation(newVocation)
    selfSay(("Congratulations! You have successfully reborn and your new vocation is %s."):format(newVocation.name), cid)
else
    selfSay("Congratulations! You have successfully reborn.", cid)
end

Note: baseVocation ~= vocation is to check whether player has already a base level of promotion (MS, ED, RP, EK)
 
English please, as it is the main language of the community anyway i used translator to understand you +8 would be 2 promotion if you have a third promotion so if the player is a knight its 4, elite knight is 8, supreme knight is 12 so from normal knight to supreme is +8.

not sure if that what you meant translator seems to be tricky
I know the community is predominantly in English, but when I clicked, automatic translation turned on for my language and I forgot to turn it off before submitting, haha. I fixed it there. Thanks!
Post automatically merged:

In my vocations.xml, ID 4 is for the "Knight" vocation, and ID 8 is for the "Elite Knight" vocation. The ultimate vocation, "Supreme Knight", has an ID of 12.
Post automatically merged:

Or you can do that so it's not necessary + 4, in case you'd like to have more than 4 base vocations, but you need to make sure all vocations are correctly configured in vocation.xml (code not tested):

Lua:
local player = Player(cid)
local vocation = player:getVocation()
local baseVocation = vocation:getBase()
local promotedVocation = vocation:getPromotion()
local newVocation = baseVocation ~= vocation and promotedVocation or nil

if newVocation then
    player:setVocation(newVocation)
    selfSay(("Congratulations! You have successfully reborn and your new vocation is %s."):format(newVocation.name), cid)
else
    selfSay("Congratulations! You have successfully reborn.", cid)
end

Note: baseVocation ~= vocation is to check whether player has already a base level of promotion (MS, ED, RP, EK)
Can I confirm if I understood correctly? You are saying that it is not necessary to use the table I made, and that you made the code for me to test. That's right?

Look, I replaced it in my script and tested it... it gave an error.
Lua:
Lua Script Error: [Npc interface]
data/npc/scripts/teste.lua:onCreatureSay
data/npc/scripts/teste.lua:52: attempt to index local 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/npc/scripts/teste.lua:52: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
        data/npc/scripts/teste.lua:15: in function <data/npc/scripts/teste.lua:14>
Reset the character, ok, but didn't gain a new vocation...
 
Last edited:
Because this line is null i guess
local player = Player(cid)

Lua:
local player = Player(cid)
if player then
    local vocation = player:getVocation()
    local baseVocation = vocation:getBase()
    local promotedVocation = vocation:getPromotion()
    local newVocation = baseVocation ~= vocation and promotedVocation or nil

    if newVocation then
        player:setVocation(newVocation)
        selfSay(("Congratulations! You have successfully reborn and your new vocation is %s."):format(newVocation.name), cid)
    else
        selfSay("Congratulations! You have successfully reborn.", cid)
    end
else
    print("Error player not found")
end

Should work without it, imo not sure which tfs version u're using.
 
Because this line is null i guess
local player = Player(cid)

Lua:
local player = Player(cid)
if player then
    local vocation = player:getVocation()
    local baseVocation = vocation:getBase()
    local promotedVocation = vocation:getPromotion()
    local newVocation = baseVocation ~= vocation and promotedVocation or nil

    if newVocation then
        player:setVocation(newVocation)
        selfSay(("Congratulations! You have successfully reborn and your new vocation is %s."):format(newVocation.name), cid)
    else
        selfSay("Congratulations! You have successfully reborn.", cid)
    end
else
    print("Error player not found")
end

Should work without it, imo not sure which tfs version u're using.
Ok, I understand. My TFS version is 1.5 8.0, made by Nekiro.

If that doesn't work, I'll simply use an NPC that will reset the player's HP/MP and level after the NPC hands over an item, and then use a command to switch to the new vocation. Done, problem solved.

thank you very much
 
I already solve! I put an NPC to perform the reset and an item that the NPC gives to the player, gains a new vocation when you click on it. Done, it's simple and fast. Many thanks to you!
 
vocation promotion is always player:getVocation():getId() + 4 = promoted same vocation, why bother with a table? when you can use also Vocation((player:getVocation():getId() + 4)):getName() <-- whenever you need the name
The problem was already solved. I used the player:getvocations function and tested it, and it worked correctly. The Master Sorcerer transformed into the Supreme Sorcerer. Also, I added +4 extra vocations, the last one being correct. There are no errors or bugs, it's working fine at the moment. Thanks

function is correct:
Lua:
local currentVocation = player:getVocation():getId()
player:setVocation(Vocation(currentVocation + 4))
 

Similar threads

Back
Top