• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction [Action] Potions with charges

soul4soul

Intermediate OT User
Joined
Aug 13, 2007
Messages
1,875
Solutions
3
Reaction score
128
Location
USA
i know this has been done many times before but i think mine is a lot easier then most of them out there.

replace ur potions.lua with this
Code:
local config = {
    removeOnUse = "no",
    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}, storage = 49990}, -- small health potion
    [7618] = {empty = 7636, splash = 2, health = {100, 200}, storage = 49989}, -- health potion
    [7588] = {empty = 7634, splash = 2, health = {200, 400}, level = 50, vocations = {3, 4, 7, 8}, vocStr = "knights and paladins", storage = 49988}, -- strong health potion
    [7591] = {empty = 7635, splash = 2, health = {500, 700}, level = 80, vocations = {4, 8}, vocStr = "knights", storage = 49987}, -- great health potion
    [8473] = {empty = 7635, splash = 2, health = {800, 1000}, level = 130, vocations = {4, 8}, vocStr = "knights", storage = 49986}, -- ultimate health potion

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

    [8472] = {empty = 7635, splash = 3, health = {200, 400}, mana = {110, 190}, level = 80, vocations = {3, 7}, vocStr = "paladins", storage = 49982} -- 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

    if getPlayerStorageValue(cid, potion.storage) > 1 then
        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
        setPlayerStorageValue(cid, potion.storage, getPlayerStorageValue(cid, potion.storage)-1)
        doPlayerSendTextMessage(cid, 19, "Using 1 of "..getPlayerStorageValue(cid, potion.storage).." charges.")
    else 
        doPlayerSendTextMessage(cid, 19, "You are out of charges, buy more charges by typing: !charges |type|,|amount|.")
        return false
    end

    
    
    doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)
    if(not realAnimation) then
        doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
    else
        for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1)) do
            if(isPlayer(tid)) then
                doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1, false, tid)
            end
        end
    end

        
    doAddCondition(cid, exhaust)
    return true
end

here is the talkaction to get more charges

add this to talkactions.xml
Code:
<talkaction words="!charges" event="script" value="charges.lua"/>

create a new file in data\talkaction\scripts called charges.lua
Code:
function onSay(cid, words, param)    
--Start configuration --
    local items = 
    {
     ['hp'] = {cost = 45, storage = 49989},
     ['shp'] = {cost = 100, storage = 49988},
     ['ghp'] = {cost = 190, storage = 49987},
     ['uhp'] = {cost = 310, storage = 49986},
     ['mp'] = {cost = 50, storage = 49985},
     ['smp'] = {cost = 80, storage = 49984},
     ['gmp'] = {cost = 120, storage = 49983}, 
     ['gsp'] = {cost = 190, storage = 49982}
    }    
-- End configuration --    

    local t = string.explode(param, ",")
    local item = items[t[1]]
    local amount = tonumber(t[2])    
    
    -- Checks if we can buy that itemname --
    if item then
        -- Checks if the player has enough money --
        if doPlayerRemoveMoney(cid, item.cost*amount) == LUA_NO_ERROR then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You have bought '..amount..' '..t[1]..' charges for '..(item.cost*amount)..' golden pieces.')
            setPlayerStorageValue(cid, item.storage, getPlayerStorageValue(cid, item.storage)+amount)
        else
            doPlayerSendCancel(cid, 'You dont have enough money to buy that many charges.')
            doSendMagicEffect(getPlayerPosition (cid), CONST_ME_POFF)    
        end
    else            
        -- Sends the player a message wich includes items he can buy --
        text = "Charges you can buy:\n"
        -- Getting the all itemnames and prics --
        for item1 in pairs (items) do    
            -- Sends a message with each itemname and price --
            text = text .. "\n" .. item1
        end
        text = text .. "\n\nexample: type '!charges gmp,100' to buy 100 great mana potion charges"
        doPlayerPopupFYI(cid, text)
    end
    return true
end

to buy more charges type
!charges |type|,|amount|
EX. !potions uhp,100 will buy 100 ultimate health pots.

you just need 1 potion in your inventory. when you use a potion you get this msg in the default channel
13:29 Using 1 of 87 charges.

if you type !charges youll get a popup box telling you what you can buy and an example of how to buy charges
 
Last edited:
That reminds me... I need to post my suggestion example in the project page..

replace this line:
if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) and
with
local playerVoc = 0
if isKnight(cid) then
playerVoc = 4
elseif isPaladin(cid) then
playerVoc = 3
elseif isDruid(cid) then
playerVoc = 2
elseif isSorcerer(cid) then
playerVoc = 1
end

if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, playerVoc))) and
then you can safely remove any vocation numbers not 1-4 in the potions table.

The player shouldn't have to edit this file to extend the promotions chain. The vocations lua and vocations xml should be enough! Anyways, that's not your fault, but an inheritance from the original script. I had posted about this topic a week or two ago and this reminded me. =P
 
Last edited:
mines in an mod but i added it and that should work. u dont need anything for potions you just need to replace your old potions.lua
 
That reminds me... I need to post my suggestion example in the project page..

replace this line:
with
then you can safely remove any vocation numbers not 1-4 in the potions table.

The player shouldn't have to edit this file to extend the promotions chain. The vocations lua and vocations xml should be enough! Anyways, that's not your fault, but an inheritance from the original script. I had posted about this topic a week or two ago and this reminded me. =P

In the newest tfs you have only 4 vocations. The promoted vocations are the same, they are just promoted. F.e. sorcerer - 1, master sorcerer (promoted) - 1
 
In the newest tfs you have only 4 vocations. The promoted vocations are the same, they are just promoted. F.e. sorcerer - 1, master sorcerer (promoted) - 1
yes, with promotion levels(0 - non promoted(sorcerer) 1- first promotion(master sorcerer)
 
It should be NPC instead Talkcation. Please can anyone fix NPC?
 
Last edited:
Hello, I know this thread was made over 2 years ago but I wanted to ask if there was a way to fix the errors I get when I use this script. I get this when I try to use potions:
Code:
[23/12/2012 10:59:25] Lua Script Error: [Test Interface] 
[23/12/2012 10:59:25] data/actions/scripts/potions/potions.lua
[23/12/2012 10:59:25] data/actions/scripts/potions/potions.lua:11: attempt to call global 'getBooleanFromString' (a nil value)
[23/12/2012 10:59:25] stack traceback:
[23/12/2012 10:59:25] 	[C]: in function 'getBooleanFromString'
[23/12/2012 10:59:25] 	data/actions/scripts/potions/potions.lua:11: in main chunk
[23/12/2012 10:59:25] Warning: [Event::checkScript] Can not load script. /scripts/potions/potions.lua
I use TFS 0.2.14 (Mystic Spirit) for reference.

Thank you for your time! :)
 
Back
Top