• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Remove vial from manafluids after use?

atyll

Member
Joined
Dec 30, 2008
Messages
380
Reaction score
16
As in title, my code is:

Code:
local exhaust = createConditionObject(CONDITION_EXHAUST_HEAL)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, 1000)

function onUse(cid, item, frompos, item2, topos)
    if((hasCondition(cid, CONDITION_EXHAUST_COMBAT) == TRUE) or (hasCondition(cid, CONDITION_EXHAUST_HEAL) == TRUE)) then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
        return TRUE
    end

    if item2.itemid == 1 then
        if item.type == 0 then
            doPlayerSendCancel(cid, "It is empty.")
        else
            if item2.uid == cid then
                doChangeTypeItem(item.uid, 0)
                if item.type == 7 then
                    new_mana = math.random(80, 160)
                    doPlayerAddMana(cid, new_mana)
                    doSendMagicEffect(topos, 12)
                    doPlayerSay(cid, "Aaaah...", 1)
                    doAddCondition(cid, exhaust)
                elseif item.type == 10 then
                    new_life = math.random(40, 80)
                    doPlayerAddHealth(cid, new_life)
                    doSendMagicEffect(topos, 12)
                    doPlayerSay(cid, "Aaaah...", 1)
                else
                    doPlayerSay(cid, "Gulp.", 1)
                end
            else
                doChangeTypeItem(item.uid, 0)
                splash = doCreateItem(2025, item.type, topos)
                doDecayItem(splash)
            end
        end
    elseif item2.itemid >= 490 and item2.itemid <= 517
    or item2.itemid >= 618 and item2.itemid <= 629
    or item2.itemid == 1368 or item2.itemid == 1369
    or item2.itemid >= 4820 and item2.itemid <= 4825
    or item2.itemid >= 4828 and item2.itemid <= 4831
    or item2.itemid >= 4608 and item2.itemid <= 4666 then
        doChangeTypeItem(item.uid, 1)
    elseif item2.itemid == 103 then
        doChangeTypeItem(item.uid, 19)
    elseif item2.itemid >= 598 and item2.itemid < 601
    or item2.itemid == 1509
    or item2.itemid >= 518 and item2.itemid <= 529 then
        doChangeTypeItem(item.uid, 26)
    elseif item2.itemid >= 351 and item2.itemid <= 355 then
        doChangeTypeItem(item.uid, 19)
    elseif item2.itemid >= 602 and item2.itemid <= 605
    or item2.itemid >= 4691 and item2.itemid <= 4755
    or item2.itemid == 4758 then
        doChangeTypeItem(item.uid, 28)
    elseif item2.itemid == 1771 then
        doChangeTypeItem(item.uid, 1)
    elseif item2.itemid == 1772 then
        doChangeTypeItem(item.uid, 3)
    elseif item2.itemid == 1773 then
        doChangeTypeItem(item.uid, 15)
    elseif item2.itemid > 2806 and item2.itemid < 3132
    or item2.itemid >= 4251 and item2.itemid <= 4327 then
        doChangeTypeItem(item.uid, 2)
    else
        if item.type == 0 then
            doPlayerSendCancel(cid, "It is empty.")
        else
            doChangeTypeItem(item.uid, 0)
            splash = doCreateItem(2025, item.type, topos)
            doDecayItem(splash)
        end
    end
   
    return TRUE
end
 
Next time give info about Distro.
I have TFS 0.3.6 and this is my potions.lua, i have "yes" for "removeOnUse"
Code:
local config = {
    removeOnUse = "yes",
    usableOnTarget = "yes", -- can be used on target? (fe. healing friend)
    splashable = "no",
    realAnimation = "no", -- make text effect visible only for players in range 1x1
    healthMultiplier = 1.0,
    manaMultiplier = 1.0
}

config.removeOnUse = getBooleanFromString(config.removeOnUse)
config.usableOnTarget = getBooleanFromString(config.usableOnTarget)
config.splashable = getBooleanFromString(config.splashable)
config.realAnimation = getBooleanFromString(config.realAnimation)

local POTIONS = {
    [8704] = {empty = 7636, splash = 2, health = {50, 100}}, -- small health potion
    [7618] = {empty = 7636, splash = 2, health = {100, 200}}, -- health potion
    [7588] = {empty = 7634, splash = 2, health = {200, 400}, level = 50, vocations = {3, 4, 7, 8}, vocStr = "knights and paladins"}, -- strong health potion
    [7591] = {empty = 7635, splash = 2, health = {500, 700}, level = 50, vocations = {4, 8}, vocStr = "knights"}, -- great health potion
    [8473] = {empty = 7635, splash = 2, health = {800, 1000}, level = 50, vocations = {4, 8}, vocStr = "knights"}, -- ultimate health potion

    [7620] = {empty = 7636, splash = 7, mana = {70, 130}}, -- mana potion
    [7589] = {empty = 7634, splash = 7, mana = {110, 190}, level = 50, vocations = {1, 2, 3, 5, 6, 7}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion
    [7590] = {empty = 7635, splash = 7, mana = {200, 300}, level = 50, vocations = {1, 2, 5, 6}, vocStr = "sorcerers and druids"}, -- great mana potion

    [8472] = {empty = 7635, splash = 3, health = {200, 400}, mana = {110, 190}, level = 50, vocations = {3, 7}, vocStr = "paladins"} -- great spirit potion
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local potion = POTIONS[item.itemid]
    if(not potion) then
        return false
    end

    if(not isPlayer(itemEx.uid) or (not config.usableOnTarget and cid ~= itemEx.uid)) then
        if(not config.splashable) then
            return false
        end

        if(toPosition.x == CONTAINER_POSITION) then
            toPosition = getThingPos(item.uid)
        end

        doDecayItem(doCreateItem(2016, potion.splash, toPosition))
        doTransformItem(item.uid, potion.empty)
        return true
    end

    if(hasCondition(cid, CONDITION_EXHAUST_HEAL)) then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
        return true
    end

    if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) and
        not getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES))
    then
        doCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)
        return true
    end

    local health = potion.health
    if(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(health[1], health[2]) * config.healthMultiplier))) then
        return false
    end

    local mana = potion.mana
    if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(mana[1], mana[2]) * config.manaMultiplier))) then
        return false
    end

    if isInArray({8704, 7618, 7588, 7591, 8473}, item.itemid) then
        doSendAnimatedText(getPlayerPosition(cid), "Ahhhh...", 180)
    elseif isInArray({7620, 7589, 7590, 8472}, item.itemid) then
        doSendAnimatedText(getPlayerPosition(cid), "Ahhhh...", 17)
    end
    doSendMagicEffect(getThingPos(itemEx.uid), 30)
    if realAnimation then
        for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1)) do
            if(isPlayer(tid)) then
            end
        end
    end

    doAddCondition(cid, exhaust)
    if(not potion.empty or config.removeOnUse) then
        doRemoveItem(item.uid, 1)
        return true
    end
    doRemoveItem(item.uid, 1)
    doPlayerAddItem(cid, potion.empty, 1)
    return true
end
 
Back
Top