• 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 Buying potions Talkaction

demon088

#088 in the Horde
Joined
Jun 17, 2009
Messages
250
Solutions
3
Reaction score
30
Location
Hell
Hello again OtLand!
I have TFS 1.1 and I was trying to create a talkaction which could be used to buy potions just by saying "!manapotion 25" and then money equal to the price of 25 potions (50gp each) could be charged to the gold you are carrying. But I can't set the amount parameter to the script because I don't know really how to add this feature to the talkaction. Here is my script:

manapot.lua
Code:
local amount = ??? <!--- I don't know how to register this, example: "!manapotion 20" and then 20 will be registered here as 'amount' --->
local cost = 50 * amount

function onSay(cid, words, param)
if doPlayerRemoveMoney(cid, cost) == TRUE then
local bp = doPlayerAddItem(cid, 7620, amount)
doCreatureSay(cid, "You have bought '.. amount ..' mana potion.", TALKTYPE_ORANGE_1)
else
doCreatureSay(cid, "You need '.. cost ..' gold to buy such mana potion.", TALKTYPE_ORANGE_1)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
end
end

talkactions.xml
Code:
    <talkaction words="!manapotion" separator=" " script="pots/manapot.lua" />

Please I need some help making this script to work like this. My knowledge isn't enough making this script and I'd be thankful if someone could help me with this. Also, I'd like to share this talkaction script to someone who's thinking the same way as me for their OTSs as an aditional system to buy potions. Then I'll make a script for every potion including dynamic systems for higher levels.
Thanks for all the help!
 
Solution
Lua:
function onSay(cid, words, param)
    param = tonumber(param)
    if not param then
        -- error message here if you want, no number param provided
        return true
    end
    -- rest of the script here
I loved this I added it to all my pot scripts.

Lua:
local config = {
    price = 50,
    limit = 500
}

