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

Lua How do I cap other vocations from using the command/getting promoted?

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,085
Solutions
15
Reaction score
379
Location
Sweden
YouTube
Joriku
Hi,
so trying to lock this away from other vocations except for id 0. How do I I check if the vocation is id 0 and if not send a cancel message?

Either that or just seprate so that if id is 0 then put the character to id 9 if level is 250 and cash is 25k then the rest is normal. level 20, 20k for the promotion.
Now that I think about it, the second option is better. If id is 0 then promote to id 9 if level is 250 and payment is 25k
Lua:
-- Promotion
    if player:getVocation():getId() == 0 then
    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? test msg'})
        node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, toVoc = 9, cost = 20000, level = 250, text = 'Congratulations! You are now promoted. test msg'})
        node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
    else
    npcHandler:say("Sorry, this is not the right promotion for you.", npc, creature)
    npcHandler:setTopic(playerId, 1)
    return false
    end

Version 2
Lua:
local cost = 20000
    local level = 20
    local championLevel = 250
  
    local promotion = player:getVocation():getPromotion()  
    if MsgContains(message, 'promotion') then
        if player:getStorageValue(STORAGEVALUE_PROMOTION) == 1 then
            elseif player:getStorageValue(STORAGEVALUE_PROMOTION) == 1 then
                npcHandler:say("You are already promoted!", npc, player)
            elseif player:getVocation() == 0 and player:getLevel() < championLevel then
                selfSay("Test", cid)
                npcHandler:say("I am sorry, but I can only promote you once you have reached level 250.", npc, player)
            elseif player:getLevel() < level then
                npcHandler:say(string.format("I am sorry, but I can only promote you once you have reached level %d.", level), npc, player)
            elseif not player:removeMoneyBank(cost) then
                npcHandler:say("You do not have enough money!", npc, player)
            else
            npcHandler:say("You've been promoted.")
            player:setVocation(promotion)
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
            npcHandler:setTopic(playerId, 1)
        end
    end

Third try
Lua:
local function creatureSayCallback(npc, creature, type, message)
    local player = Player(creature)
    local playerId = player:getId()
    local vocId = player:getVocation()

    if not npcHandler:checkInteraction(npc, creature) then
        return false
    end

    -- Promotion
    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?'})
    if vocId == VOCATION_NONE and player:getLevel() < 250 then
        npcHandler:say("Sorry, but I can only promote you once you have reached level 250.")
        return true
    else
        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
end

Last try for now..
Lua:
local function creatureSayCallback(npc, creature, type, message)
    local player = Player(creature)
    local playerId = player:getId()
    local vocId = player:getVocation()

    if not npcHandler:checkInteraction(npc, creature) then
        return false
    end

    -- Promotion
        if player and player:getVocation() == 0 and player:getLevel() < 250 then
        npcHandler:say("Sorry, but I can only promote you once you have reached level 250.", npc, creature)
        return false
    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
end
 
Last edited:
Solution
Managed to solve it
Lua:
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) -- Double check that you got this on the npc you want to the the script on.

-- Written by Joriku on Otland, using Canary promotion
local function greetCallback(npc, player, message)
    local level = player:getLevel() -- Variable to check player level
    if level < 250 and player:getVocation():getId() == 0 then -- Check if player level is below 250 and vocation is "None" so ID 0
        npcHandler:say("If you are looking for a promotion, I can't promote you since you are below level 250.", npc, player) -- NPC return this message..
        npcHandler:resetNpc(player) -- Reset player, don't think this is needed but I'll leave it in...
Managed to solve it
Lua:
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) -- Double check that you got this on the npc you want to the the script on.

-- Written by Joriku on Otland, using Canary promotion
local function greetCallback(npc, player, message)
    local level = player:getLevel() -- Variable to check player level
    if level < 250 and player:getVocation():getId() == 0 then -- Check if player level is below 250 and vocation is "None" so ID 0
        npcHandler:say("If you are looking for a promotion, I can't promote you since you are below level 250.", npc, player) -- NPC return this message..
        npcHandler:resetNpc(player) -- Reset player, don't think this is needed but I'll leave it in.
        return false
    else
    -- Normal Promotion script, found in Canary
    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_GREET, greetCallback) -- Double check that you got this on the npc you want to the the script on.
 
Solution
Managed to solve it
Lua:
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) -- Double check that you got this on the npc you want to the the script on.

