Advertisement
Guest User

potions.lua

a guest
Dec 24th, 2014
1,050
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.20 KB | None | 0 0
  1. -- =============================================================================================================================================================== --
  2. -- ===================  CREATED BY CODINABLACK@OTLAND.NET CREDITS TO OTLAND FOR HELPING ME TO LEARN EVERY KIND OF CODING USED IN THIS SCRIPT ====================== --
  3. -- =============================================================================================================================================================== --
  4. local config = {
  5. lvl = 1, -- the multiplier for how much level matters. Default 1.
  6. mlvl = 1, -- the mulitplier for how much mlvl matters. Default 1.
  7. forMin = 0.9, -- forumula multiplier for MIN/max range. Default 0.9 == 90%          --Change both to 1.0 for amount healed to have no min/max
  8. forMax = 1.1, -- forumula multiplier for min/MAX range. Default 0.9 == 110%         --Change both to 1.0 for amount healed to have no min/max
  9. removeOnUse = true, -- Does this remove 1 potion after it's use? true/false         -- Default true.
  10. useOnSummons = true, -- Can you use this on a players summon? true/false            -- Default true.
  11. useOnGuildSummon = true, -- Can you use this on guild mate's summon? true/false     -- Default true.
  12. useOnPartySummon = true, -- Can you use this on a party members summon? true/false      -- Default true.
  13. realPvpMode = true, -- True = Players can't use potions for hotkeys || False = Players are allowed to use potions for hotkeys.
  14. exhaust = Condition(CONDITION_EXHAUST_HEAL, CONDITIONID_HEAD),
  15. cooldown =  Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_HEAD)
  16. }
  17. local POTIONS = {
  18. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  19.   [8704] = {empty = 7636, spellid = 1, splash = 2, exhaust = 2000, health = true, mana = false, healthpercent = 8},                                                                         -- small health potion
  20.   [7618] = {empty = 7636, spellid = 1, splash = 2, exhaust = 2000, health = true, mana = false, healthpercent = 12},                                                                        -- health potion
  21.   [7588] = {empty = 7634, spellid = 2, splash = 2, exhaust = 2000, health = true, mana = false, healthpercent = 25, lvlReq = 50, vocations = {1, 3, 4, 7, 8, 12}},                          -- strong health potion
  22.   [7591] = {empty = 7635, spellid = 2, splash = 2, exhaust = 2000, health = true, mana = false, healthpercent = 40, lvlReq = 80, vocations = {4, 8, 12}},                                   -- great health potion
  23.   [8473] = {empty = 7635, spellid = 2, splash = 2, exhaust = 2000, health = true, mana = false, healthpercent = 60, lvlReq = 150, vocations = {4, 8, 12}},                                  -- ultimate health potion
  24. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  25.   [7620] = {empty = 7636, spellid = 3, splash = 7, exhaust = 2000, health = false, mana = true, manapercent = 12},                                                                          -- mana potion
  26.   [7589] = {empty = 7634, spellid = 3, splash = 7, exhaust = 2000, health = false, mana = true, manapercent = 25, lvlReq = 50, vocations = {1, 2, 3, 5, 6, 7, 9, 10, 11}},                  -- strong mana potion
  27.   [7590] = {empty = 7635, spellid = 3, splash = 7, exhaust = 2000, health = false, mana = true, manapercent = 40, lvlReq = 80, vocations = {1, 2, 5, 6, 9, 10}},                            -- great mana potion
  28. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  29.   [8472] = {empty = 7635, spellid = 2, splash = 3, exhaust = 2000, health = true,  mana = true, healthpercent = 60, manapercent = 60, lvlReq = 100, vocations = {3, 7, 11}}                     -- great spirit potion
  30. }
  31. function onUse(caster, item, fromPosition, itemEx, toPosition, isHotkey)
  32.     if isHotkey and config.realPvpMode == true then
  33.         caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  34.         return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Hotkey use is disabled for potions!")
  35.     end
  36.     if toPosition.z == 0 or nil then
  37.         caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  38.         return caster:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
  39.     end
  40.     if toPosition.x == 65535 or nil then
  41.         caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  42.         return caster:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
  43.     end
  44. local CGID = 0
  45. local CPID = 0
  46. local mlevel = caster:getMagicLevel()
  47. local level = caster:getLevel()
  48. local potion = POTIONS[item.itemid]
  49. local health = potion.health
  50. local mana = potion.mana
  51. local hpPercent = potion.healthpercent
  52. local mpPercent = potion.manapercent
  53. local exhaust = config.exhaust
  54. local cooldown = config.cooldown
  55. local targetItem = Item(itemEx.uid)
  56.     if targetItem then
  57.         if (not targetItem:hasProperty()) then
  58.             Item(doCreateItem(2016, potion.splash, toPosition)):decay()
  59.                 if config.removeOnUse and not caster:getGroup():getAccess() then
  60.                     Item(item.uid):remove(1)
  61.                 end
  62.             return true
  63.         end
  64.         caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  65.         return caster:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
  66.     end
  67. local target = Creature(itemEx.uid)
  68. local healthmax = target:getMaxHealth()
  69. local manamax = target:getMaxMana()
  70.  
  71.     if(not potion) then
  72.         return false
  73.     end
  74.     if caster:getCondition(CONDITION_EXHAUST_HEAL, CONDITIONID_HEAD, potion.spellid) then
  75.         caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  76.         return caster:sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED)
  77.     end
  78.     if (potion.vocations) and  (not caster:getGroup():getAccess()) then
  79.         if (not isInArray(potion.vocations, caster:getVocation():getId())) then
  80.             caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  81.             return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Your vocation may not use this fluid")
  82.         end
  83.     end
  84.     if((potion.lvlReq and caster:getLevel() < potion.lvlReq) and not caster:getGroup():getAccess()) then
  85.         caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  86.         return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Only players of " ..potion.level.. " or above may use this fluid.")
  87.     end
  88.         if target:isPlayer() then
  89.             if health == true then
  90.                 target:addHealth( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax)))
  91.             end
  92.             if mana == true then
  93.                 target:addMana( math.random((((manamax/100)*mpPercent ) + ((level/18)*config.lvl ) + ((mlevel/12)*config.mlvl ))*config.forMin, ((((manamax/100)*mpPercent ) + ((level/18)*config.lvl )+ ((mlevel/12))*config.mlvl )*config.forMax)))
  94.             end
  95.         end
  96.     if target:isMonster() then
  97.     local monsterMaster = target:getMaster()
  98.         if monsterMaster then
  99.             if config.useOnSummons == true then
  100.                 if config.useOnGuildSummon == true then
  101.                     if monsterMaster:getGuild() then
  102.                         if caster:getGuild() then
  103.                             CGID = caster:getGuild():getId()
  104.                         end
  105.                     end
  106.                     if CGID ~= 0 then
  107.                         if monsterMaster:getGuild():getId() == CGID then
  108.                             if mana == false then
  109.                                 if health == true then
  110.                                     target:addHealth( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax)))
  111.                                 end
  112.                             else
  113.                                 caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  114.                                 return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"Summons don't use mana!")
  115.                             end
  116.                         end
  117.                     end
  118.                 else
  119.                     caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  120.                     return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You may not use this on that summon!")
  121.                 end
  122.                 if config.useOnPartySummon == true then
  123.                     if monsterMaster:getParty() then
  124.                         if caster:getParty() then
  125.                             CPID = caster:getParty():getId()
  126.                         end
  127.                     end
  128.                     if CPID ~= 0 then
  129.                         if monsterMaster:getParty():getId() == CPID then
  130.                             if mana == false then
  131.                                 if health == true then
  132.                                     target:addHealth( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax)))
  133.                                 end
  134.                             else
  135.                                 caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  136.                                 return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"Summons don't use mana!")
  137.                             end
  138.                         end
  139.                     end
  140.                 else
  141.                     caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  142.                     return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You may not use this on that summon!")
  143.                 end
  144.                 if monsterMaster:getId() == caster:getId() then
  145.                     if mana == false then
  146.                         if health == true then
  147.                             target:addHealth( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax)))
  148.                         end
  149.                     else
  150.                         caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  151.                         return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"Summons don't use mana!")
  152.                     end
  153.                 end
  154.             else
  155.                 caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  156.                 return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on summons!")
  157.             end
  158.             if CPID == 0 and CGID == 0 then
  159.                 caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  160.                 return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on that creature!")
  161.             end
  162.         end
  163.     end    
  164.     if target:isNpc() then
  165.         caster:getPosition():sendMagicEffect(CONST_ME_POFF)
  166.         return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on that creature!")
  167.     end
  168.     if config.removeOnUse and not caster:getGroup():getAccess() then
  169.         Item(item.uid):remove(1)
  170.     end
  171.     exhaust:setParameter(CONDITION_PARAM_TICKS, potion.exhaust)
  172.     exhaust:setParameter(CONDITION_PARAM_SUBID, potion.spellid)
  173.     cooldown:setParameter(CONDITION_PARAM_TICKS, potion.exhaust)
  174.     cooldown:setParameter(CONDITION_PARAM_SUBID, potion.spellid)
  175.     caster:addCondition(cooldown)
  176.     caster:addCondition(exhaust)
  177.     target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
  178.     target:say("Aaaah...", TALKTYPE_ORANGE_1)
  179.   return true
  180. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement