• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Promotion npc

kamilcioo

Veteran OT User
Joined
Jul 25, 2008
Messages
979
Solutions
1
Reaction score
291
Tried some options but none of them worked. I need a npc who will give promotion. For example:
*You are mage and you can promote to Druid or Sorcerer.
*You are paladin and you can promote to Assassin or Sharpshooter.
*You are knight and you can promote to Berserker or Crusader.

Voc ids:
mage - 1
sorcerer - 4
mage - 5
paladin - 2
assassin - 6
Sharpshooter - 8
Knight - 3
Berserker - 7
Crusader - 9

Tried with this script but bugged:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState = {}
local vocations = 
{
[Begginer] = {Mage, Archer, Knight}
[0] = {1, 2, 3},
[Mage] = {Master Sorcerer, Elder Druid}
[1] = {4, 5},
[Ranger] = {Bow master, Crossbow Master}
[2] = {6, 8},
[Knight] = {Berserker, Crusader}
[3] = {7, 9}
}

local promotions = {}
local choose = {}

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)

if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid

if msg:lower() == "promotion" then
if not vocations[getPlayerVocation(cid)] and getPlayerVocation(cid) > 0 then
return npcHandler:say("You already have the highest promotion.", cid)
end

promotions[cid] = {}
local vocs = vocations[getPlayerVocation(cid)]
local sep = ", "
local i = 0
local text = ""
for _, id in pairs(vocs) do
i = i + 1
if i == #vocs - 1 then
sep = " and "
elseif i == #vocs then
sep = "."
end
text = text .. "{" .. getVocationInfo(id).name .. "}" .. sep
table.insert(promotions[cid], getVocationInfo(id).name:lower())
end
npcHandler:say("You can choose " .. (#vocs > 1 and "one between" or "") .. " the following promotion" .. (#vocs > 1 and "s" or "") .. ": " .. text .. ". Wich will you select?", cid)
talkState[talkUser] = 1
elseif talkState[talkUser] == 1 and isInArray(promotions[cid], msg:lower()) then
npcHandler:say("Are you sure do you want to be promoted to {" .. msg:lower() .. "}?", cid)
talkState[talkUser] = 2
choose[cid] = getVocationByName(msg)
elseif talkState[talkUser] == 2 then
if msg:lower() == "yes" then
doPlayerSetVocation(cid, choose[cid])
npcHandler:say("Congratulations! You have been promoted to " .. getVocationInfo(choose[cid]).name .. ".", cid)
choose[cid] = nil
promotions[cid] = nil
talkState[talkUser] = 0
else
npcHandler:say("Ok then.", cid)
choose[cid] = nil
promotions[cid] = nil
talkState[talkUser] = 0
end
end
return true
end


function getVocationByName(name)
for k, v in pairs(vocations) do
for _, voc in ipairs(v) do
if getVocationInfo(voc).name:lower() == name:lower() then
return voc
end
end
end
return 0
end

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

Attachments

f.png
Code:
local vocations = {
    [1] = {4, 5},
    [2] = {6, 8},
    [3] = {7, 9}
}

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 talkState, choose, text = {}, 0, ""

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
    local v = getPlayerVocation(cid)
  
    if (msgcontains(msg, 'no')) then
        selfSay("Ok. Maybe next time.", cid)
        npcHandler:resetNpc()
    elseif (msgcontains(msg, 'heal')) then
        local hp = getCreatureHealth(cid)
        local pos = getCreaturePosition(cid)
        if hp < 65 then
            doCreatureAddHealth(cid, 65-hp)
            doSendMagicEffect(pos, CONST_ME_MAGICBLUE)
            doRemoveConditions(cid)
            selfSay("Here you are.", cid)
        else
            selfSay("I cannot help you.", cid)
        end
    elseif (msgcontains(msg, 'promotion') then
        if isInArray(vocations, v) then
            for i = 1, #vocations[v] do
                text = text.. " {" ..getVocationInfo(vocations[v].[i]).name.. "}"
                if i < #vocations[v] then
                    text = text.. ","
                else
                    text = text.. "."
                end
            end
            selfSay("Young " ..getVocationInfo(v).name.. ". Hmm, which one you would like to be: " ..text, cid)
            talkState[talkUser] = 1
        else
            selfSay("I can\'t promote you. Maybe you already have the highest promotion?", cid)
            npcHandler:resetNpc()
        end
    end
    if talkState[talkUser] == 1 then
        for j = 1, #vocations[v] do
            if msgcontains(msg, getVocationInfo(vocations[v].[j]).name) then
                choose = j
                selfSay("You choosen a " ..getVocationInfo(vocations[v].[j]).name.. ". This decision is IRREVERSIBLE. So, do you want to be a " ..getVocationInfo(vocations[v].[j]).name.. "?", cid)
                talkState[talkUser] = 2
            else
                selfSay("Don\'t waste my time.", cid)
                npcHandler:resetNpc()
            end
        end
    elseif talkState[talkUser] == 2 and msgcontains(msg, "yes") then
        doPlayerSetVocation(cid, choose)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGICBLUE)
        selfSay("Congratulations! You have been promoted to " .. getVocationInfo(choose).name .. ".", cid)
        npcHandler:resetNpc()
    end
  
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
37 lined bugged but I found answer
This
Code:
elseif (msgcontains(msg, 'promotion') then
to this
Code:
elseif (msgcontains(msg, 'promotion')) then

But then 41 line is bugged. Any idea?
 
Code:
local vocations = {
    [1] = {4, 5},
    [2] = {6, 8},
    [3] = {7, 9}
}

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 talkState, choose, text = {}, 0, ""

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
    local v = getPlayerVocation(cid)
    if msgcontains(msg, 'no') then
        selfSay("Ok. Maybe next time.", cid)
        npcHandler:resetNpc()
    elseif msgcontains(msg, 'heal') then
        local hp = getCreatureHealth(cid)   
        local pos = getCreaturePosition(cid)
        if hp < 65 then
            doCreatureAddHealth(cid, 65-hp)
            doSendMagicEffect(pos, CONST_ME_MAGICBLUE)
            doRemoveConditions(cid)
            selfSay("Here you are.", cid)
        else
            selfSay("I cannot help you.", cid)
        end
    elseif msgcontains(msg, 'promotion') then
        if isInArray(vocations, v) then
            for i = 1, #vocations[v] do
                text = text.. " {" ..getVocationInfo(vocations[v][i]).name.. "}"
                if i < #vocations[v] then
                    text = text.. ","
                end
            end
            selfSay("Young " ..getVocationInfo(v).name.. ". Hmm, which one you would like to be:" ..text.. ".", cid)
            talkState[talkUser] = 1
        else
            selfSay("I can\'t promote you. Maybe you already have the highest promotion?", cid)
            npcHandler:resetNpc()
        end
    end
    if talkState[talkUser] == 1 then
        for j = 1, #vocations[v] do
            if msgcontains(msg, getVocationInfo(vocations[v][j]).name) then
                choose = j
                selfSay("You choosen a " ..getVocationInfo(vocations[v][j]).name.. ". This decision is IRREVERSIBLE. So, do you want to be a " ..getVocationInfo(vocations[v][j]).name.. "?", cid)
                talkState[talkUser] = 2
            else
                selfSay("Don\'t waste my time.", cid)
                npcHandler:resetNpc()
            end
        end
    elseif talkState[talkUser] == 2 and msgcontains(msg, "yes") then
        doPlayerSetVocation(cid, choose)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGICBLUE)
        selfSay("Congratulations! You have been promoted to " .. getVocationInfo(choose).name .. ".", cid)
        npcHandler:resetNpc()
    end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
It's only a minimal bug, forgot to close the function with end.
Code:
local vocations = {
    [1] = {4, 5},
    [2] = {6, 8},
    [3] = {7, 9}
}

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 talkState, choose, text = {}, 0, ""

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
    local v = getPlayerVocation(cid)
    if msgcontains(msg, 'no') then
        selfSay("Ok. Maybe next time.", cid)
        npcHandler:resetNpc()
    elseif msgcontains(msg, 'heal') then
        local hp = getCreatureHealth(cid)  
        local pos = getCreaturePosition(cid)
        if hp < 65 then
            doCreatureAddHealth(cid, 65-hp)
            doSendMagicEffect(pos, CONST_ME_MAGICBLUE)
            doRemoveConditions(cid)
            selfSay("Here you are.", cid)
        else
            selfSay("I cannot help you.", cid)
        end
    elseif msgcontains(msg, 'promotion') then
        if isInArray(vocations, v) then
            for i = 1, #vocations[v] do
                text = text.. " {" ..getVocationInfo(vocations[v][i]).name.. "}"
                if i < #vocations[v] then
                    text = text.. ","
                end
            end
            selfSay("Young " ..getVocationInfo(v).name.. ". Hmm, which one you would like to be:" ..text.. ".", cid)
            talkState[talkUser] = 1
        else
            selfSay("I can\'t promote you. Maybe you already have the highest promotion?", cid)
            npcHandler:resetNpc()
        end
    end
    if talkState[talkUser] == 1 then
        for j = 1, #vocations[v] do
            if msgcontains(msg, getVocationInfo(vocations[v][j]).name) then
                choose = j
                selfSay("You choosen a " ..getVocationInfo(vocations[v][j]).name.. ". This decision is IRREVERSIBLE. So, do you want to be a " ..getVocationInfo(vocations[v][j]).name.. "?", cid)
                talkState[talkUser] = 2
            else
                selfSay("Don\'t waste my time.", cid)
                npcHandler:resetNpc()
            end
        end
    elseif talkState[talkUser] == 2 and msgcontains(msg, "yes") then
        doPlayerSetVocation(cid, choose)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGICBLUE)
        selfSay("Congratulations! You have been promoted to " .. getVocationInfo(choose).name .. ".", cid)
        npcHandler:resetNpc()
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
No bug in console but he doesn't wanna give me promotion. He's saying that I have the highest even when I'm voc 1,2 or 3.
Promo: I can't promote you. Maybe you already have the highest promotion?
 
Back
Top