Advertisement
Guest User

Potion.lua Script

a guest
Jan 24th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.96 KB | None | 0 0
  1. local config = {
  2.     removeOnUse = "no",
  3.     usableOnTarget = "yes", -- can be used on target? (fe. healing friend)
  4.     splashable = "no",
  5.     range = -1,
  6.     realAnimation = "no", -- make text effect visible only for players in range 1x1
  7.     multiplier = {
  8.         health = 1.0,
  9.         mana = 1.0
  10.     }
  11. }
  12.  
  13. config.removeOnUse = getBooleanFromString(config.removeOnUse)
  14. config.usableOnTarget = getBooleanFromString(config.usableOnTarget)
  15. config.splashable = getBooleanFromString(config.splashable)
  16. config.realAnimation = getBooleanFromString(config.realAnimation)
  17.  
  18. local POTIONS = {
  19.     [8704] = {empty = 7636, splash = 42, health = {50, 100}}, -- small health potion
  20.     [7618] = {empty = 7636, splash = 42, health = {100, 200}}, -- health potion
  21.     [7588] = {empty = 7634, splash = 42, health = {200, 400}, level = 50, vocations = {3, 4, 7, 8}, vocStr = "knights and paladins"}, -- strong health potion
  22.     [7591] = {empty = 7635, splash = 42, health = {500, 700}, level = 80, vocations = {4, 8}, vocStr = "knights"}, -- great health potion
  23.     [8473] = {empty = 7635, splash = 42, health = {800, 1000}, level = 130, vocations = {4, 8}, vocStr = "knights"}, -- ultimate health potion
  24.  
  25.     [7620] = {empty = 7636, splash = 47, mana = {70, 130}}, -- mana potion
  26.     [7589] = {empty = 7634, splash = 47, mana = {110, 190}, level = 50, vocations = {1, 2, 3, 5, 6, 7}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion
  27.     [7590] = {empty = 7635, splash = 47, mana = {200, 300}, level = 80, vocations = {1, 2, 5, 6}, vocStr = "sorcerers and druids"}, -- great mana potion
  28.  
  29.     [8472] = {empty = 7635, splash = 43, health = {200, 400}, mana = {110, 190}, level = 80, vocations = {3, 7}, vocStr = "paladins"} -- great spirit potion
  30. }
  31.  
  32. local exhaust = createConditionObject(CONDITION_EXHAUST)
  33. setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))
  34.  
  35. function onUse(cid, item, fromPosition, itemEx, toPosition)
  36.     local potion = POTIONS[item.itemid]
  37.     if(not potion) then
  38.         return false
  39.     end
  40.  
  41.     if(not isPlayer(itemEx.uid) or (not config.usableOnTarget and cid ~= itemEx.uid)) then
  42.         if(not config.splashable) then
  43.             return false
  44.         end
  45.  
  46.         if(toPosition.x == CONTAINER_POSITION) then
  47.             toPosition = getThingPosition(item.uid)
  48.         end
  49.  
  50.         doDecayItem(doCreateItem(POOL, potion.splash, toPosition))
  51.         if(not potion.empty or config.removeOnUse) then
  52.             return true
  53.         end
  54.  
  55.  
  56.         return true
  57.     end
  58.  
  59.     if(hasCondition(cid, CONDITION_EXHAUST)) then
  60.         doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
  61.         return true
  62.     end
  63.  
  64.     if(((potion.level and getPlayerLevel(itemEx.uid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(itemEx.uid)))) and
  65.         not getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES))
  66.     then
  67.         doCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)
  68.         return true
  69.     end
  70.  
  71.     if(config.range > 0 and cid ~= itemEx.uid and getDistanceBetween(getThingPosition(cid), getThingPosition(itemEx.uid)) > config.range) then
  72.         return false
  73.     end
  74.  
  75.     local health = potion.health
  76.     if(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(health[1], health[2]) * config.multiplier.health))) then
  77.         return false
  78.     end
  79.  
  80.     local mana = potion.mana
  81.     if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(mana[1], mana[2]) * config.multiplier.mana))) then
  82.         return false
  83.     end
  84.  
  85.     doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_MAGIC_BLUE)
  86.     if(not config.realAnimation) then
  87.         doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
  88.     else
  89.         for i, tid in ipairs(getSpectators(getThingPosition(itemEx.uid), 1, 1)) do
  90.             if(isPlayer(tid)) then
  91.                 doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1, false, tid)
  92.             end
  93.         end
  94.     end
  95.  
  96.     doAddCondition(cid, exhaust)
  97.     doRemoveItem(item.uid, 1)
  98.     if(not potion.empty or config.removeOnUse) then
  99.         return true
  100.     end
  101.  
  102.  
  103.     return true
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement