• 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 TFS 1.2 Promotion Npc for the second promotion.

SlayingWorld

Active Member
Joined
Jan 23, 2014
Messages
156
Reaction score
37
Location
USA
Alright well i tested it on my TFS currently using the latest one, and everything worked fine!
Remember this is just the NPC.lua file, you have to do the rest, vocations.xml, spells, etc

Code:
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

alreadypromoted1    = 'You already have the first promotion, stop wasting my time!'
alreadypromoted2    = 'You already have the second promotion, stop wasting my time!'
nomoney        = 'You do not have enough money.'
firstpromotionlevel    = 'You need level 20+ for the first promotion!'
secondpromotionlevel    = 'You need level 150+ for the second promotion!'
cantskippromo        = 'You have to get the first promotion first!'
    
-- FIRST PROMOTION --
function FirstPromotion(cid, message, keywords, parameters, node)
local player = Player(cid)
local promolevel = 20
local promocost = 20000
    if(not npcHandler:isFocused(cid)) then
        return false
    end
        if player:getLevel() < promolevel then
        selfSay(firstpromotionlevel, cid)
        return false
        end
        if player:getMoney() < promocost then
            selfSay(nomoney, cid)
            return false
        end
        if player:getVocation():getId() == 5 or player:getVocation():getId() == 6 or player:getVocation():getId() == 7 or player:getVocation():getId() == 8 then
        selfSay(alreadypromoted1, cid)
        return false
        end
        if player:getVocation():getId() == 9 or player:getVocation():getId() == 10 or player:getVocation():getId() == 11 or player:getVocation():getId() == 12 then
        selfSay(alreadypromoted2, cid)
        return false
        end
            if player:getVocation():getId() == 1 then
            player:removeMoney(promocost)
            player:setVocation(5)
            elseif player:getVocation():getId() == 2 then
            player:removeMoney(promocost)
            player:setVocation(6)
            elseif player:getVocation():getId() == 3 then
            player:removeMoney(promocost)
            player:setVocation(7)
            elseif player:getVocation():getId() == 4 then
            player:removeMoney(promocost)
            player:setVocation(8)
        end
end        
-- SECOND PROMOTION --
function SecondPromotion(cid, message, keywords, parameters, node)
local player = Player(cid)
local promolevel = 150
local promocost = 200000
    if(not npcHandler:isFocused(cid)) then
        return false
    end
        if player:getLevel() < promolevel then
        selfSay(secondpromotionlevel, cid)
        return false
        end
        if player:getMoney() < promocost then
            selfSay(nomoney, cid)
            return false
        end
        if player:getVocation():getId() == 1 or player:getVocation():getId() == 2 or player:getVocation():getId() == 3 or player:getVocation():getId() == 4 then
        selfSay(cantskippromo, cid)
        return false
        end
        if player:getVocation():getId() == 9 or player:getVocation():getId() == 10 or player:getVocation():getId() == 11 or player:getVocation():getId() == 12 then
        selfSay(alreadypromoted2, cid)
        return false
        end
            if player:getVocation():getId() == 5 then
            player:removeMoney(promocost)
            player:setVocation(9)
            elseif player:getVocation():getId() == 6 then
            player:removeMoney(promocost)
            player:setVocation(10)
            elseif player:getVocation():getId() == 7 then
            player:removeMoney(promocost)
            player:setVocation(11)
            elseif player:getVocation():getId() == 8 then
            player:removeMoney(promocost)
            player:setVocation(12)
        end
end         
         
         
         
         
         
         

