• 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+ Problem with promotion npc

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
921
Location
Chile
Hello guys! I have a script for a npc that allows people to be promoted again.I have knights, elite knights and senior knights...and well ofc all the other vocations respective's promotions
So this npc is supose to promote you if youhave the first promotion(elite, elder, etc)
but right now, when players say the keyword "senior", he says: you already have the X(senior) promotion :/

can anyone plz help me figuring this out? i can't fully understand the script
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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

local vocationCount = 4
local config = {
    ["first"] = { lvl = 20, cost = 1, id = 1 },
    ["senior"] = { lvl = 200, cost = 500000, id = 2 }
}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    local pname = msg:lower()
    local getPromotion = config[pname]
    if not getPromotion then
        return selfSay("The promotion you ask for does not exist.", cid)
    end
    local vocid = player:getVocation():getId()
    local count = math.floor(vocid / vocationCount)
    local canPromotion = (count - getPromotion.id)
    if canPromotion < -1 then
        return selfSay("You still can not acquire this promotion.", cid)
    elseif canPromotion == 1 then
        return selfSay("You can not degrade your promotion.", cid)
    elseif canPromotion == 0 then
        return selfSay(string.format("You already have the %s promotion.", pname), cid)
    end
    if player:getLevel() < getPromotion.lvl then
        return selfSay(string.format("You need level %u+ for the %s promotion.", getPromotion.lvl, pname), cid)
    end
    if not player:removeMoney(getPromotion.cost) then
        return selfSay("You do not have enough money.", cid)
    end
    local newVocation = Vocation(vocid + vocationCount)
    player:setVocation(newVocation)
    selfSay(string.format("You have been successfully promoted to %s.", newVocation:getName()), cid)
    player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Thanks in advance!!
 
Solution
I assume you have the default vocations.xml ids, so knights are 4, elite knights are 8 and seniors would be 12
taking this into consideration, an elite knight would have "vocid" 8
Lua:
local count = math.floor(vocid / vocationCount)
local canPromotion = (count - getPromotion.id)
8 / 4 = 2, so when you subtract getPromotion.id (for senior, 2) it becomes 0
instead, you should do
Lua:
local count = math.floor((vocid - 1) / vocationCount)
local canPromotion = (count - getPromotion.id)
which will result in 0 for basic vocations and 1 for every first promotion, thus giving you the -1 on canPromotion
I assume you have the default vocations.xml ids, so knights are 4, elite knights are 8 and seniors would be 12
taking this into consideration, an elite knight would have "vocid" 8
Lua:
local count = math.floor(vocid / vocationCount)
local canPromotion = (count - getPromotion.id)
8 / 4 = 2, so when you subtract getPromotion.id (for senior, 2) it becomes 0
instead, you should do
Lua:
local count = math.floor((vocid - 1) / vocationCount)
local canPromotion = (count - getPromotion.id)
which will result in 0 for basic vocations and 1 for every first promotion, thus giving you the -1 on canPromotion
 
Solution
I assume you have the default vocations.xml ids, so knights are 4, elite knights are 8 and seniors would be 12
taking this into consideration, an elite knight would have "vocid" 8
Lua:
local count = math.floor(vocid / vocationCount)
local canPromotion = (count - getPromotion.id)
8 / 4 = 2, so when you subtract getPromotion.id (for senior, 2) it becomes 0
instead, you should do
Lua:
local count = math.floor((vocid - 1) / vocationCount)
local canPromotion = (count - getPromotion.id)
which will result in 0 for basic vocations and 1 for every first promotion, thus giving you the -1 on canPromotion
Thank you man! It worked perfectly :D
 
I assume you have the default vocations.xml ids, so knights are 4, elite knights are 8 and seniors would be 12
taking this into consideration, an elite knight would have "vocid" 8
Lua:
local count = math.floor(vocid / vocationCount)
local canPromotion = (count - getPromotion.id)
8 / 4 = 2, so when you subtract getPromotion.id (for senior, 2) it becomes 0
instead, you should do
Lua:
local count = math.floor((vocid - 1) / vocationCount)
local canPromotion = (count - getPromotion.id)
which will result in 0 for basic vocations and 1 for every first promotion, thus giving you the -1 on canPromotion
sorry to bring an old post but I had a question. What if my vocations count would be higher? like instead of having only 4 vocations I have 3 more or 4 more? Do I put vocationCount = 8? so that way it does the vocid -1 / 8) for example?
 
Back
Top