• 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 Promotion NPC

Kinocks

New Member
Joined
Mar 3, 2021
Messages
5
Reaction score
0
Hey guys,

I was seeing a lot of topics about it, but none were finalized.
Many parts of the bugs I fixed, but there is one last one that I can't fix.



I created 4 new vocations in my vocation.xml, I added this in several places in the sources, now I am finishing the NPC.
The NPC works, it promotes players from 5 to 9, 6 to 10 etc. BUT, I need a little help to:

If the player does not have the FIRST promotion, he will not be able to purchase the SECOND promotion.

So, here my codes.

First I added a new module in /data/npc/lib/npcsystem/modules.lua

Lua:
function StdModule.secondPromotePlayer(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if npcHandler == nil then
            error("StdModule.secondPromotePlayer 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) == 2 then
                npcHandler:say("You are already promoted!", cid)
            elseif player:getStorageValue(STORAGEVALUE_PROMOTION) < 1 then
            npcHandler:say("You need have the {first} promotion!", 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 getPlayerItemCount(cid, parameters.item) < parameters.qtd then
                npcHandler:say("You do not have the items!", cid)
            elseif not player:removeMoneyNpc(parameters.cost) then
                npcHandler:say("You do not have enough money!", cid)
            else
                doPlayerRemoveItem(cid, parameters.item, parameters.qtd)
                npcHandler:say(parameters.text, cid)
                player:setVocation(promotion)
                player:setStorageValue(STORAGEVALUE_PROMOTION, 2)
            end
        else
            npcHandler:say("You need a premium account in order to get promoted.", cid)
        end
        npcHandler:resetNpc(cid)
        return true
    end

After that, I created the npc, I called him "Old Master".

XML

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Old Master" walkinterval="2000" floorchange="0" script="old_master.lua">
<mana now="800" max="800"/>
<health now="200" max="200"/>
<look type="302" head="78" body="94" legs="132" feet="115"/>
</npc>

Here old_master.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)   
local var1 = getPlayerVocation(cid)
local promoteKeyword = keywordHandler:addKeyword({'firs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you a first time for 50.000 gold coins. Do you want me to promote you?'})
promoteKeyword:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 50000, level = 50, promotion = 1, text = 'Congratulations! You are now promoted.'})
promoteKeyword:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
    
local promotedKeyword = keywordHandler:addKeyword({"secon"}, StdModule.say, {npcHandler = npcHandler, text = "I can promote you for 2.000.000 gold coins and 100 Scarab Coin. Do you want me to promote you?"})
promotedKeyword:addChildKeyword({"yes"}, StdModule.secondPromotePlayer, {npcHandler = npcHandler, cost = 2000000, level = 200, item = 2159, qtd = 100, promotion = 2, text = 'Congratulations! You are now promoted.'})
promotedKeyword:addChildKeyword({"no"}, StdModule.say, {npcHandler = npcHandler, text = "Allright then. Come back when you are ready.", reset = true})



npcHandler:setMessage(MESSAGE_GREET, 'Welcome |PLAYERNAME|. I am the old master of this town, I can promote you to the high level of you vocation. Just tell me if you wanna a {first} or {second} promotion.')
npcHandler:setMessage(MESSAGE_FAREWELL, 'Good bye, |PLAYERNAME|!')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Good bye, |PLAYERNAME|!')

npcHandler:addModule(FocusModule:new())

So, I have two problems here

First, If one player with no promotion tries to talk to him and say "second" he will be promoted (if have 2kk, 100 scarab coins and lvl 200). And He will become Vocation{5~9} after that he can bought the first promotion and become vocation {10~12}
I tried use this line on modules to block this:
Lua:
elseif player:getStorageValue(STORAGEVALUE_PROMOTION) < 1 then
            npcHandler:say("You need have the {first} promotion!", cid)

But it didn't works.

Second, After fixing that part, I would like to change the vocation items, example, Knight will bring 100 green scales, druid 100 scarab coins, etc...

Can someone bring me ideas to fix this?

Thanks a lot.
 
Back
Top