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)
- local random_texts = {'Welcome to our humble temple.', 'If you are hurt ask me, I\'ll heal you.', 'Feeling lost? Ask me for help.', 'Praise our God. He has power to revive adventurers whose adventure is not over yet!'}
- local random_texts_chance = 40 -- percent
- local random_texts_interval = 5 -- seconds
- random_word_bless = 0
- local talkState = {}
- local function round(num, idp)
- local mult = 10^(idp or 0)
- if num >= 0 then return math.floor(num * mult + 0.5) / mult
- else return math.ceil(num * mult - 0.5) / mult end
- end
- 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()
- if(random_word_bless < os.time()) then
- random_word_bless = (os.time() + random_texts_interval)
- if(math.random(1, 100) < random_texts_chance) then
- selfSay(random_texts[math.random(1, #random_texts)])
- end
- end
- npcHandler:onThink()
- end
- function onPlayerEndTrade(cid) npcHandler:onPlayerEndTrade(cid) end
- function onPlayerCloseChannel(cid) npcHandler:onPlayerCloseChannel(cid) end
- function greetCallback(cid)
- local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
- local msg = {
- "Be greeted. If you need {something} just ask me.",
- "Welcome to our humble temple, " .. getPlayerName(cid) .. ".",
- "Welcome, " .. getPlayerName(cid) .. "! Welcome to the temple of {Enigma City}. If you need {healing}, I can help you.",
- "Hello. How may I help you " .. getPlayerName(cid) .. "?",
- "Come in, " .. getPlayerName(cid) .. "."
- }
- npcHandler:setMessage(MESSAGE_GREET, msg[math.random(1, #msg)])
- talkState[talkUser] = 0
- return true
- end
- function creatureSayCallback(cid, type, msg)
- if(not npcHandler:isFocused(cid)) then
- return false
- end
- local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
- if(msgcontains(msg, 'map') or msgcontains(msg, 'mark')) then
- selfSay('Do you want me to mark your map with important locations in our town?', cid)
- talkState[talkUser] = 1
- return true
- end
- if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
- local marks = {
- {mark = 5, pos = {x = 256, y = 256, z = 7}, desc = "Enigma City Temple"},
- {mark = 10, pos = {x = 287, y = 254, z = 7}, desc = "Depot with bank"},
- {mark = 13, pos = {x = 303, y = 247, z = 7}, desc = "Food store"},
- {mark = 8, pos = {x = 278, y = 236, z = 7}, desc = "Smithery"},
- {mark = 8, pos = {x = 271, y = 226, z = 7}, desc = "Distance weapons shop"},
- {mark = 13, pos = {x = 268, y = 241, z = 7}, desc = "Jewelry, magic store and music instruments shop"},
- {mark = 13, pos = {x = 303, y = 247, z = 7}, desc = "Food shop and magic store"},
- {mark = 7, pos = {x = 252, y = 242, z = 7}, desc = "Tools and furniture"},
- {mark = 13, pos = {x = 258, y = 237, z = 7}, desc = "Creature products and fashion"},
- {mark = 9, pos = {x = 234, y = 215, z = 7}, desc = "Ship"},
- }
- local f_addMark = doPlayerAddMapMark
- if(not f_addMark) then f_addMark = doAddMapMark end
- for _, m in pairs(marks) do
- f_addMark(cid, m.pos, m.mark, m.desc ~= nil and m.desc or "")
- end
- selfSay('Here you are.', cid)
- talkState[talkUser] = 0
- return true
- end
- if msgcontains(msg, "no") and talkState[talkUser] ~= 0 then
- selfSay('May God guide your path then.', cid)
- talkState[talkUser] = 0
- return true
- end
- if msgcontains(msg, "heal") then
- if getCreatureCondition(cid, CONDITION_FIRE) then
- selfSay("You are burning. I will help you.", cid)
- doRemoveCondition(cid, CONDITION_FIRE)
- doSendMagicEffect(getCreaturePosition(cid), 14)
- elseif getCreatureCondition(cid, CONDITION_POISON) then
- selfSay("You are poisoned. I will cure you.", cid)
- doRemoveCondition(cid, CONDITION_POISON)
- doSendMagicEffect(getCreaturePosition(cid), 13)
- elseif getCreatureCondition(cid, CONDITION_ENERGY) then
- selfSay("You are electrificed. I will help you.", cid)
- doRemoveCondition(cid, CONDITION_ENERGY)
- doSendMagicEffect(getCreaturePosition(cid), 12)
- elseif getCreatureCondition(cid, CONDITION_PARALYZE) then
- selfSay("You are paralyzed. I will cure you.", cid)
- doRemoveCondition(cid, CONDITION_PARALYZE)
- doSendMagicEffect(getCreaturePosition(cid), 14)
- elseif getCreatureCondition(cid, CONDITION_DROWN) then
- selfSay("You are drowing. I will help you.", cid)
- doRemoveCondition(cid, CONDITION_DROWN)
- doSendMagicEffect(getCreaturePosition(cid), 12)
- elseif getCreatureCondition(cid, CONDITION_FREEZING) then
- selfSay("You are cold! I will help you.", cid)
- doRemoveCondition(cid, CONDITION_FREEZING)
- doSendMagicEffect(getCreaturePosition(cid), 15)
- elseif getCreatureCondition(cid, CONDITION_BLEEDING) then
- selfSay("You are bleeding! I will help you.", cid)
- doRemoveCondition(cid, CONDITION_BLEEDING)
- doSendMagicEffect(getCreaturePosition(cid), 12)
- elseif getCreatureCondition(cid, CONDITION_DAZZLED) then
- selfSay("You are dazzled! Do not mess with holy creatures anymore!", cid)
- doRemoveCondition(cid, CONDITION_DAZZLED)
- doSendMagicEffect(getCreaturePosition(cid), 47)
- elseif getCreatureCondition(cid, CONDITION_CURSED) then
- selfSay("You are cursed! I will remove it.", cid)
- doRemoveCondition(cid, CONDITION_CURSED)
- doSendMagicEffect(getCreaturePosition(cid), 47)
- elseif getCreatureHealth(cid) < 65 then
- selfSay("You are looking really bad. Let me heal your wounds.", cid)
- doCreatureAddHealth(cid, 65 - getCreatureHealth(cid))
- doSendMagicEffect(getCreaturePosition(cid), 12)
- elseif getCreatureHealth(cid) < 2000 then
- selfSay("I did my best to fix your wounds.", cid)
- doCreatureAddHealth(cid, 2000 - getCreatureHealth(cid))
- doSendMagicEffect(getCreaturePosition(cid), 12)
- else
- local msgheal = {
- "You aren't looking really bad, " .. getCreatureName(cid) .. ". I only help in cases of real emergencies. Raise your health simply by eating {food}.",
- "Seriously? It's just a scratch",
- "Don't be a child. You don't need any help with your health.",
- "I'm not an expert. If you need help find a medic.",
- "Don't even waste my time, I have bigger problems than your scratched armor."
- }
- selfSay("" .. msgheal[math.random(1, #msgheal)] .. "", cid)
- end
- return true
- end
- if(msgcontains(msg, 'white') and msgcontains(msg, 'magic')) then
- selfSay('The white magic book, I saw it recently in library. If you are lucky enough you may still find it there.', cid)
- talkState[talkUser] = 0
- return true
- end
- if(msgcontains(msg, 'expert') and msgcontains(msg, 'spell')) then
- selfSay('They are available only for highest level wizards. They are mostly support and protection spells.', cid)
- talkState[talkUser] = 0
- return true
- end
- if(msgcontains(msg, 'stationary') and msgcontains(msg, 'shield')) then
- selfSay('Princess Estalice told me to learn this spell. It might be useful during assault of the hive one day.', cid)
- talkState[talkUser] = 0
- return true
- end
- if(msgcontains(msg, 'age') and msgcontains(msg, 'spell')) then
- selfSay('This one is available only for highest level wizards. I am not skilled enough to cast it.', cid)
- talkState[talkUser] = 0
- return true
- end
- if(msgcontains(msg, 'soft') and msgcontains(msg, 'wings')) then
- selfSay('This one allows to fly and walk on clouds by summoning mentioned wings, but they are very fragile and the spell is very complicated itself. I casted this spell once, but its user didn\'t appreciated my effort.', cid)
- talkState[talkUser] = 0
- return true
- end
- if(msgcontains(msg, 'lightbringer')) then
- selfSay('They are very rare creatures. Seeing one is like spotting a unicorn. They live in highest layers of clouds, a very little is known about them.', cid)
- talkState[talkUser] = 0
- return true
- end
- if(msgcontains(msg, 'cloudwalking')) then
- local spelldur = round((getPlayerStorageValue(cid, 22444)-os.time())/3600)
- if getPlayerStorageValue(cid,22444) < os.time() then
- if getPlayerMoney(cid) > 4999 then
- selfSay('The cloudwalking spell is simpler alternative of {soft wings} spell, but it\'s more dangerous also. You have to watch youself - if you fall from a cloud, nothing can save you. This spell lasts for three days. Do you want me to cast it on you for a small donation of 5000 gold?', cid)
- talkState[talkUser] = 9
- else
- selfSay('The cloudwalking spell is simpler alternative of {soft wings} spell, but it\'s more dangerous also. You have to watch youself - if you fall from a cloud, nothing can save you. This spell lasts for three days.', cid)
- talkState[talkUser] = 0
- end
- else
- if getPlayerMoney(cid) > 4999 then
- if spelldur == 1 then rt = '' else rt = 's' end
- selfSay('It seems you still have ' .. spelldur .. ' hour' .. rt .. ' of spell left. Do you want to extend your spell for 5000 gold? It will work for three days from now.', cid) talkState[talkUser] = 9
- else
- selfSay('The cloudwalking spell is simpler alternative of {soft wings} spell, but it\'s more dangerous also. You have to watch youself - if you fall from a cloud, nothing can save you. This spell lasts for three days. You have ' .. spelldur .. ' hour' .. rt .. ' of spell left.', cid)
- talkState[talkUser] = 0
- end
- end
- return true
- end
- if msgcontains(msg, "yes") and talkState[talkUser] == 9 then
- if(doPlayerRemoveMoney(cid, 5000)) then
- doCreatureSetStorage(cid, 22444, os.time() + (86400 * 3))
- doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
- selfSay('So be it! I hope you know what you are doing.', cid)
- talkState[talkUser] = 0
- else
- selfSay('Come back when you decide to bring me donation for serious. I don\'t work with cheaters.', cid)
- talkState[talkUser] = 0
- end
- return true
- end
- if msgcontains(msg, "yes") and talkState[talkUser] > 90 and talkState[talkUser] < 96 then
- if getPlayerBlessing(cid, talkState[talkUser] - 90) then
- selfSay("You already have this blessing!", cid)
- else
- b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
- if b_price < 2000 then b_price = 2000 end
- if doPlayerRemoveMoney(cid, b_price) then
- selfSay("You have been blessed by one of the five gods!", cid)
- doPlayerAddBlessing(cid, talkState[talkUser] - 90)
- doSendMagicEffect(getThingPos(cid), 12)
- else
- selfSay("I'm sorry. We need money to keep this temple up.", cid)
- end
- end
- talkState[talkUser] = 0
- return true
- end
- if msgcontains(msg, "yes") and talkState[talkUser] == 96 then
- havebless = {}
- for i = 1, 5 do
- if(getPlayerBlessing(cid, i)) then
- table.insert(havebless,i)
- end
- end
- if #havebless == 5 then
- selfSay('You already have all available blessings.',cid)
- talkState[talkUser] = 0
- return true
- end
- b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
- if b_price < 2000 then b_price = 2000 end
- b_price = ((5 - #havebless) * b_price)
- if doPlayerRemoveMoney(cid, b_price) then
- selfSay("You have been blessed by the five gods!", cid)
- for i = 1, 5 do doPlayerAddBlessing(cid, i) end
- doSendMagicEffect(getThingPos(cid), 12)
- else
- selfSay("I'm sorry. We need money to keep this temple up.", cid)
- end
- talkState[talkUser] = 0
- return true
- end
- if msgcontains(msg, "all") then
- havebless = {}
- b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
- if b_price < 2000 then b_price = 2000 end
- for i = 1, 5 do
- if(getPlayerBlessing(cid, i)) then
- table.insert(havebless,i)
- end
- end
- b_price = ((5 - #havebless) * b_price)
- if b_price == 0 then
- selfSay('You already have all available blessings.',cid)
- talkState[talkUser] = 0
- return true
- end
- selfSay('Do you want to receive all blessings for ' .. b_price .. ' gold?',cid)
- talkState[talkUser] = 96
- return true
- end
- local blesskeywords = {'wisdom', 'spark', 'fire', 'spiritual', 'embrace'}
- local blessnames = {'Wisdom of Solitude', 'Spark of The Phoenix', 'Fire of Two Suns', 'Spiritual Shielding', 'The Embrace'}
- for i = 1, #blesskeywords do
- if msgcontains(msg, blesskeywords[i]) then
- b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
- if b_price < 2000 then b_price = 2000 end
- selfSay('Do you want me to grant you ' .. blessnames[i] .. ' blessing for ' .. b_price .. ' gold?',cid)
- talkState[talkUser] = 90 + i
- return true
- end
- end
- return true
- end
- npcHandler:setCallback(CALLBACK_GREET, greetCallback)
- npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
- npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement