• 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!

Npc promotion system 1.2

tnecniiv

scripter to be
Joined
Jan 6, 2012
Messages
294
Solutions
3
Reaction score
23
hello guys i need help with an npc that will check for level 50 and offer a promotion but the promotion branches out to two different types of vocations the promotion will cost 30,000
so for instance
let say i have a knight that is level 50
he could have a choice to go to a defender or the knight could choose the attacker route.
i made the vocations they have the same type of client ids and they both have the vocation from knight
i just cant figure out how to script this NPC and the npc will offer both paths. once i see how this is made i will turn it into my other vocations. Thank you for your time reading this request
 
forgottenserver/promotion.lua at master · otland/forgottenserver · GitHub
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 node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
    node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})

npcHandler:addModule(FocusModule:new())
Instead of saying "Do you want me to promote you?", you can make him say something along the likes of: "Do you want me to promote you into a defender or a berserker?".
Then you add child keywords (defender, beserker) with the StdModule.promotePlayer callback.

Then edit StdModule.promotePlayer:
forgottenserver/modules.lua at master · otland/forgottenserver · GitHub
Lua:
    function StdModule.promotePlayer(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if npcHandler == nil then
            error("StdModule.promotePlayer called without any npcHandler instance.")
        end

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

        local player = Player(cid)
        if player:isPremium() or not parameters.premium then
            local promotion = player:getVocation():getPromotion()
            if player:getStorageValue(STORAGEVALUE_PROMOTION) == 1 then
                npcHandler:say("You are already promoted!", cid)
            elseif player:getLevel() < parameters.level then
                npcHandler:say("I am sorry, but I can only promote you once you have reached level " .. parameters.level .. ".", cid)
            elseif not player:removeMoney(parameters.cost) then
                npcHandler:say("You do not have enough money!", cid)
            else
                npcHandler:say(parameters.text, cid)
                player:setVocation(promotion)
                player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
            end
        else
            npcHandler:say("You need a premium account in order to get promoted.", cid)
        end
        npcHandler:resetNpc(cid)
        return true
    end
Modify it to see if message contains defender or berserker, and add the custom Lua code to transfer you to the correct vocationid/promotion.
 
yes but how would i be able to make them choose for instance if he wants to go to a defender from a knight
knight to defender
or knight to bezerker i dont see where i would put the vocationsID
 
Never been any good at NPC coding, but try this:

promotion.lua:
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 player = Player(cid)
if player:getVocation() == 4 then
    local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want to become a {berserker} or a {defender}?'})
        node1:addChildKeyword({'berserker'}, StdModule.promoteKnight, {npcHandler = npcHandler, toVoc = 8, cost = 20000, level = 20, text = 'Congratulations! You are now promoted to a berserker.'})
        node1:addChildKeyword({'defender'}, StdModule.promoteKnight, {npcHandler = npcHandler, toVoc = 12, cost = 20000, level = 20, text = 'Congratulations! You are now promoted to a defender.'})
        node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
else
    local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
        node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
        node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
end

npcHandler:addModule(FocusModule:new())
In berserker og defender keywords, change toVoc = 8, to correct promotion vocation.

Add this below function StdModule.promotePlayer in npc modules.lua
Lua:
    function StdModule.promoteKnight(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if npcHandler == nil then
            error("StdModule.promoteKnight called without any npcHandler instance.")
        end
        local promotion = parameters.toVoc
        if promotion == nil then
             error("StdModule.promoteKnight called without specifying promoted vocation id (toVoc)")
        end

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

        local player = Player(cid)
        if player:isPremium() or not parameters.premium then
            if player:getStorageValue(STORAGEVALUE_PROMOTION) == 1 then
                npcHandler:say("You are already promoted!", cid)
            elseif player:getLevel() < parameters.level then
                npcHandler:say("I am sorry, but I can only promote you once you have reached level " .. parameters.level .. ".", cid)
            elseif not player:removeMoney(parameters.cost) then
                npcHandler:say("You do not have enough money!", cid)
            else
                npcHandler:say(parameters.text, cid)
                player:setVocation(promotion)
                player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
            end
        else
            npcHandler:say("You need a premium account in order to get promoted.", cid)
        end
        npcHandler:resetNpc(cid)
        return true
    end
 
Last edited:
added and i come up with this in my console
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/promotion.lua
data/npc/scripts/promotion.lua:11: attempt to index local 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/npc/scripts/promotion.lua:11: in main chunk
[Warning - NpcScript::NpcScript] Can not load script: promotion.lua
 
added and i come up with this in my console
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/promotion.lua
data/npc/scripts/promotion.lua:11: attempt to index local 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/npc/scripts/promotion.lua:11: in main chunk
[Warning - NpcScript::NpcScript] Can not load script: promotion.lua

Lua:
local player = Player(cid)
if not player then
    return false
end
 
it reads the script but the npc doesnt say anything when i say hi he just walks around

Give this a try, just like @Znote im also really bad at NPCs, but if this dosn't work you have to code the child keywords into the creatureSayCallback function.
.. Or maybe recode the StdModule.promotePlayer function.

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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    if player and player:getVocation() == 4 then
        local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want to become a {berserker} or a {defender}?'})
        node1:addChildKeyword({'berserker'}, StdModule.promoteKnight, {npcHandler = npcHandler, toVoc = 8, cost = 20000, level = 20, text = 'Congratulations! You are now promoted to a berserker.'})
        node1:addChildKeyword({'defender'}, StdModule.promoteKnight, {npcHandler = npcHandler, toVoc = 12, cost = 20000, level = 20, text = 'Congratulations! You are now promoted to a defender.'})
        node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
    else
        local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
        node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
        node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
so we are all bad at scripting npcs :D that's funny to me, npcs are a wreck to script for me aswell.
He talks to me now just doesn't offer me the choices to get promoted to a bezerker or defender:(i am also trying to get rid of the promotion option for other vocations and make it strictly for knights only. i plan on making a certain npc for each vocation. i tried using "~=" boolean to check if he isnt a knight but no luck there
 
so we are all bad at scripting npcs :D that's funny to me, npcs are a wreck to script for me aswell.
He talks to me now just doesn't offer me the choices to get promoted to a bezerker or defender:(i am also trying to get rid of the promotion option for other vocations and make it strictly for knights only. i plan on making a certain npc for each vocation. i tried using "~=" boolean to check if he isnt a knight but no luck there

Add like "print("1")" and change out 1 for another number at the next if statment etc and see if the code is loaded.
I would probbly just write the code from scratch, it's not the best way but IMO the best option if you don't want a bunch of problems.

Ye NPCs are a huge mess IMO
 
there all these different functions that i dont know when scripting npcs and all the tutorials is outdated even the scripting items tutorials now-a-days are outdated, i dont know where to begin. ill try from the top again.
 
Back
Top