function onSay(cid, words, param)
    if param >= config.limit then
        doCreatureSay(cid, 'You can only buy ' .. config.limit .. ' great health potion a time.', TALKTYPE_ORANGE_1)
        return true
    end

    local cost = config.price * param
    if doPlayerRemoveMoney(cid, cost) then
        doPlayerAddItem(cid, 8704, param)
        doCreatureSay(cid, 'You have bought ' .. param .. ' small health...
Code:
function onSay(cid, words, param)
    local cost = 50 * param
    if doPlayerRemoveMoney(cid, cost) == true then
        local bp = doPlayerAddItem(cid, 7620, param)
        doCreatureSay(cid, 'You have bought '.. param ..' mana potion.', TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, 'You need '.. cost ..' gold to buy such mana potion.', TALKTYPE_ORANGE_1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end

end
 
Code:
function onSay(cid, words, param)
    local cost = 50 * param
    if doPlayerRemoveMoney(cid, cost) == true then
        local bp = doPlayerAddItem(cid, 7620, param)
        doCreatureSay(cid, 'You have bought '.. param ..' mana potion.', TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, 'You need '.. cost ..' gold to buy such mana potion.', TALKTYPE_ORANGE_1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end

end

Dude I was so dumb. Thank you so much. xD
I will post the final script then.
 
I have a doubt again, I want to set a limit of the amount of potions you can buy when you use the talkaction. I mean if you try to buy 120000 a message will say that you can only but a maximum of 1000 potions.
This is what I was trying:

Code:
function onSay(cid, words, param)
    local cost = 500 * param
    local limit = 1000
if param =< limit then
    if doPlayerRemoveMoney(cid, cost) == true then
        local bp = doPlayerAddItem(cid, 7591, param)
        doCreatureSay(cid, 'You have bought '.. param ..' great health potion.', TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, 'You need '.. cost ..' gold to buy '.. param ..' great health potion.', TALKTYPE_ORANGE_1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end
else
        doCreatureSay(cid, 'You can only buy '.. limit ..' great health potion a time.', TALKTYPE_ORANGE_1)
end
end
 
Last edited:
I have a doubt again, I want to set a limit of the amount of potions you can buy when you use the talkaction. I mean if you try to buy 120000 a message will say that you can only but a maximum of 1000 potions.
This is what I was trying:

Code:
function onSay(cid, words, param)
    local cost = 500 * param
    local limit = 1000
if param is =< limit then
    if doPlayerRemoveMoney(cid, cost) == true then
        local bp = doPlayerAddItem(cid, 7591, param)
        doCreatureSay(cid, 'You have bought '.. param ..' great health potion.', TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, 'You need '.. cost ..' gold to buy '.. param ..' great health potion.', TALKTYPE_ORANGE_1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end
else
        doCreatureSay(cid, 'You can only buy '.. limit ..' great health potion a time.', TALKTYPE_ORANGE_1)
end
end

Issue:
Code:
[Warning - Event::checkScript] Can not load script: scripts/pots/ghealthpot.lua
data/talkactions/scripts/pots/ghealthpot.lua:4: 'then' expected near 'is'

Lua:
if param <= limit then
Lua:
if doPlayerRemoveMoney(cid, cost) then
 
Lua:
if param <= limit then
Lua:
if doPlayerRemoveMoney(cid, cost) then
I'm still getting issues.

Script:
Lua:
function onSay(cid, words, param)
    local cost = 50 * param
    local cfg = { level = 1, limit = 500, msgtype = MESSAGE_STATUS_CONSOLE_BLUE }
if param <= limit then
    if doPlayerRemoveMoney(cid, cost) then
        local bp = doPlayerAddItem(cid, 8704, param)
        doCreatureSay(cid, 'You have bought '.. param ..' small health potion.', TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, 'You need '.. cost ..' gold to buy '.. param ..' small health potion.', TALKTYPE_ORANGE_1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end 
else
        doCreatureSay(cid, 'You can only buy '.. limit ..' great health potion a time.', TALKTYPE_ORANGE_1)
end
end

Issue:
Lua:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/pots/smallhealthpot.lua:onSay
data/talkactions/scripts/pots/smallhealthpot.lua:4: attempt to compare string with nil
stack traceback:
        [C]: in function '__le'
        data/talkactions/scripts/pots/smallhealthpot.lua:4: in function <data/talkactions/scripts/pots/smallhealthpot.lua:1>
 
I'm still getting issues.

Script:
Lua:
function onSay(cid, words, param)
    local cost = 50 * param
    local cfg = { level = 1, limit = 500, msgtype = MESSAGE_STATUS_CONSOLE_BLUE }
if param <= limit then
    if doPlayerRemoveMoney(cid, cost) then
        local bp = doPlayerAddItem(cid, 8704, param)
        doCreatureSay(cid, 'You have bought '.. param ..' small health potion.', TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, 'You need '.. cost ..' gold to buy '.. param ..' small health potion.', TALKTYPE_ORANGE_1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end
else
        doCreatureSay(cid, 'You can only buy '.. limit ..' great health potion a time.', TALKTYPE_ORANGE_1)
end
end

Issue:
Lua:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/pots/smallhealthpot.lua:onSay
data/talkactions/scripts/pots/smallhealthpot.lua:4: attempt to compare string with nil
stack traceback:
        [C]: in function '__le'
        data/talkactions/scripts/pots/smallhealthpot.lua:4: in function <data/talkactions/scripts/pots/smallhealthpot.lua:1>

Limit isn't set
Lua:
local limit = 1000

But since you changed the script you have to use this;
Lua:
if param <= cfg.limit then

You have to do that with all the variables now, also move the table "cfg" from the scope aka before function onSay ..
 
Limit isn't set
Lua:
local limit = 1000

But since you changed the script you have to use this;
Lua:
if param <= cfg.limit then

You have to do that with all the variables now, also move the table "cfg" from the scope aka before function onSay ..

It has no issues, but the script is not respecting the limit. I can still buy more than 1000 potions.
 
It has no issues, but the script is not respecting the limit. I can still buy more than 1000 potions.

Lua:
local config = {
    price = 50,
    limit = 500
}

function onSay(cid, words, param)
    if param >= config.limit then
        doCreatureSay(cid, 'You can only buy ' .. config.limit .. ' great health potion a time.', TALKTYPE_ORANGE_1)
        return true
    end

    local cost = config.price * param
    if doPlayerRemoveMoney(cid, cost) then
        doPlayerAddItem(cid, 8704, param)
        doCreatureSay(cid, 'You have bought ' .. param .. ' small health potion.', TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, 'You need ' .. cost .. ' gold to buy ' .. param .. ' small health potion.', TALKTYPE_ORANGE_1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end

    return true
end
 
Lua:
function onSay(cid, words, param)
    param = tonumber(param)
    if not param then
        -- error message here if you want, no number param provided
        return true
    end
    -- rest of the script here
 
Lua:
function onSay(cid, words, param)
    param = tonumber(param)
    if not param then
        -- error message here if you want, no number param provided
        return true
    end
    -- rest of the script here
I loved this I added it to all my pot scripts.

Lua:
local config = {
    price = 50,
    limit = 500
}

function onSay(cid, words, param)
    if param >= config.limit then
        doCreatureSay(cid, 'You can only buy ' .. config.limit .. ' great health potion a time.', TALKTYPE_ORANGE_1)
        return true
    end

    local cost = config.price * param
    if doPlayerRemoveMoney(cid, cost) then
        doPlayerAddItem(cid, 8704, param)
        doCreatureSay(cid, 'You have bought ' .. param .. ' small health potion.', TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, 'You need ' .. cost .. ' gold to buy ' .. param .. ' small health potion.', TALKTYPE_ORANGE_1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end

    return true
end
It's not working, when I add the limit control the talkaction has issues and just stop working.

It's all working with this:
Code:
function onSay(cid, words, param)

    param = tonumber(param)
    if not param then
            doPlayerSendCancel(cid, "You must set the number of desired potions")
        return true
    end

      local cost = 50 * param
    local cfg = { level = 1, limit = 100, msgtype = MESSAGE_STATUS_CONSOLE_BLUE }

    if param > cfg.limit then
            doPlayerSendCancel(cid, "You can only buy " .. cfg.limit .. " small health potion a time.")
        return true
    end

    if doPlayerRemoveMoney(cid, cost) then
        local bp = doPlayerAddItem(cid, 8704, param)
        doCreatureSay(cid, 'You have bought '.. param ..' small health potion.', TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, 'You need '.. cost ..' gold to buy '.. param ..' small health potion.', TALKTYPE_ORANGE_1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end 
end
Thanks @WibbenZ and @Static_ for your help!
 
Last edited by a moderator:
Solution
Lua:
function onSay(cid, words, param)
    local param = 1 * param
    local cost = 50 * param
    local limit = 500
 
if param <= limit then
    if doPlayerRemoveMoney(cid, cost) then
        local bp = doPlayerAddItem(cid, 8704, param)
        doCreatureSay(cid, 'You have bought '.. param ..' small health potion.', TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, 'You need '.. cost ..' gold to buy '.. param ..' small health potion.', TALKTYPE_ORANGE_1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end
else
        doCreatureSay(cid, 'You can only buy '.. limit ..' great health potion a time.', TALKTYPE_ORANGE_1)
end
end

Oh sorry, I din't see above
 
Lua:
function onSay(cid, words, param)
    local param = 1 * param
    local cost = 50 * param
    local limit = 500
 
if param <= limit then
    if doPlayerRemoveMoney(cid, cost) then
        local bp = doPlayerAddItem(cid, 8704, param)
        doCreatureSay(cid, 'You have bought '.. param ..' small health potion.', TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, 'You need '.. cost ..' gold to buy '.. param ..' small health potion.', TALKTYPE_ORANGE_1)
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end
else
        doCreatureSay(cid, 'You can only buy '.. limit ..' great health potion a time.', TALKTYPE_ORANGE_1)
end
end

Oh sorry, I din't see above
Thank you anyway!
 
Back
Top