-- Written by Joriku on Otland, using Canary promotion
local function greetCallback(npc, player, message)
    local level = player:getLevel() -- Variable to check player level
    if level < 250 and player:getVocation():getId() == 0 then -- Check if player level is below 250 and vocation is "None" so ID 0
        npcHandler:say("If you are looking for a promotion, I can't promote you since you are below level 250.", npc, player) -- NPC return this message..
        npcHandler:resetNpc(player) -- Reset player, don't think this is needed but I'll leave it in.
        return false
    else
    -- Normal Promotion script, found in Canary
    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_GREET, greetCallback) -- Double check that you got this on the npc you want to the the script on.
Here's a solution to make the promotePlayer module in the NPC library handle it

You can now add a table of vocation id's to the parameters that you want to allow to be promoted - just leave it out or leave it empty if you don't want to restrict it to any vocations
Lua:
node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 250, vocations = {VOCATION_NONE}, text = 'Congratulations! You are now promoted. test msg'})

Replace the module with the code below
Lua:
function StdModule.promotePlayer(npc, player, message, keywords, parameters, node)
	local npcHandler = parameters.npcHandler
	if npcHandler == nil then
		error("StdModule.promotePlayer called without any npcHandler instance.")
	end

	if not npcHandler:checkInteraction(npc, player) then
		return false
	end

	if player:isPremium() or not parameters.premium then
		local playerVocation = player:getVocation()
		local promotion = playerVocation:getPromotion()
		if player:getStorageValue(STORAGEVALUE_PROMOTION) == 1 then
			npcHandler:say("You are already promoted!", npc, player)
		elseif player:getLevel() < parameters.level then
			npcHandler:say(("I am sorry, but I can only promote you once you have reached level %d."):format(parameters.level), npc, player)
		elseif parameters.vocations and #parameters.vocations > 0 and not table.contains(parameters.vocations, playerVocation:getId()) then
			local vocationNames = {}
			for _, id in ipairs(parameters.vocations) do
				local vocation = Vocation(id)
				if vocation then
					table.insert(vocationNames, vocation:getName())
				end
			end

			npcHandler:say(("I can only promote you if you have one of the following vocations: %s."):format(table.concat(vocationNames, ", ")), npc, player)
		elseif not player:removeMoneyBank(parameters.cost) then
			npcHandler:say("You do not have enough money!", npc, player)
		else
			npcHandler:say(parameters.text, npc, player)
			player:setVocation(promotion)
			player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
		end
	else
		npcHandler:say("You need a premium account in order to get promoted.", npc, player)
	end

	npcHandler:resetNpc(player)
	return true
end
 
Here's a solution to make the promotePlayer module in the NPC library handle it

You can now add a table of vocation id's to the parameters that you want to allow to be promoted - just leave it out or leave it empty if you don't want to restrict it to any vocations
Lua:
node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 250, vocations = {VOCATION_NONE}, text = 'Congratulations! You are now promoted. test msg'})

Replace the module with the code below
Lua:
function StdModule.promotePlayer(npc, player, message, keywords, parameters, node)
    local npcHandler = parameters.npcHandler
    if npcHandler == nil then
        error("StdModule.promotePlayer called without any npcHandler instance.")
    end

    if not npcHandler:checkInteraction(npc, player) then
        return false
    end

    if player:isPremium() or not parameters.premium then
        local playerVocation = player:getVocation()
        local promotion = playerVocation:getPromotion()
        if player:getStorageValue(STORAGEVALUE_PROMOTION) == 1 then
            npcHandler:say("You are already promoted!", npc, player)
        elseif player:getLevel() < parameters.level then
            npcHandler:say(("I am sorry, but I can only promote you once you have reached level %d."):format(parameters.level), npc, player)
        elseif parameters.vocations and #parameters.vocations > 0 and not table.contains(parameters.vocations, playerVocation:getId()) then
            local vocationNames = {}
            for _, id in ipairs(parameters.vocations) do
                local vocation = Vocation(id)
                if vocation then
                    table.insert(vocationNames, vocation:getName())
                end
            end

            npcHandler:say(("I can only promote you if you have one of the following vocations: %s."):format(table.concat(vocationNames, ", ")), npc, player)
        elseif not player:removeMoneyBank(parameters.cost) then
            npcHandler:say("You do not have enough money!", npc, player)
        else
            npcHandler:say(parameters.text, npc, player)
            player:setVocation(promotion)
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
        end
    else
        npcHandler:say("You need a premium account in order to get promoted.", npc, player)
    end

    npcHandler:resetNpc(player)
    return true
end
Oh wow, did not even know about it..
Will try it out later and try to update it
 
Back
Top