• 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 Click to buy [modifications needed]

4Muki4

HOROHOROHORO
Joined
May 1, 2012
Messages
757
Reaction score
70
Hello,

i have this script which is from centera datapack, and when you right click it gives you a backpack of runes or just 20 potions. I would like it to do like this just give 1 item no backpack example: 1 sd or 1 potion nothing else
Script:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local cfg =
{
    [8000] = {backpackid = 2004, rune = 7618, charges = 1, cost = 1000},
    [8001] = {backpackid = 2002, rune = 7588, charges = 1, cost = 1000},
    [8002] = {backpackid = 2000, rune = 7591, charges = 1, cost = 1000},
    [8003] = {backpackid = 2001, rune = 8473, charges = 1, cost = 1000},
    [8004] = {backpackid = 2000, rune = 8472, charges = 1, cost = 1000},
    [8005] = {backpackid = 2000, rune = 7620, charges = 1, cost = 1000},
    [8006] = {backpackid = 2000, rune = 7589, charges = 1, cost = 1000},
    [8007] = {backpackid = 2000, rune = 7590, charges = 1, cost = 1000},
}
-- Variables --
local price = cfg[item.uid].cost
local types = cfg[item.uid].rune
local count = cfg[item.uid].charges
local bag = cfg[item.uid].backpackid
local name = getItemNameById(types)
local backpack_weight = getItemWeightById(bag,1)
local potions_weight = getItemWeightById(types,20)
local total_weight = backpack_weight + potions_weight
-- End --

        if getPlayerMoney(cid) > price then
                if getPlayerFreeCap(cid) > total_weight then
                        addBackpack = doCreateItemEx(bag,1)
                        for i=1,20 do
                                doAddContainerItem(addBackpack, types, count)
                        end
                        local addItemToPlayer = doPlayerAddItemEx(cid, addBackpack , 0)
                        if addItemToPlayer == RETURNVALUE_NOERROR then
                                doSendMagicEffect(fromPosition, CONST_ME_GIFT_WRAPS)
                                doSendAnimatedText(fromPosition, "Bought!", TEXTCOLOR_RED)
                                doPlayerRemoveMoney(cid, price)
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have purchased a backpack of ".. name .."s for ".. price .." gold.")
                        else
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don\'t have enough space in your backpack to put there a backpack of ".. name .."s.")
                        end
                else
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need ".. total_weight .." oz. to take a backpack of ".. name .."s.")
                end
        else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need ".. price .." gold coins for a backpack of ".. name .."s.")
        end

        return TRUE
end
 
Code:
local cfg = {
    [3001] = {rune = 2268, count = 370, cost = 1000}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local tmp = cfg[item.actionid]
    if not tmp then
        return true
    end
    if not doPlayerRemoveMoney(tmp.cost) then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You need '.. tmp.cost - getPlayerMoney(cid) .. ' more gold.')
    end
    local count, num = tmp.count, 0
    while count > 0 do
        num = math.min(100, count)
        doPlayerAddItem(cid, cfg.rune, num)
        count = count - num
    end
    return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, string.format('You have bought %d %s for %d gold coins.', tmp.count, getItemPluralNameById(tmp.rune), tmp.cost))
end
 
Hey, I installed the new script and tested it I'm sorry if i dint say it was for 0.4
this was the error
Code:
10:55 You need 1000 more gold.
10:55 /i 2160
10:55 You need -999000 more gold.
10:55 You need 0 more gold.
Edit: there was actually console error
Code:
[Error - Action Interface]
data/actions/scripts/shop.lua:onUse
Description:
(luaDoPlayerRemoveMoney) Player not found
 
Last edited:
Code:
local cfg = {
   [3001] = {rune = 2268, count = 370, cost = 1000}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local tmp = cfg[item.actionid]
    if not tmp then
        return true
    end
    if not doPlayerRemoveMoney(cid, tmp.cost) then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You need '.. tmp.cost - getPlayerMoney(cid) .. ' more gold.')
    end
    local count, num = tmp.count, 0
    while count > 0 do
        num = math.min(100, count)
        doPlayerAddItem(cid, cfg.rune, num)
        count = count - num
    end
    return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, string.format('You have bought %d %s for %d gold coins.', tmp.count, getItemPluralNameById(tmp.rune), tmp.cost))
end
 
this time another bug popped up
Code:
 11:23 You have bought 1 health potions for 1000 gold coins.
Code:
[Error - Action Interface]
data/actions/scripts/shop.lua:onUse
Description:
(luaDoPlayerAddItem) Item not found
 
this time another bug popped up
Code:
 11:23 You have bought 1 health potions for 1000 gold coins.
Code:
[Error - Action Interface]
data/actions/scripts/shop.lua:onUse
Description:
(luaDoPlayerAddItem) Item not found
change cfg.rune to tmp.rune
 
Back
Top