node1 = keywordHandler:addKeyword({'first promotion'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to become promoted for 20,000 gold coins?'})
    node1:addChildKeyword({'yes'}, FirstPromotion, {})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Stop wasting my time.', reset = true})

node2 = keywordHandler:addKeyword({'second promotion'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want the second promotion for 200,000 gold coins?'})
    node2:addChildKeyword({'yes'}, SecondPromotion, {})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Stop wasting my time.', reset = true})
   
   
npcHandler:addModule(FocusModule:new())
 
Here m8

Code:
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

alreadypromoted1    = 'You already have the first promotion, stop wasting my time!'
alreadypromoted2    = 'You already have the second promotion, stop wasting my time!'
nomoney1        = 'You do not have enough money. You need 20k for this promotion'
nomoney2        = 'You do not have enough money. You need 150k for this promotion'
firstpromotionlevel    = 'You need level 20+ for the first promotion!'
secondpromotionlevel    = 'You need level 150+ for the second promotion!'
cantskippromo        = 'You have to get the first promotion first!'
first_cost = 20000
first_level = 20
second_cost = 200000
second_level = 150

local vocations = {
[1] = {new_voc = 5, msg = "You are now a Master Sorcerer!"},
[2] = {new_voc = 6, msg = "You are now an Elder Druid!"},
[3] = {new_voc = 7, msg = "You are now a Royal Paladin!"},
[4] = {new_voc = 8, msg = "You are now an Elite Knight!"},
[5] = {new_voc = 9, msg = "You are now a 3rd Sorcerer!"},
[6] = {new_voc = 10, msg = "You are now a 3rd Druid!"},
[7] = {new_voc = 11, msg = "You are now a 3rd Paladin!"},
[8] = {new_voc = 12, msg = "You are now a 3rd Knight!"}
}
   
-- FIRST PROMOTION --
function FirstPromotion(cid, message, keywords, parameters, node)
local player = Player(cid)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
   
    CONFIG = vocations[player:getVocation():getId()]
   
    if not CONFIG then
        selfSay("You are already promoted to the max level.", cid)
        return false
    end
   
    if player:getVocation():getId() < 5 then
        cost = first_cost
        level = first_level
        msg_level = firstpromotionlevel
        msg_cost = nomoney1
    else
        cost = second_cost
        level = second_level
        msg_level = secondpromotionlevel
        msg_cost = nomoney2
    end
   
        if player:getLevel() < level then
            selfSay(msg_level, cid)
        return false
        end
       
        if player:getMoney() < cost then
            selfSay(msg_cost, cid)
            return false
        end
       
        player:removeMoney(cost)
        player:setVocation(CONFIG.id)
        selfSay(CONFIG.msg, cid)      
end

node1 = keywordHandler:addKeyword({'promotion'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to be promoted?'})
    node1:addChildKeyword({'yes'}, FirstPromotion, {})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Stop wasting my time.', reset = true})
   
   
npcHandler:addModule(FocusModule:new())
 
He just likes to flame my comments because he doesn't have a life. Don't mind him.

What he meant to say is: Its optimized but not good enough because i'm an asshole.
 
He just likes to flame my comments because he doesn't have a life. Don't mind him.

What he meant to say is: Its optimized but not good enough because i'm an asshole.
You shouldn't be so hard on yourself, not knowing how to code is one thing, but calling yourself names is another. :(
 
Removing 30 lines out of the code is optimizing even if its not 100%
 
hey, i have a problem with this script, when i try to get promoted, i get the message that i got promoted, and my money is taken, but i dont get the promotion D:
 
hey, i have a problem with this script, when i try to get promoted, i get the message that i got promoted, and my money is taken, but i dont get the promotion D:
Here you have another option:
npc.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Promotion" script="promotionOtland.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100" />
    <look type="130" head="39" body="122" legs="125" feet="57" addons="0" />
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|. You want {first} or {seccond} promotion?" />
    </parameters>
</npc>

script.lua
Code:
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 vocationCount = 4
local config = {
    ["first"] = { lvl = 20, cost = 100, id = 1 },
    ["seccond"] = { lvl = 40, cost = 10000, id = 2 }
}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    local pname = msg:lower()
    local getPromotion = config[pname]
    if not getPromotion then
        return selfSay("The promotion you ask for does not exist.", cid)
    end
    local vocid = player:getVocation():getId()
    local count = math.floor(vocid / vocationCount)
    local canPromotion = (count - getPromotion.id)
    if canPromotion < -1 then
        return selfSay("You still can not acquire this promotion.", cid)
    elseif canPromotion == 1 then
        return selfSay("You can not degrade your promotion.", cid)
    elseif canPromotion == 0 then
        return selfSay(string.format("You already have the %s promotion.", pname), cid)
    end
    if player:getLevel() < getPromotion.lvl then
        return selfSay(string.format("You need level %u+ for the %s promotion.", getPromotion.lvl, pname), cid)
    end
    if not player:removeMoney(getPromotion.cost) then
        return selfSay("You do not have enough money.", cid)
    end
    local newVocation = Vocation(vocid + vocationCount)
    player:setVocation(newVocation)
    selfSay(string.format("You have been successfully promoted to %s.", newVocation:getName()), cid)
    player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Here you have another option:
npc.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Promotion" script="promotionOtland.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100" />
    <look type="130" head="39" body="122" legs="125" feet="57" addons="0" />
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|. You want {first} or {seccond} promotion?" />
    </parameters>
</npc>

script.lua
Code:
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 vocationCount = 4
local config = {
    ["first"] = { lvl = 20, cost = 100, id = 1 },
    ["seccond"] = { lvl = 40, cost = 10000, id = 2 }
}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    local pname = msg:lower()
    local getPromotion = config[pname]
    if not getPromotion then
        return selfSay("The promotion you ask for does not exist.", cid)
    end
    local vocid = player:getVocation():getId()
    local count = math.floor(vocid / vocationCount)
    local canPromotion = (count - getPromotion.id)
    if canPromotion < -1 then
        return selfSay("You still can not acquire this promotion.", cid)
    elseif canPromotion == 1 then
        return selfSay("You can not degrade your promotion.", cid)
    elseif canPromotion == 0 then
        return selfSay(string.format("You already have the %s promotion.", pname), cid)
    end
    if player:getLevel() < getPromotion.lvl then
        return selfSay(string.format("You need level %u+ for the %s promotion.", getPromotion.lvl, pname), cid)
    end
    if not player:removeMoney(getPromotion.cost) then
        return selfSay("You do not have enough money.", cid)
    end
    local newVocation = Vocation(vocid + vocationCount)
    player:setVocation(newVocation)
    selfSay(string.format("You have been successfully promoted to %s.", newVocation:getName()), cid)
    player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
that is what i call optimizing a script, not adding lines
 
Thank you man!! it worked great :D
 
Last edited:
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 promotions = {
    [1] = {cost = 20000, level = 20, name = "first"},
    [2] = {cost = 40000, level = 50, name = "second"}
}
local vocationCount = 4

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if msgcontains(msg, "promotion") then
        local PROMO = false
        local vocId = player:getVocation():getId()
        if vocId <= vocationCount then
            PROMO = promotions[1]
        elseif vocId > vocationCount and vocId < vocationCount * 2
            PROMO = promotions[2]
        end
        if not PROMO then
            return selfSay("You already have both promotions.", cid)
        end
        if player:getLevel() < PROMO.level then
            return selfSay("You must be level "..PROMO.level.." for the "..PROMO.name.." promotion.", cid)
        end
        if not player:removeMoney(PROMO.cost) then
            return selfSay("You need "..PROMO.cost.." gold for the "..PROMO.name.." promotion.", cid)
        end
        player:setVocation(Vocation(vocId + vocationCount))
        selfSay("You have recieved the "..PROMO.name.." promotion.", cid)
        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
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 promotions = {
    [1] = {cost = 20000, level = 20, name = "first"},
    [2] = {cost = 40000, level = 50, name = "second"}
}
local vocationCount = 4

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if msgcontains(msg, "promotion") then
        local PROMO = false
        local vocId = player:getVocation():getId()
        if vocId <= vocationCount then
            PROMO = promotions[1]
        elseif vocId > vocationCount and vocId < vocationCount * 2
            PROMO = promotions[2]
        end
        if not PROMO then
            return selfSay("You already have both promotions.", cid)
        end
        if player:getLevel() < PROMO.level then
            return selfSay("You must be level "..PROMO.level.." for the "..PROMO.name.." promotion.", cid)
        end
        if not player:removeMoney(PROMO.cost) then
            return selfSay("You need "..PROMO.cost.." gold for the "..PROMO.name.." promotion.", cid)
        end
        player:setVocation(Vocation(vocId + vocationCount))
        selfSay("You have recieved the "..PROMO.name.." promotion.", cid)
        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Would it be possible to change instead of money for items?
 
Of course its possible.

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 promotions = {--itemid/amount
    [1] = {items = {{1111, 1}, {1111, 5}}, level = 20, name = "first"},
    [2] = {items = {{1111, 1}, {1111, 5}}, level = 50, name = "second"}
}

local vocationCount = 4

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if msgcontains(msg, "promotion") then
        local PROMO = false
        local vocId = player:getVocation():getId()
        if vocId <= vocationCount then
            PROMO = promotions[1]
        elseif vocId > vocationCount and vocId < vocationCount * 2
            PROMO = promotions[2]
        end
        if not PROMO then
            return selfSay("You already have both promotions.", cid)
        end
        if player:getLevel() < PROMO.level then
            return selfSay("You must be level "..PROMO.level.." for the "..PROMO.name.." promotion.", cid)
        end
        
        local hasItems = true
        local text = "You need"
        for i = 1, #PROMO.items do
            if player:getItem(PROMO.items[i][1]) < PROMO.items[i][2] then
                hasItems = false
                local itemName = ItemType(PROMO.items[i][1]):getName()
                if i == #PROMO.items then
                    text = text.." "..PROMO.items[i][2].." "..itemName.."('s).."."
                else
                    text = text.." "..PROMO.items[i][2].." "..itemName.."('s).." "
                end
            end
        end
        
        if not hasItems then
            return selfSay(text, cid)
        end

        player:setVocation(Vocation(vocId + vocationCount))
        selfSay("You have recieved the "..PROMO.name.." promotion.", cid)
        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Of course its possible.

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 promotions = {--itemid/amount
    [1] = {items = {{1111, 1}, {1111, 5}}, level = 20, name = "first"},
    [2] = {items = {{1111, 1}, {1111, 5}}, level = 50, name = "second"}
}

local vocationCount = 4

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if msgcontains(msg, "promotion") then
        local PROMO = false
        local vocId = player:getVocation():getId()
        if vocId <= vocationCount then
            PROMO = promotions[1]
        elseif vocId > vocationCount and vocId < vocationCount * 2
            PROMO = promotions[2]
        end
        if not PROMO then
            return selfSay("You already have both promotions.", cid)
        end
        if player:getLevel() < PROMO.level then
            return selfSay("You must be level "..PROMO.level.." for the "..PROMO.name.." promotion.", cid)
        end
       
        local hasItems = true
        local text = "You need"
        for i = 1, #PROMO.items do
            if player:getItem(PROMO.items[i][1]) < PROMO.items[i][2] then
                hasItems = false
                local itemName = ItemType(PROMO.items[i][1]):getName()
                if i == #PROMO.items then
                    text = text.." "..PROMO.items[i][2].." "..itemName.."('s).."."
                else
                    text = text.." "..PROMO.items[i][2].." "..itemName.."('s).." "
                end
            end
        end
       
        if not hasItems then
            return selfSay(text, cid)
        end

        player:setVocation(Vocation(vocId + vocationCount))
        selfSay("You have recieved the "..PROMO.name.." promotion.", cid)
        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
otland.png
 
Back
Top