Advertisement
Guest User

blessevoguide.lua

a guest
Jan 28th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.70 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4. 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!'}
  5. local random_texts_chance = 40 -- percent
  6. local random_texts_interval = 5 -- seconds
  7. random_word_bless = 0
  8. local talkState = {}
  9. local function round(num, idp)
  10.     local mult = 10^(idp or 0)
  11.     if num >= 0 then return math.floor(num * mult + 0.5) / mult
  12.     else return math.ceil(num * mult - 0.5) / mult end
  13. end
  14.  
  15. function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid)            end
  16. function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid)         end
  17. function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)    end
  18. function onThink()
  19.     if(random_word_bless < os.time()) then
  20.         random_word_bless = (os.time() + random_texts_interval)
  21.         if(math.random(1, 100) < random_texts_chance) then
  22.             selfSay(random_texts[math.random(1, #random_texts)])
  23.         end
  24.     end
  25.     npcHandler:onThink()
  26. end
  27. function onPlayerEndTrade(cid)              npcHandler:onPlayerEndTrade(cid)            end
  28. function onPlayerCloseChannel(cid)          npcHandler:onPlayerCloseChannel(cid)        end
  29.         function greetCallback(cid)
  30.     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  31.     local msg = {
  32.         "Be greeted. If you need {something} just ask me.",
  33.         "Welcome to our humble temple, " .. getPlayerName(cid) .. ".",
  34.         "Welcome, " .. getPlayerName(cid) .. "! Welcome to the temple of {Enigma City}. If you need {healing}, I can help you.",
  35.         "Hello. How may I help you " .. getPlayerName(cid) .. "?",
  36.         "Come in, " .. getPlayerName(cid) .. "."
  37.     }
  38.     npcHandler:setMessage(MESSAGE_GREET, msg[math.random(1, #msg)])
  39.     talkState[talkUser] = 0
  40.     return true
  41. end
  42.  
  43. function creatureSayCallback(cid, type, msg)
  44.     if(not npcHandler:isFocused(cid)) then
  45.         return false
  46.     end
  47.  
  48.     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  49.     if(msgcontains(msg, 'map') or msgcontains(msg, 'mark')) then
  50.     selfSay('Do you want me to mark your map with important locations in our town?', cid)
  51.     talkState[talkUser] = 1
  52.     return true
  53.     end
  54.     if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
  55.         local marks = {
  56.         {mark = 5, pos = {x = 256, y = 256, z = 7}, desc = "Enigma City Temple"},
  57.         {mark = 10, pos = {x = 287, y = 254, z = 7}, desc = "Depot with bank"},
  58.         {mark = 13, pos = {x = 303, y = 247, z = 7}, desc = "Food store"},
  59.         {mark = 8, pos = {x = 278, y = 236, z = 7}, desc = "Smithery"},
  60.         {mark = 8, pos = {x = 271, y = 226, z = 7}, desc = "Distance weapons shop"},
  61.         {mark = 13, pos = {x = 268, y = 241, z = 7}, desc = "Jewelry, magic store and music instruments shop"},
  62.         {mark = 13, pos = {x = 303, y = 247, z = 7}, desc = "Food shop and magic store"},
  63.         {mark = 7, pos = {x = 252, y = 242, z = 7}, desc = "Tools and furniture"},
  64.         {mark = 13, pos = {x = 258, y = 237, z = 7}, desc = "Creature products and fashion"},
  65.         {mark = 9, pos = {x = 234, y = 215, z = 7}, desc = "Ship"},
  66.     }
  67.     local f_addMark = doPlayerAddMapMark
  68.     if(not f_addMark) then f_addMark = doAddMapMark end
  69.     for _, m  in pairs(marks) do
  70.         f_addMark(cid, m.pos, m.mark, m.desc ~= nil and m.desc or "")
  71.     end
  72.     selfSay('Here you are.', cid)
  73.     talkState[talkUser] = 0
  74.     return true
  75.     end
  76.    
  77.     if msgcontains(msg, "no") and talkState[talkUser] ~= 0 then
  78.     selfSay('May God guide your path then.', cid)
  79.     talkState[talkUser] = 0
  80.     return true
  81.     end
  82.    
  83.     if msgcontains(msg, "heal") then
  84.         if getCreatureCondition(cid, CONDITION_FIRE) then
  85.             selfSay("You are burning. I will help you.", cid)
  86.             doRemoveCondition(cid, CONDITION_FIRE)
  87.             doSendMagicEffect(getCreaturePosition(cid), 14)
  88.         elseif getCreatureCondition(cid, CONDITION_POISON) then
  89.             selfSay("You are poisoned. I will cure you.", cid)
  90.             doRemoveCondition(cid, CONDITION_POISON)
  91.             doSendMagicEffect(getCreaturePosition(cid), 13)
  92.         elseif getCreatureCondition(cid, CONDITION_ENERGY) then
  93.             selfSay("You are electrificed. I will help you.", cid)
  94.             doRemoveCondition(cid, CONDITION_ENERGY)
  95.             doSendMagicEffect(getCreaturePosition(cid), 12)
  96.         elseif getCreatureCondition(cid, CONDITION_PARALYZE) then
  97.             selfSay("You are paralyzed. I will cure you.", cid)
  98.             doRemoveCondition(cid, CONDITION_PARALYZE)
  99.             doSendMagicEffect(getCreaturePosition(cid), 14)
  100.         elseif getCreatureCondition(cid, CONDITION_DROWN) then
  101.             selfSay("You are drowing. I will help you.", cid)
  102.             doRemoveCondition(cid, CONDITION_DROWN)
  103.             doSendMagicEffect(getCreaturePosition(cid), 12)
  104.         elseif getCreatureCondition(cid, CONDITION_FREEZING) then
  105.             selfSay("You are cold! I will help you.", cid)
  106.             doRemoveCondition(cid, CONDITION_FREEZING)
  107.             doSendMagicEffect(getCreaturePosition(cid), 15)
  108.         elseif getCreatureCondition(cid, CONDITION_BLEEDING) then
  109.             selfSay("You are bleeding! I will help you.", cid)
  110.             doRemoveCondition(cid, CONDITION_BLEEDING)
  111.             doSendMagicEffect(getCreaturePosition(cid), 12)
  112.         elseif getCreatureCondition(cid, CONDITION_DAZZLED) then
  113.             selfSay("You are dazzled! Do not mess with holy creatures anymore!", cid)
  114.             doRemoveCondition(cid, CONDITION_DAZZLED)
  115.             doSendMagicEffect(getCreaturePosition(cid), 47)
  116.         elseif getCreatureCondition(cid, CONDITION_CURSED) then
  117.             selfSay("You are cursed! I will remove it.", cid)
  118.             doRemoveCondition(cid, CONDITION_CURSED)
  119.             doSendMagicEffect(getCreaturePosition(cid), 47)
  120.         elseif getCreatureHealth(cid) < 65 then
  121.             selfSay("You are looking really bad. Let me heal your wounds.", cid)
  122.             doCreatureAddHealth(cid, 65 - getCreatureHealth(cid))
  123.             doSendMagicEffect(getCreaturePosition(cid), 12)
  124.         elseif getCreatureHealth(cid) < 2000 then
  125.             selfSay("I did my best to fix your wounds.", cid)
  126.             doCreatureAddHealth(cid, 2000 - getCreatureHealth(cid))
  127.             doSendMagicEffect(getCreaturePosition(cid), 12)
  128.         else
  129.             local msgheal = {
  130.                 "You aren't looking really bad, " .. getCreatureName(cid) .. ". I only help in cases of real emergencies. Raise your health simply by eating {food}.",
  131.                 "Seriously? It's just a scratch",
  132.                 "Don't be a child. You don't need any help with your health.",
  133.                 "I'm not an expert. If you need help find a medic.",
  134.                 "Don't even waste my time, I have bigger problems than your scratched armor."
  135.             }
  136.             selfSay("" .. msgheal[math.random(1, #msgheal)] .. "", cid)
  137.         end
  138.     return true
  139.     end
  140.    
  141.     if(msgcontains(msg, 'white') and msgcontains(msg, 'magic')) then
  142.     selfSay('The white magic book, I saw it recently in library. If you are lucky enough you may still find it there.', cid)
  143.     talkState[talkUser] = 0
  144.     return true
  145.     end
  146.    
  147.     if(msgcontains(msg, 'expert') and msgcontains(msg, 'spell')) then
  148.     selfSay('They are available only for highest level wizards. They are mostly support and protection spells.', cid)
  149.     talkState[talkUser] = 0
  150.     return true
  151.     end
  152.    
  153.     if(msgcontains(msg, 'stationary') and msgcontains(msg, 'shield')) then
  154.     selfSay('Princess Estalice told me to learn this spell. It might be useful during assault of the hive one day.', cid)
  155.     talkState[talkUser] = 0
  156.     return true
  157.     end
  158.    
  159.     if(msgcontains(msg, 'age') and msgcontains(msg, 'spell')) then
  160.     selfSay('This one is available only for highest level wizards. I am not skilled enough to cast it.', cid)
  161.     talkState[talkUser] = 0
  162.     return true
  163.     end
  164.    
  165.     if(msgcontains(msg, 'soft') and msgcontains(msg, 'wings')) then
  166.     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)
  167.     talkState[talkUser] = 0
  168.     return true
  169.     end
  170.    
  171.     if(msgcontains(msg, 'lightbringer')) then
  172.     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)
  173.     talkState[talkUser] = 0
  174.     return true
  175.     end
  176.    
  177.     if(msgcontains(msg, 'cloudwalking')) then
  178.     local spelldur = round((getPlayerStorageValue(cid, 22444)-os.time())/3600)
  179.         if getPlayerStorageValue(cid,22444) < os.time() then
  180.             if getPlayerMoney(cid) > 4999 then
  181.             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)
  182.             talkState[talkUser] = 9
  183.             else
  184.             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)
  185.             talkState[talkUser] = 0
  186.             end
  187.         else
  188.             if getPlayerMoney(cid) > 4999 then
  189.             if spelldur == 1 then rt = '' else rt = 's' end
  190.             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
  191.             else
  192.             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)
  193.             talkState[talkUser] = 0
  194.             end    
  195.         end
  196.         return true
  197.     end
  198.    
  199.     if msgcontains(msg, "yes") and talkState[talkUser] == 9 then
  200.     if(doPlayerRemoveMoney(cid, 5000)) then
  201.     doCreatureSetStorage(cid, 22444, os.time() + (86400 * 3))
  202.     doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
  203.     selfSay('So be it! I hope you know what you are doing.', cid)
  204.     talkState[talkUser] = 0
  205.     else
  206.     selfSay('Come back when you decide to bring me donation for serious. I don\'t work with cheaters.', cid)
  207.     talkState[talkUser] = 0
  208.     end
  209.     return true
  210.     end
  211.    
  212.     if msgcontains(msg, "yes") and talkState[talkUser] > 90 and talkState[talkUser] < 96 then
  213.         if getPlayerBlessing(cid, talkState[talkUser] - 90) then
  214.             selfSay("You already have this blessing!", cid)
  215.         else
  216.             b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
  217.             if b_price < 2000 then b_price = 2000 end
  218.            
  219.             if doPlayerRemoveMoney(cid, b_price) then
  220.                 selfSay("You have been blessed by one of the five gods!", cid)
  221.                 doPlayerAddBlessing(cid, talkState[talkUser] - 90)
  222.                 doSendMagicEffect(getThingPos(cid), 12)
  223.             else
  224.                 selfSay("I'm sorry. We need money to keep this temple up.", cid)
  225.             end
  226.         end
  227.         talkState[talkUser] = 0
  228.         return true
  229.     end
  230.    
  231.     if msgcontains(msg, "yes") and talkState[talkUser] == 96 then
  232.         havebless = {}
  233.        
  234.         for i = 1, 5 do
  235.             if(getPlayerBlessing(cid, i)) then
  236.                 table.insert(havebless,i)
  237.             end
  238.         end
  239.        
  240.         if #havebless == 5 then
  241.             selfSay('You already have all available blessings.',cid)
  242.             talkState[talkUser] = 0
  243.             return true
  244.         end
  245.        
  246.         b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
  247.         if b_price < 2000 then b_price = 2000 end
  248.         b_price = ((5 - #havebless) * b_price)
  249.        
  250.         if doPlayerRemoveMoney(cid, b_price) then
  251.             selfSay("You have been blessed by the five gods!", cid)
  252.             for i = 1, 5 do doPlayerAddBlessing(cid, i) end
  253.             doSendMagicEffect(getThingPos(cid), 12)
  254.         else
  255.             selfSay("I'm sorry. We need money to keep this temple up.", cid)
  256.         end
  257.            
  258.         talkState[talkUser] = 0
  259.         return true
  260.     end
  261.    
  262.     if msgcontains(msg, "all") then
  263.         havebless = {}
  264.         b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
  265.         if b_price < 2000 then b_price = 2000 end
  266.        
  267.         for i = 1, 5 do
  268.             if(getPlayerBlessing(cid, i)) then
  269.                 table.insert(havebless,i)
  270.             end
  271.         end
  272.        
  273.         b_price = ((5 - #havebless) * b_price)
  274.        
  275.         if b_price == 0 then
  276.             selfSay('You already have all available blessings.',cid)
  277.             talkState[talkUser] = 0
  278.             return true
  279.         end
  280.        
  281.         selfSay('Do you want to receive all blessings for ' .. b_price .. ' gold?',cid)
  282.         talkState[talkUser] = 96
  283.         return true
  284.     end
  285.    
  286.     local blesskeywords = {'wisdom', 'spark', 'fire', 'spiritual', 'embrace'}
  287.     local blessnames = {'Wisdom of Solitude', 'Spark of The Phoenix', 'Fire of Two Suns', 'Spiritual Shielding', 'The Embrace'}
  288.     for i = 1, #blesskeywords do
  289.         if msgcontains(msg, blesskeywords[i]) then
  290.        
  291.             b_price = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
  292.             if b_price < 2000 then b_price = 2000 end
  293.            
  294.             selfSay('Do you want me to grant you ' .. blessnames[i] .. ' blessing for ' .. b_price .. ' gold?',cid)
  295.             talkState[talkUser] = 90 + i
  296.             return true
  297.         end
  298.     end
  299.    
  300.     return true
  301. end
  302.            
  303. npcHandler:setCallback(CALLBACK_GREET, greetCallback)
  304. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  305. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement