Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 blessMsgs =
- {
- 'You have been blessed with the Spiritual Shielding.',
- 'You have been blessed with the Spark of the Phoenix.',
- 'You have been blessed with the Embrace of Tibia.',
- 'You have been blessed with the Fire of the Suns.',
- 'You have been blessed with the Wisdom of Solitude.'
- }
- local chooseBless = {}
- local function creatureSayCallback(cid, type, msg)
- if not npcHandler:isFocused(cid) then
- return false
- end
- local msg = msg:lower()
- local player = Player(cid)
- if npcHandler.topic[ cid ] == 0 then
- if ( msg == "heal" ) then
- if player:getHealth() < 50 then
- player:addHealth(50 - player:getHealth())
- local conditions = {CONDITION_POISON, CONDITION_FIRE, CONDITION_ENERGY, CONDITION_BLEEDING, CONDITION_PARALYZE, CONDITION_DROWN, CONDITION_FREEZING, CONDITION_DAZZLED, CONDITION_CURSED}
- for i = 1, #conditions do
- if player:getCondition(conditions[i]) then
- player:removeCondition(conditions[i])
- end
- end
- npcHandler:say("You are hurt, my child. I will heal your wounds.", cid)
- else
- npcHandler:say("You aren't looking that bad. Sorry, I can't help you. But if you are looking for additional protection you should go on the {pilgrimage} of ashes or get the protection of the {twist of fate} here.", cid)
- end
- elseif isInArray( { "blessing", "blessings" }, msg ) then
- local amount = player:getBlessings()
- npcHandler:say( string.format( "There are five blessings available in five sacred places: the {spiritual} shielding, the spark of the {phoenix}, the {embrace} of Tibia, the fire of the {suns} and the wisdom of {solitude}. You have %d out of 5 blessings. I can also provide you with {all} blessings at once. Additionally, you can also receive the {twist of fate} here.", amount ), cid )
- npcHandler.topic[ cid ] = 2
- end
- elseif ( npcHandler.topic[ cid ] == 2 ) then
- local cost = getBlessingsCost(player:getLevel())
- if isInArray( { "spiritual", "spiritual shielding" }, msg ) then
- npcHandler:say( string.format( "For %d gold coins I will bless you with the Spiritual Shielding. Is that okay?", cost ), cid )
- chooseBless[ cid ] = 1
- npcHandler.topic[cid] = 3
- elseif isInArray( { "phoenix", "spark of the phoenix" }, msg ) then
- npcHandler:say( string.format( "For %d gold coins I will bless you with the Spark of the Phoenix. Is that okay?", cost ), cid )
- chooseBless[ cid ] = 2
- npcHandler.topic[cid] = 3
- elseif isInArray( { "embrace", "embrace of tibia" }, msg ) then
- npcHandler:say( string.format( "For %d gold coins I will bless you with the Embrace of Tibia. Is that okay?", cost ), cid )
- chooseBless[ cid ] = 3
- npcHandler.topic[cid] = 3
- elseif isInArray( { "suns", "fire of the suns" }, msg ) then
- npcHandler:say( string.format( "For %d gold coins I will bless you with the Fire of the Suns. Is that okay?", cost ), cid )
- chooseBless[ cid ] = 4
- npcHandler.topic[cid] = 3
- elseif isInArray( { "solitude", "wisdom of solitude" }, msg ) then
- npcHandler:say( string.format( "For %d gold coins I will bless you with the Wisdom of Solitude. Is that okay?", cost ), cid )
- chooseBless[ cid ] = 5
- npcHandler.topic[cid] = 3
- elseif ( msg == "twist of fate" ) then
- npcHandler:say({
- "This is a special blessing I can bestow upon you once you have obtained at least one of the other blessings and which functions a bit differently. ...",
- "It only works when you're killed by other adventurers, which means that at least half of the damage leading to your death was caused by others, not by monsters or the environment. ...",
- "The {twist of fate} will not reduce the death penalty like the other blessings, but instead prevent you from losing your other blessings as well as the amulet of loss, should you wear one. It costs the same as the other blessings. ...",
- "Would you like to receive that protection for a sacrifice of " .. getPvpBlessingCost(player:getLevel()) .. " gold, child?"
- }, cid)
- npcHandler.topic[cid] = 1
- elseif ( msg == "all" ) then
- if player:getBlessings() == 5 then
- npcHandler:say("You already possess all blessings.", cid )
- npcHandler.topic[cid] = 0
- return true
- end
- npcHandler:say( string.format( "For %d gold coins, I will bless you with all the blessings you don't already have. Is that okay?", player:getBlessingPrices() ), cid )
- npcHandler.topic[cid] = 4
- elseif ( msg == "no" ) then
- npcHandler:say("Fine. You are free to decline my offer.", cid)
- npcHandler.topic[cid] = 0
- else
- npcHandler:say( "I can't understand you.", cid )
- npcHandler.topic[cid] = 0
- end
- elseif ( msg == "yes" ) then
- if npcHandler.topic[cid] == 1 then
- if player:getBlessings() > 0 or player:getItemCount(2173) > 0 then
- if not player:hasBlessing(6) then
- if player:removeMoney(getPvpBlessingCost(player:getLevel())) then
- player:addBlessing(6)
- npcHandler:say("So receive the protection of the twist of fate, pilgrim.", cid)
- else
- npcHandler:say("Oh. You do not have enough money.", cid)
- end
- else
- npcHandler:say("You already possess this blessing.", cid)
- end
- else
- npcHandler:say("You don't have any of the other blessings nor an amulet of loss, so it wouldn't make sense to bestow this protection on you now. Remember that it can only protect you from the loss of those!", cid)
- end
- npcHandler.topic[cid] = 0
- elseif npcHandler.topic[cid] == 3 then
- local cost = getBlessingsCost(player:getLevel())
- if player:hasBlessing( chooseBless[ cid ] ) then
- npcHandler:say("Gods have already blessed you with this blessing!", cid)
- else
- if player:removeMoney( cost ) then
- npcHandler:say( blessMsgs[ chooseBless[ cid ] ], cid )
- player:addBlessing( chooseBless[ cid ] )
- player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
- else
- npcHandler:say("Oh. You do not have enough money.", cid)
- end
- end
- npcHandler.topic[cid] = 0
- elseif npcHandler.topic[cid] == 4 then
- if player:getBlessingsCount( ) == 6 then
- npcHandler:say("You already possess all blessings.", cid)
- else
- local allCost = player:getBlessingPrices()
- if player:removeMoney( allCost ) then
- player:addAllBlessings()
- player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
- npcHandler:say( "Now you have been blessed by all five Gods!", cid )
- else
- npcHandler:say("Oh. You do not have enough money.", cid)
- end
- end
- npcHandler.topic[cid] = 0
- end
- elseif ( msg == "no" ) and npcHandler.topic[cid] >= 1 then
- npcHandler:say("Fine. You are free to decline my offer.", cid)
- npcHandler.topic[cid] = 0
- elseif npcHandler.topic[ cid ] >= 1 then
- npcHandler:say( "I can't understand you.", cid )
- npcHandler.topic[cid] = 0
- end
- return true
- end
- keywordHandler:addKeyword({'pilgrimage'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Whenever you receive a lethal wound, your vital force is damaged and there is a chance that you lose some of your equipment. With every single of the five {blessings} you have, this damage and chance of loss will be reduced.'})
- --[[
- keywordHandler:addKeyword({'spiritual'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can ask for the blessing of spiritual shielding in the whiteflower temple south of Thais.'})
- keywordHandler:addKeyword({'phoenix'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The spark of the phoenix is given by the dwarven priests of earth and fire in Kazordoon.'})
- keywordHandler:addKeyword({'embrace'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The druids north of Carlin will provide you with the embrace of Tibia.'})
- keywordHandler:addKeyword({'suns'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can ask for the blessing of the two suns in the suntower near Ab\'Dendriel.'})
- keywordHandler:addKeyword({'solitude'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Talk to the hermit Eremo on the isle of Cormaya about this blessing.'})
- --]]
- npcHandler:setMessage(MESSAGE_GREET, "Welcome, young |PLAYERNAME|! If you are heavily wounded or poisoned, I can {heal} you for free.")
- npcHandler:setMessage(MESSAGE_WALKAWAY, "Remember: If you are heavily wounded or poisoned, I can heal you for free.")
- npcHandler:setMessage(MESSAGE_FAREWELL, "May the gods bless you, |PLAYERNAME|!")
- npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
- npcHandler:addModule(FocusModule:new())
- ynpc = YNPC:new( npcHandler )
- --ynpc:initialize()
- local HEAL = 1
- local BLESSINGS = 2
- local CHOOSEBLESSINGS = 3
- local BLESSINGYES = 4
- local BLESSINGNO = 5
- local DONTUNDERSTAND = 6
- local function healPlayer( cid )
- local player = Player( cid )
- if player:getHealth() < 50 then
- player:addHealth(50 - player:getHealth())
- local conditions = {CONDITION_POISON, CONDITION_FIRE, CONDITION_ENERGY, CONDITION_BLEEDING, CONDITION_PARALYZE, CONDITION_DROWN, CONDITION_FREEZING, CONDITION_DAZZLED, CONDITION_CURSED}
- for i = 1, #conditions do
- if player:getCondition(conditions[i]) then
- player:removeCondition(conditions[i])
- end
- end
- npcHandler:say("You are hurt, my child. I will heal your wounds.", cid)
- else
- npcHandler:say("You aren't looking that bad. Sorry, I can't help you. But if you are looking for additional protection you should go on the {pilgrimage} of ashes or get the protection of the {twist of fate} here.", cid)
- end
- return true
- end
- local function sayBlessings( cid )
- local player = Player( cid )
- local amount = player:getBlessings()
- npcHandler:say( string.format( "There are five blessings available in five sacred places: the {spiritual} shielding, the spark of the {phoenix}, the {embrace} of Tibia, the fire of the {suns} and the wisdom of {solitude}. You have %d out of 5 blessings. I can also provide you with {all} blessings at once. Additionally, you can also receive the {twist of fate} here.", amount ), cid )
- --ynpc:setCurrentTopic( cid, CHOOSEBLESSINGS )
- return true
- end
- local function chooseBlessings( cid, msg )
- local player = Player( cid )
- local cost = getBlessingsCost(player:getLevel())
- if isInArray( { "spiritual", "spiritual shielding" }, msg ) then
- npcHandler:say( string.format( "For %d gold coins I will bless you with the Spiritual Shielding. Is that okay?", cost ), cid )
- chooseBless[ cid ] = 1
- elseif isInArray( { "phoenix", "spark of the phoenix" }, msg ) then
- npcHandler:say( string.format( "For %d gold coins I will bless you with the Spark of the Phoenix. Is that okay?", cost ), cid )
- chooseBless[ cid ] = 2
- elseif isInArray( { "embrace", "embrace of tibia" }, msg ) then
- npcHandler:say( string.format( "For %d gold coins I will bless you with the Embrace of Tibia. Is that okay?", cost ), cid )
- chooseBless[ cid ] = 3
- elseif isInArray( { "suns", "fire of the suns" }, msg ) then
- npcHandler:say( string.format( "For %d gold coins I will bless you with the Fire of the Suns. Is that okay?", cost ), cid )
- chooseBless[ cid ] = 4
- elseif isInArray( { "solitude", "wisdom of solitude" }, msg ) then
- npcHandler:say( string.format( "For %d gold coins I will bless you with the Wisdom of Solitude. Is that okay?", cost ), cid )
- chooseBless[ cid ] = 5
- elseif ( msg == "twist of fate" ) then
- npcHandler:say({
- "This is a special blessing I can bestow upon you once you have obtained at least one of the other blessings and which functions a bit differently. ...",
- "It only works when you're killed by other adventurers, which means that at least half of the damage leading to your death was caused by others, not by monsters or the environment. ...",
- "The {twist of fate} will not reduce the death penalty like the other blessings, but instead prevent you from losing your other blessings as well as the amulet of loss, should you wear one. It costs the same as the other blessings. ...",
- "Would you like to receive that protection for a sacrifice of " .. getPvpBlessingCost(player:getLevel()) .. " gold, child?"
- }, cid)
- chooseBless[ cid ] = 6
- elseif ( msg == "all" ) then
- if player:getBlessings() == 5 then
- npcHandler:say("You already possess all blessings.", cid )
- ynpc:reset( cid )
- return false
- end
- npcHandler:say( string.format( "For %d gold coins, I will bless you with all the blessings you don't already have. Is that okay?", player:getBlessingPrices() ), cid )
- chooseBless[ cid ] = 7
- elseif ( msg == "no" ) then
- npcHandler:say("Fine. You are free to decline my offer.", cid)
- chooseBless[ cid ] = 0
- ynpc:reset( cid )
- return false
- else
- ynpc:doTopic( cid, DONTUNDERSTAND )
- return false
- end
- return true
- end
- local function buyBlessings( cid )
- local player = Player( cid )
- if chooseBless[ cid ] == 6 then
- if player:getBlessings() > 0 or player:getItemCount(2173) > 0 then
- if not player:hasBlessing(6) then
- if player:removeMoney(getPvpBlessingCost(player:getLevel())) then
- player:addBlessing(6)
- npcHandler:say("So receive the protection of the twist of fate, pilgrim.", cid)
- else
- npcHandler:say("Oh. You do not have enough money.", cid)
- end
- else
- npcHandler:say("You already possess this blessing.", cid)
- end
- else
- npcHandler:say("You don't have any of the other blessings nor an amulet of loss, so it wouldn't make sense to bestow this protection on you now. Remember that it can only protect you from the loss of those!", cid)
- end
- elseif ( chooseBless[ cid ] >= 1 ) and ( chooseBless[ cid ] <= 5 ) then
- local cost = getBlessingsCost(player:getLevel())
- if player:hasBlessing( chooseBless[ cid ] ) then
- npcHandler:say("Gods have already blessed you with this blessing!", cid)
- else
- if player:removeMoney( cost ) then
- npcHandler:say( blessMsgs[ chooseBless[ cid ] ], cid )
- player:addBlessing( chooseBless[ cid ] )
- player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
- else
- npcHandler:say("Oh. You do not have enough money.", cid)
- end
- end
- elseif chooseBless[ cid ] == 7 then
- if player:getBlessings() == 5 then
- npcHandler:say("You already possess all blessings.", cid)
- else
- local allCost = player:getBlessingPrices()
- if player:removeMoney( allCost ) then
- player:addAllBlessings()
- player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
- npcHandler:say( "Now you have been blessed by all five Gods!", cid )
- else
- npcHandler:say("Oh. You do not have enough money.", cid)
- end
- end
- end
- return true
- end
- --Opções iniciais( quando o player começa a conversa com o npc ) de topicos
- ynpc:setDefaultTopics( { HEAL, BLESSINGS } )
- ynpc:addTopic( {
- id = DONTUNDERSTAND,
- words = {},
- answer = "I don't understand you.",
- next = {},
- default = { reset = true }
- } )
- ynpc:addTopic( {
- id = HEAL,
- words = { "heal", "heal" },
- answer = healPlayer,
- next = {},
- default = {message = "I don't understand you.", reset = true}
- } )
- ynpc:addTopic( {
- id = BLESSINGS,
- words = { "blessing", "blessings" },
- answer = sayBlessings,
- next = { CHOOSEBLESSINGS },
- default = {topic = DONTUNDERSTAND}
- } )
- ynpc:addTopic( {
- id = CHOOSEBLESSINGS,
- words = { "any" },
- answer = chooseBlessings,
- next = { BLESSINGYES, BLESSINGNO },
- default = {message = "I don't understand you.", reset = true }
- } )
- ynpc:addTopic( {
- id = BLESSINGYES,
- words = { "yes" },
- answer = buyBlessings,
- next = {}
- } )
- ynpc:addTopic( {
- id = BLESSINGNO,
- words = { "no" },
- answer = "Fine. You are free to decline my offer.",
- next = {}
- } )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement