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

Promotion Lua/TFS 1.2

rikaardo25

New Member
Joined
May 22, 2017
Messages
10
Reaction score
0
hello,

im having problem with a new npc that give a promotion, i already got promotion from the king but i want to get a second promotion from the new npc but everytime i ask him for the promotion, it tells me im already promoted...

this is the lua from npc

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({'crusader'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 250000 gold coins. Do you want me to promote you?'})
    node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 250000, level = 150, promotion = 3, text = 'Congratulations! You have been promoted to a Crusader!.'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})

local node2 = keywordHandler:addKeyword({'templar'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 500000 gold coins. Do you want me to promote you?'})
    node2:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 500000, level = 200, promotion = 4, text = 'Congratulations! You have been promoted to a Templar!.'})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you brave enough.', reset = true})

npcHandler:addModule(FocusModule:new())

23:14 Johanna: Greetings, Rikaaa.
23:14 Rikaaa [75]: crusader
23:14 Johanna: I can promote you for 250000 gold coins. Do you want me to promote you?
23:14 Rikaaa [75]: yes
23:14 Johanna: You are already promoted!

also i had like him to check out the requirement if it fit to get promoted...

If anyone know, I appreciate your help
thanks in advance
 
Hi. You have to edit the modules.lua inside npc/scripts/lib/npcsystem. There is a function called promotePlayer where the vocation check is happening.
Code:
if (oldVoc >= 5 and oldVoc <= 8) then
Im using this to check if player is already promoted cause i have only 4 vocations. You can edit this function however you want.
You can copy that function and change the vocationID checking between 5 and 8 that means he already has first promotion and then you can add him the new vocation ID.

You can name the copied function promotePlayer2 and change the StdModule.promotePlayer to StdModule.promotePlayer2 at local node2 where the keyword is templar.
 
Hi. You have to edit the modules.lua inside npc/scripts/lib/npcsystem. There is a function called promotePlayer where the vocation check is happening.
Code:
if (oldVoc >= 5 and oldVoc <= 8) then
Im using this to check if player is already promoted cause i have only 4 vocations. You can edit this function however you want.
You can copy that function and change the vocationID checking between 5 and 8 that means he already has first promotion and then you can add him the new vocation ID.

You can name the copied function promotePlayer2 and change the StdModule.promotePlayer to StdModule.promotePlayer2 at local node2 where the keyword is templar.

tried got errors, or i dont know how to put them... got any idea?

Lua:
--Usage:
        -- local node1 = keywordHandler:addKeyword({"promot"}, StdModule.say, {npcHandler = npcHandler, 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, text = "Allright then. Come back when you are ready."}, reset = true)
    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
    function StdModule.promotePlayer2(cid, message, keywords, parameters, node2)
        local npcHandler = parameters.npcHandler
        if (oldVoc >= 8 and oldVoc <= 10) then
        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)
            elseif (getPlayerPromotionLevel(cid)+1) ~= parameters.promotion then
                npcHandler:say('You need the previous promotion first!', 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
 
tried got errors, or i dont know how to put them... got any idea?

Lua:
--Usage:
        -- local node1 = keywordHandler:addKeyword({"promot"}, StdModule.say, {npcHandler = npcHandler, 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, text = "Allright then. Come back when you are ready."}, reset = true)
    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
    function StdModule.promotePlayer2(cid, message, keywords, parameters, node2)
        local npcHandler = parameters.npcHandler
        if (oldVoc >= 8 and oldVoc <= 10) then
        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)
            elseif (getPlayerPromotionLevel(cid)+1) ~= parameters.promotion then
                npcHandler:say('You need the previous promotion first!', 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

Well you didnt even ended the first function and you put another function inside of it. You have to copy the entire function from the function name to the END where its ending. The end of function is the same distance from the corner as a function if coder is good. Also you have to change the STORAGEVALUE_PROMOTION to another number that youre not using as storage key to save second promo status.

Check THIS and read my comments so you can edit this script.
 

Thanks @Thexamx i will check it right away

Well you didnt even ended the first function and you put another function inside of it. You have to copy the entire function from the function name to the END where its ending. The end of function is the same distance from the corner as a function if coder is good. Also you have to change the STORAGEVALUE_PROMOTION to another number that youre not using as storage key to save second promo status.

Check THIS and read my comments so you can edit this script.

@jakub742 i will try again, and understand it hehehe
 
This is in the wrong place, should be in the support section
 
Back
Top