NPC TFS 1.2 Promotion Npc for the second promotion.

SlayingWorld

Active Member
Joined
Jan 23, 2014
Messages
122
Best answers
0
Reaction score
29
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())
 

Itutorial

Veteran OT User
Joined
Dec 23, 2014
Messages
1,542
Best answers
35
Reaction score
379
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())
 
OP
SlayingWorld

SlayingWorld

Active Member
Joined
Jan 23, 2014
Messages
122
Best answers
0
Reaction score
29
Location
USA
Nice bro, havent tested it, but thanks for optimizing mine :D
 

Itutorial

Veteran OT User
Joined
Dec 23, 2014
Messages
1,542
Best answers
35
Reaction score
379
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.
 

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,998
Best answers
11
Reaction score
1,530
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. :(
 

Itutorial

Veteran OT User
Joined
Dec 23, 2014
Messages
1,542
Best answers
35
Reaction score
379
Removing 30 lines out of the code is optimizing even if its not 100%
 

Thorn

Spriting since 2013
Premium User
Joined
Sep 24, 2012
Messages
2,188
Best answers
1
Reaction score
853
Location
Chile
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:
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Joined
Mar 16, 2017
Messages
488
Best answers
43
Reaction score
296
Location
London
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())
 

Evil Puncker

I'd rather kiss a rattlesnake
Joined
May 30, 2009
Messages
5,932
Best answers
34
Reaction score
1,875
Location
160,54,7
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
 

Thorn

Spriting since 2013
Premium User
Joined
Sep 24, 2012
Messages
2,188
Best answers
1
Reaction score
853
Location
Chile
Thank you man!! it worked great :D
 
Last edited:
Top