Advertisement
Guest User

buff.lua

a guest
Mar 10th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.92 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4.  
  5. function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid)            end
  6. function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid)         end
  7. function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)    end
  8. function onThink()                          npcHandler:onThink()                        end
  9.  
  10. local talkState = {}
  11.  
  12. -- config
  13.     local stats = {'melee', 'distance', 'shield', 'ml', 'invisible', 'regeneration', 'manashield', 'haste'}
  14.     local config = {
  15.         max_incr = 2,
  16.         skillsupgrade = {
  17.             ['melee'] = {price = 5000, seconds = 600, amount = 10, subid = 62, renew = 24 * 60 * 60, storage = 77700, buymsg = {'Your Melee Skill has increased for ', ' minutes!'}, failmsg = 'You must be a knight to receive this increment.', canbuy = function(cid) return isKnight(cid) end},
  18.             ['distance'] = {price = 5000, seconds = 600, amount = 10, subid = 63, renew = 24 * 60 * 60, storage = 77701, buymsg = {'Your Distance Skill has increased for ', ' minutes!'}, failmsg = 'You must be a paladin to receive this increment.', canbuy = function(cid) return isPaladin(cid) end},
  19.             ['shield'] = {price = 5000, seconds = 600, amount = 10, subid = 64, renew = 24 * 60 * 60, storage = 77702, buymsg = {'Your Shielding Skill has increased for ', ' minutes!'}, failmsg = 'You must be a paladin or a knight to receive this increment.', canbuy = function(cid) return isKnight(cid) or isPaladin(cid) end},
  20.             ['ml'] = {price = 5000, seconds = 600, amount = 10, subid = 65, renew = 24 * 60 * 60, storage = 77703, buymsg = {'Your Magic Level has increased for ', ' minutes!'}, failmsg = 'You must be a druid or a sorcerer to receive this increment.', canbuy = function(cid) return isDruid(cid) or isSorcerer(cid) end},
  21.             ['invisible'] = {price = 5000, seconds = 600, subid = 66, renew = 24 * 60 * 60, storage = 77704, buymsg = {'You received Invisibility for ', ' minutes!'}, failmsg = 'You must be a druid or a sorcerer to receive this increment.', canbuy = function(cid) return isDruid(cid) or isSorcerer(cid) end},
  22.             ['haste'] = {price = 5000, seconds = 600, formula = {1.0, -86, 1.0, -86}, renew = 24 * 60 * 60, storage = 77705, buymsg = {'Your speed has increased for ', ' minutes!'}, failmsg = 'Unable to add stat.', canbuy = function(cid) return true end},
  23.             ['regeneration'] = {price = 5000, seconds = 600, gain = 20, ticks = 2000, renew = 24 * 60 * 60, storage = 77706, buymsg = {'Your regeneration has increased for ', ' minutes!'}, failmsg = 'Unable to add stat.', canbuy = function(cid) return true end},
  24.             ['manashield'] = {price = 5000, seconds = 600, renew = 24 * 60 * 60, storage = 77707, buymsg = 'You received a Magic Shield for ', ' minutes!', failmsg = 'Knights cannot receive this increment.', canbuy = function(cid) return not isKnight(cid) end},
  25.         },
  26.     }
  27. -- end of config
  28.  
  29. local su = config.skillsupgrade
  30. for i = 1, #stats do
  31.     local bm = su[stats[i]].buymsg
  32.     bm = {bm[1] .. math.floor(su[stats[i]].seconds/10), bm[2]}
  33. end
  34.  
  35. local active_incr = {}
  36. local ml = createConditionObject(CONDITION_ATTRIBUTES)
  37. setConditionParam(ml, CONDITION_PARAM_SUBID, su['ml'].subid)
  38. setConditionParam(ml, CONDITION_PARAM_BUFF_SPELL, 1)
  39. setConditionParam(ml, CONDITION_PARAM_TICKS, su['ml'].seconds * 1000)
  40. setConditionParam(ml, CONDITION_PARAM_STAT_MAGICPOINTS, su['ml'].amount)
  41.  
  42. local me = createConditionObject(CONDITION_ATTRIBUTES)
  43. setConditionParam(me, CONDITION_PARAM_SUBID, su['melee'].subid)
  44. setConditionParam(me, CONDITION_PARAM_BUFF_SPELL, 1)
  45. setConditionParam(me, CONDITION_PARAM_TICKS, su['melee'].seconds * 1000)
  46. setConditionParam(me, CONDITION_PARAM_SKILL_MELEE, su['melee'].amount)
  47.  
  48. local sh = createConditionObject(CONDITION_ATTRIBUTES)
  49. setConditionParam(sh, CONDITION_PARAM_SUBID, su['shield'].subid)
  50. setConditionParam(sh, CONDITION_PARAM_BUFF_SPELL, 1)
  51. setConditionParam(sh, CONDITION_PARAM_TICKS, su['shield'].seconds * 1000)
  52. setConditionParam(sh, CONDITION_PARAM_SKILL_SHIELD, su['shield'].amount)
  53.  
  54. local ds = createConditionObject(CONDITION_ATTRIBUTES)
  55. setConditionParam(ds, CONDITION_PARAM_SUBID, su['distance'].subid)
  56. setConditionParam(ds, CONDITION_PARAM_BUFF_SPELL, 1)
  57. setConditionParam(ds, CONDITION_PARAM_TICKS, su['distance'].seconds * 1000)
  58. setConditionParam(ds, CONDITION_PARAM_SKILL_DISTANCE, su['distance'].amount)
  59.  
  60. local iv = createConditionObject(CONDITION_INVISIBLE)
  61. setConditionParam(iv, CONDITION_PARAM_TICKS, su['invisible'].seconds * 1000)
  62.  
  63. local ms = createConditionObject(CONDITION_MANASHIELD)
  64. setConditionParam(ms, CONDITION_PARAM_TICKS, su['manashield'].seconds * 1000)
  65.  
  66. local hp = createConditionObject(CONDITION_REGENERATION)
  67. setConditionParam(hp, CONDITION_PARAM_SUBID, su['regeneration'].subid)
  68. setConditionParam(hp, CONDITION_PARAM_BUFF_SPELL, 1)
  69. setConditionParam(hp, CONDITION_PARAM_TICKS, su['regeneration'].seconds * 1000)
  70. setConditionParam(hp, CONDITION_PARAM_HEALTHGAIN, su['regeneration'].gain)
  71. setConditionParam(hp, CONDITION_PARAM_HEALTHTICKS, su['regeneration'].ticks)
  72.  
  73. local hs = createConditionObject(CONDITION_HASTE)
  74. setConditionParam(hs, CONDITION_PARAM_TICKS, su['haste'].seconds * 1000)
  75. setConditionFormula(hs, su['haste'].formula[1], su['haste'].formula[2], su['haste'].formula[3], su['haste'].formula[4])
  76.  
  77. local stat_t = {me, ds, sh, ml, iv, hp, ms, hs}
  78. for i = 1, #stats do
  79.     su[stats[i]].condition = stat_t[i]
  80. end
  81.  
  82. function creatureSayCallback(cid, type, msg)
  83.     cid = Player(cid):getId() or cid -- compat for all tfs
  84.     if(not npcHandler:isFocused(cid)) then return false end
  85.     if not talkState[cid] then talkState[cid] = 0 end
  86.    
  87.     if talkState[cid] ~= 0 then
  88.         if msgcontains(msg, "yes") then
  89.             if stats[talkState[cid]] then
  90.                 if su[stats[talkState[cid]]] then
  91.                     if su[stats[talkState[cid]]].canbuy(cid) then
  92.                         if getPlayerMoney(cid) >= su[stats[talkState[cid]]].price then
  93.                             if not active_incr[cid] then active_incr[cid] = {} end
  94.                            
  95.                             if active_incr[cid][stats[talkState[cid]]] then
  96.                                 if active_incr[cid][stats[talkState[cid]]] < os.time() then
  97.                                     local pstr = getPlayerStorageValue(cid, su[stats[talkState[cid]]].storage)
  98.                                     if pstr < os.time() then
  99.                                         local a_incr = 0
  100.                                         for i = 1, #stats do
  101.                                             if active_incr[cid][stats[i]] then
  102.                                                 if active_incr[cid][stats[i]] > os.time() then
  103.                                                     a_incr = a_incr + 1
  104.                                                 end
  105.                                             end
  106.                                         end
  107.                                        
  108.                                         if a_incr < max then
  109.                                             if doPlayerRemoveMoney(cid, su[stats[talkState[cid]]].price) then
  110.                                                 doAddCondition(cid, su[stats[talkState[cid]]].condition)
  111.                                                 setPlayerStorageValue(cid, su[stats[talkState[cid]]].storage, os.time() + su[stats[talkState[cid]]].renew)    
  112.                                                 npcHandler:say(su[stats[talkState[cid]]].buymsg[1] .. su[stats[talkState[cid]]].buymsg[2], cid)
  113.                                                 talkState[cid] = 0
  114.                                                 return true
  115.                                             end
  116.                                         else
  117.                                             npcHandler:say("You may use only " .. (config.max_incr == 1 and "one" or config.max_incr) .. " increments at once.", cid)
  118.                                         end
  119.                                     else
  120.                                         npcHandler:say('You have to wait ' .. math.ceil(((pstr - os.time()) / 60) / 60) .. ' hours before you can get it again.', cid)
  121.                                     end
  122.                                 else
  123.                                     npcHandler:say('You already use this one.', cid)
  124.                                 end
  125.                             end
  126.                         else
  127.                             npcHandler:say('You don\'t have enough money.', cid)
  128.                         end
  129.                     else
  130.                         npcHandler:say(su[stats[talkState[cid]]].failmsg, cid)
  131.                     end
  132.                 end
  133.             end
  134.         else
  135.             npcHandler:say("Come back when you change your mind.", cid)
  136.         end
  137.         talkState[cid] = 0
  138.         return true
  139.     end
  140.  
  141.    
  142.     if msgcontains(msg, "help") or msgcontains(msg, "skill") or msgcontains(msg, "stat") or msgcontains(msg, "buff") or msgcontains(msg, "increment") then
  143.         local skils = ""
  144.         local nst = {}
  145.         for i = 1, #stats do
  146.             if su[stats[i]].canbuy(cid) then
  147.                 table.insert(nst, stats[i])
  148.             end
  149.         end
  150.  
  151.         if #nst == 0 then
  152.             npcHandler:say("I don't have anything for you.", cid)
  153.             return true
  154.         end
  155.  
  156.         if #nst > 1 then
  157.             local last = nst[#nst]
  158.             table.remove(nst, #nst)
  159.             skills = table.concat(nst, "}, {")
  160.             skills = "{" .. skills .. "}" .. " and " .. "{" .. last .. "}"
  161.         else
  162.             skills = "{" .. nst[1] .. "}"
  163.         end
  164.  
  165.         npcHandler:say("I can increase your " .. skills .. (#stats > 1 and (", you may use " .. (config.max_incr == 1 and "one" or config.max_incr) .. " of them at once.") or "."), cid)
  166.         return true
  167.     end
  168.    
  169.     for i = 1, #stats do
  170.         if msgcontains(msg, stats[i]) and su[stats[i]] then
  171.             if su[stats[i]].canbuy(cid) then
  172.                 npcHandler:say("Do you want to increase your " .. stats[i] .. " for " .. math.floor(su[stats[i]].seconds/10) .. " minutes for " .. su[stats[i]].price .. " gold?", cid)
  173.                 talkState[cid] = i
  174.                 return true
  175.             else
  176.                 npcHandler:say(su[stats[i]].failmsg, cid)
  177.                 return true
  178.             end
  179.         end
  180.     end
  181. end
  182.  
  183. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  184. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement