• 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+ [NPC Script Change Vocation]

5516593

New Member
Joined
Jul 21, 2011
Messages
8
Reaction score
0
Criei esse topico pq estou tentando fazer um comando ou npc que consiga trocar a vocação do player para uma vocação nova que criei, mas queria resetar, vida, mana, ml, skills e o storage 378378 (resets), mas ele cobra o dinheiro, troca a classe mas não remove os skills e ml =/
Meu servidor é 1.4 TFS 10.98
i am using TFS 1.4 on tibia 10.98, trying to create one talkaction or npc for change the vocation for the new vocation, i create this npc, for restart the follows attributes: Health, Mana, Skills, Magic level and the storage 378378, while charging a fee and demanding a value on storage. It didn't work as expected, it didn't remove magiclevel, skills, life and mana, it just charged value and storage. And when the user did not have the necessary, he does not say the proposed message

Any can help me ?):



Lua:
function onSay(cid, words, param, channel)
    local player = Player(cid)
    local cost = 10000 -- o custo em gold coins do serviço
    local resetsNeeded = 10 -- o número de resets necessários para a troca de vocação
    local newVocationId = 9 -- o ID da nova vocação que você criou
    
    if not player then
        return false
    end
    
    -- Verifique se o jogador tem o número necessário de resets
    if player:getStorageValue(378378) < resetsNeeded then
        player:sendCancelMessage("Você precisa de " .. resetsNeeded .. " resets para realizar esta troca de vocação.")
        return false
    end
    
    -- Verifique se o jogador tem gold coins suficientes para pagar pelo serviço
    if player:getMoney() < cost then
        player:sendCancelMessage("Você precisa de " .. cost .. " gold coins para realizar esta troca de vocação.")
        return false
    end
    
    -- Remova os gold coins e resets do jogador
    player:removeMoney(cost)
    player:setStorageValue(378378, player:getStorageValue(378378) - resetsNeeded)
    
    -- Altere a vocação do jogador para a nova vocação
    player:setVocation(Vocation(newVocationId))
    
    -- Configure as estatísticas do jogador
    player:setStorageValue(PlayerStorageKeys.promotion, 0)
    player:setMagicLevel(0)
    player:setSkill(SKILL_FIST, 10)
    player:setSkill(SKILL_CLUB, 10)
    player:setSkill(SKILL_SWORD, 10)
    player:setSkill(SKILL_AXE, 10)
    player:setSkill(SKILL_DISTANCE, 10)
    player:setMaxHealth(180)
    player:setMaxMana(80)
    player:setMaxCapacity(1000)
    
    -- Envie uma mensagem ao jogador confirmando a troca de vocação
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você trocou de vocação com sucesso!")
    return true
end
 
Criei esse topico pq estou tentando fazer um comando ou npc que consiga trocar a vocação do player para uma vocação nova que criei, mas queria resetar, vida, mana, ml, skills e o storage 378378 (resets), mas ele cobra o dinheiro, troca a classe mas não remove os skills e ml =/
Meu servidor é 1.4 TFS 10.98
i am using TFS 1.4 on tibia 10.98, trying to create one talkaction or npc for change the vocation for the new vocation, i create this npc, for restart the follows attributes: Health, Mana, Skills, Magic level and the storage 378378, while charging a fee and demanding a value on storage. It didn't work as expected, it didn't remove magiclevel, skills, life and mana, it just charged value and storage. And when the user did not have the necessary, he does not say the proposed message

Any can help me ?):



Lua:
function onSay(cid, words, param, channel)
    local player = Player(cid)
    local cost = 10000 -- o custo em gold coins do serviço
    local resetsNeeded = 10 -- o número de resets necessários para a troca de vocação
    local newVocationId = 9 -- o ID da nova vocação que você criou
 
    if not player then
        return false
    end
 
    -- Verifique se o jogador tem o número necessário de resets
    if player:getStorageValue(378378) < resetsNeeded then
        player:sendCancelMessage("Você precisa de " .. resetsNeeded .. " resets para realizar esta troca de vocação.")
        return false
    end
 
    -- Verifique se o jogador tem gold coins suficientes para pagar pelo serviço
    if player:getMoney() < cost then
        player:sendCancelMessage("Você precisa de " .. cost .. " gold coins para realizar esta troca de vocação.")
        return false
    end
 
    -- Remova os gold coins e resets do jogador
    player:removeMoney(cost)
    player:setStorageValue(378378, player:getStorageValue(378378) - resetsNeeded)
 
    -- Altere a vocação do jogador para a nova vocação
    player:setVocation(Vocation(newVocationId))
 
    -- Configure as estatísticas do jogador
    player:setStorageValue(PlayerStorageKeys.promotion, 0)
    player:setMagicLevel(0)
    player:setSkill(SKILL_FIST, 10)
    player:setSkill(SKILL_CLUB, 10)
    player:setSkill(SKILL_SWORD, 10)
    player:setSkill(SKILL_AXE, 10)
    player:setSkill(SKILL_DISTANCE, 10)
    player:setMaxHealth(180)
    player:setMaxMana(80)
    player:setMaxCapacity(1000)
 
    -- Envie uma mensagem ao jogador confirmando a troca de vocação
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você trocou de vocação com sucesso!")
    return true
end
Have you tried using skilltries to 0?

Lua:
player:removeSkillTries(skill, player:getSkillTries(skill))

And
Lua:
player:removeManaSpent(player:getManaSpent())


And looks like you forgot about shielding
 
Last edited:
oh man thanks, i will try this
Post automatically merged:

Have you tried using skilltries to 0?

Lua:
player:removeSkillTries(skill, player:getSkillTries(skill))

And
Lua:
player:removeManaSpent(player:getManaSpent())


And looks like you forgot about shielding
nothin ): the magic level and the skill there was no change
 
Last edited:
@5516593 I doubt it's the case but have you specified skill ID for these functions?
Lua:
for skill = SKILL_FIRST, SKILL_LAST do
    player:removeSkillTries(skill, player:getSkillTries(skill), false)
end
 
Lua:
player:removeSkillTries(skill, player:getSkillTries(skill))
This will only remove skill tries, not base skill level.
Also, there's no "player:setSkill()" or "player:setMagicLevel()" in TFS.
In order to do this right, you must remove both tries and base skill level, like this:

Lua:
player:addSkill(skill, -player:getSkillLevel(skill))
player:removeSkillTries(skill, player:getSkillTries(skill))

Replicate this to every skill. That should do it :)
Post automatically merged:

Oh, in time:

SKILL_CLUB
SKILL_SWORD
SKILL_AXE
SKILL_DISTANCE
SKILL_SHIELD
SKILL_FISHING
SKILL_FIST
SKILL_MAGLEVEL
SKILL_LEVEL (if you want to reset the player's level also)
 
Last edited:
i try this, but the skills don't remove =/ only remove life and mana, cap don't remove

Lua:
function onSay(cid, words, param, channel)
    local player = Player(cid)
    local cost = 10000 -- o custo em gold coins do serviço
    local resetsNeeded = 10 -- o número de resets necessários para a troca de vocação
    local newVocationId = 9 -- o ID da nova vocação que você criou
    
    if not player then
        return false
    end
    
    -- Verifique se o jogador tem o número necessário de resets
    if player:getStorageValue(378378) < resetsNeeded then
        player:sendCancelMessage("Você precisa de " .. resetsNeeded .. " resets para realizar esta troca de vocação.")
        return false
    end
    
    -- Verifique se o jogador tem gold coins suficientes para pagar pelo serviço
    if player:getMoney() < cost then
        player:sendCancelMessage("Você precisa de " .. cost .. " gold coins para realizar esta troca de vocação.")
        return false
    end
    
    -- Remova os gold coins e resets do jogador
    player:removeMoney(cost)
    player:setStorageValue(378378, player:getStorageValue(378378) - resetsNeeded)
    
    -- Altere a vocação do jogador para a nova vocação
    player:setVocation(Vocation(newVocationId))
    
    -- Configure as estatísticas do jogador
    playerid = player:getGuid()
    player:setStorageValue(PlayerStorageKeys.promotion, 0)

    hp = player:getMaxHealth()
  mana = player:getMaxMana()
    resethp = hp*0.1
    resetmana = mana*0.1
    player:setMaxHealth(resethp)
    player:setMaxMana(resetmana)
    player:setMagicLevel(1)
    player:setSkill(SKILL_FIST, 10)
    player:setSkill(SKILL_CLUB, 10)
    player:setSkill(SKILL_SWORD, 10)
    player:setSkill(SKILL_AXE, 10)
    player:setSkill(SKILL_DISTANCE, 10)
    -- Envie uma mensagem ao jogador confirmando a troca de vocação
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você trocou de vocação com sucesso!")
    return true
end
 
@5516593 oserc told you that there are no such things as setSkill on Player.

Lua:
for skill = SKILL_FIRST, SKILL_LAST do
    player:addSkill(skill, -player:getSkillLevel(skill))
    player:removeSkillTries(skill, player:getSkillTries(skill), false)
end
 
@5516593 oserc told you that there are no such things as setSkill on Player.

Lua:
for skill = SKILL_FIRST, SKILL_LAST do
    player:addSkill(skill, -player:getSkillLevel(skill))
    player:removeSkillTries(skill, player:getSkillTries(skill), false)
end
sorry I misunderstood, now that I've done what you said, functional for all but magic
 
Last edited:
no error
Post automatically merged:

stayed like this:
functional for all but for magic
Lua:
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você trocou de vocação com sucesso!")
    local skills = {SKILL_FIST, SKILL_SWORD, SKILL_AXE, SKILL_CLUB, SKILL_DIST, SKILL_MAGLEVEL}
    for _, skill in ipairs(skills) do
    player:addSkill(skill, -player:getSkillLevel(skill))
    player:removeSkillTries(skill, player:getSkillTries(skill), false)
        end
Post automatically merged:

@5516593
Try add that in addition (outside the loop):

Lua:
player:addMagicLevel(-player:getBaseMagicLevel())
oh man, very thanks for this, solved the problem, all right now, you can only say how to reset the cap too ?
 
Last edited:
no error
Post automatically merged:

stayed like this:
functional for all but for magic
Lua:
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você trocou de vocação com sucesso!")
    local skills = {SKILL_FIST, SKILL_SWORD, SKILL_AXE, SKILL_CLUB, SKILL_DIST, SKILL_MAGLEVEL}
    for _, skill in ipairs(skills) do
    player:addSkill(skill, -player:getSkillLevel(skill))
    player:removeSkillTries(skill, player:getSkillTries(skill), false)
        end
Post automatically merged:


oh man, very thanks for this, solved the problem, all right now, you can only say how to reset the cap too ?
player:setCapacity(capacity_amount)
 
That's weired, I thought Player::removeExperience already would update capacity (it even sendStats() to client):
C++:
void Player::removeExperience(uint64_t exp, bool sendText/* = false*/) {
...
    experience = std::max<int64_t>(0, experience - exp);
    uint32_t oldLevel = level;
    uint64_t currLevelExp = Player::getExpForLevel(level);

    while (level > 1 && experience < currLevelExp) {
        --level;
        healthMax = std::max<int32_t>(0, healthMax - vocation->getHPGain());
        manaMax = std::max<int32_t>(0, manaMax - vocation->getManaGain());
        capacity = std::max<int32_t>(0, capacity - vocation->getCapGain());
        currLevelExp = Player::getExpForLevel(level);
    }
...
    sendStats();
 

Similar threads

Back
Top