• 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!

Script !sell item

adrianootavares

New Member
Joined
Jul 23, 2012
Messages
112
Reaction score
4
Location
Salvador - Bahia - Brasil
Is there a script that displays items by command;example:let's say the game has 20 fire sword and 2 demon helmet, it uses the command sell item on the item everything in the backpack.

SCRIPT TFS 1.3


Lua:
-- charge free accounts more since prem player support the server
local extraCost = 10 -- in percentage, 10 equals 10%

local shopItems = {
    ['backpack'] = {price = 20, count = 1},
    ['shovel'] = {price = 5, count = 1},
    ['pick'] = {price = 45, count = 1},
    ['rope'] = {price = 45, count = 1, itemid = 2120},
}

function increasePrice(base, extra)
    return base + math.ceil((extra/100) * base)
end

function onSay(player, words, param)
    local isPrem = player:isPremium()
    if param and param ~= '' then
        param = param:lower()
        local item = shopItems[param]
        if item then
            item.itemid = item.itemid or getItemIdByName(param)
            if not isPrem then
                item.price = increasePrice(item.price, extraCost)
            end
            if doPlayerRemoveMoney(player:getId(), item.price) then
                player:addItem(item.itemid, item.count)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Thank you for purchasing a " .. param .. "!")
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
                return false
            end
            player:sendCancelMessage("You do not have enough money to buy a " .. param .. ".")
            return false
        end
        player:sendCancelMessage("Sorry we don't sell " .. param .. ".")
    end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Please enter a shop item name to buy, prices are listed, free accounts pay "..extraCost.."% more than premium account.")
    for name, list in next, shopItems do
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, name .. ": " .. (isPrem and list.price or increasePrice(list.price, extraCost)) .. "gp." )
    end
    return false
end

change any of that from buy to sell

Lua:
--Buy Items With Command
    --Script by Programmer (Credits to Darkhaos)

local shop =
{
    ["aol"] = {money=10000, id=3057, amount=1},
    ["backpack"] = {money=100, id=2854, amount=1},
    ["food"] = {money=10, id=3725, amount=100},
    ["rope"] = {money=50, id=3003, amount=1},
    ["shovel"] = {money=50, id=3457, amount=1},
    ["machete"] = {money=250, id=3308, amount=1},
    ["pick"] = {money=200, id=3456, amount=1},
    ["rod"] = {money=500, id=3483, amount=1},
    ["worms"] = {money=200, id=3492, amount=100}
}
 
function onSay(cid, words, param)
    local text = "Here's a list of items available in the shop\nBuy Name : Item Name : Price : Amount\n\n"
    if(param == "" or param == nil) then
        for k, v in pairs(shop) do
            text = text .. k .. " - " .. v.money .. " - " .. getItemNameById(v.id) .. " - " .. v.amount .. "\n"
        end
        return doShowTextDialog(cid, 2195, text)
    else
        buyItem = shop[param]
        if buyItem then
                   if getPlayerMoney(cid) >= buyItem.money then
                doSendMagicEffect(getCreaturePosition(cid), 14)
                doPlayerAddItem(cid, buyItem.id, buyItem.amount)
                        doPlayerRemoveMoney(cid, buyItem.money)
                        doPlayerSendTextMessage(cid, 24, "Great choice! You've bought " .. param .. "for " .. buyItem.money .. "!")
                return true
                else
                        return doPlayerSendCancel(cid, "You require " .. buyItem.money .. " gold coins to buy this item.")
                end
            else
                return doPlayerSendCancel(cid, "Parameter Error 404: Wrong param")
        end
        end
    return true
end
 
Last edited:
Well an admin rejected my report, so I'll just type it in myself.

Here's the second script tabbed properly.
Lua:
--Buy Items With Command
--Script by Programmer (Credits to Darkhaos)

local shop =
{
    ["aol"] = {money=10000, id=3057, amount=1},
    ["backpack"] = {money=100, id=2854, amount=1},
    ["food"] = {money=10, id=3725, amount=100},
    ["rope"] = {money=50, id=3003, amount=1},
    ["shovel"] = {money=50, id=3457, amount=1},
    ["machete"] = {money=250, id=3308, amount=1},
    ["pick"] = {money=200, id=3456, amount=1},
    ["rod"] = {money=500, id=3483, amount=1},
    ["worms"] = {money=200, id=3492, amount=100}
}
 
function onSay(cid, words, param)
    local text = "Here's a list of items available in the shop\nBuy Name : Item Name : Price : Amount\n\n"
    if(param == "" or param == nil) then
        for k, v in pairs(shop) do
            text = text .. k .. " - " .. v.money .. " - " .. getItemNameById(v.id) .. " - " .. v.amount .. "\n"
        end
        return doShowTextDialog(cid, 2195, text)
    else
        buyItem = shop[param]
        if buyItem then
            if getPlayerMoney(cid) >= buyItem.money then
                doSendMagicEffect(getCreaturePosition(cid), 14)
                doPlayerAddItem(cid, buyItem.id, buyItem.amount)
                doPlayerRemoveMoney(cid, buyItem.money)
                doPlayerSendTextMessage(cid, 24, "Great choice! You've bought " .. param .. "for " .. buyItem.money .. "!")
                return true
            else
                return doPlayerSendCancel(cid, "You require " .. buyItem.money .. " gold coins to buy this item.")
            end
        else
            return doPlayerSendCancel(cid, "Parameter Error 404: Wrong param")
        end
    end
    return true
end
 
Well an admin rejected my report, so I'll just type it in myself.

Here's the second script tabbed properly.
Lua:
--Buy Items With Command
--Script by Programmer (Credits to Darkhaos)

local shop =
{
    ["aol"] = {money=10000, id=3057, amount=1},
    ["backpack"] = {money=100, id=2854, amount=1},
    ["food"] = {money=10, id=3725, amount=100},
    ["rope"] = {money=50, id=3003, amount=1},
    ["shovel"] = {money=50, id=3457, amount=1},
    ["machete"] = {money=250, id=3308, amount=1},
    ["pick"] = {money=200, id=3456, amount=1},
    ["rod"] = {money=500, id=3483, amount=1},
    ["worms"] = {money=200, id=3492, amount=100}
}

function onSay(cid, words, param)
    local text = "Here's a list of items available in the shop\nBuy Name : Item Name : Price : Amount\n\n"
    if(param == "" or param == nil) then
        for k, v in pairs(shop) do
            text = text .. k .. " - " .. v.money .. " - " .. getItemNameById(v.id) .. " - " .. v.amount .. "\n"
        end
        return doShowTextDialog(cid, 2195, text)
    else
        buyItem = shop[param]
        if buyItem then
            if getPlayerMoney(cid) >= buyItem.money then
                doSendMagicEffect(getCreaturePosition(cid), 14)
                doPlayerAddItem(cid, buyItem.id, buyItem.amount)
                doPlayerRemoveMoney(cid, buyItem.money)
                doPlayerSendTextMessage(cid, 24, "Great choice! You've bought " .. param .. "for " .. buyItem.money .. "!")
                return true
            else
                return doPlayerSendCancel(cid, "You require " .. buyItem.money .. " gold coins to buy this item.")
            end
        else
            return doPlayerSendCancel(cid, "Parameter Error 404: Wrong param")
        end
    end
    return true
end

BUG
 
sigh.. I guess I got what I asked for. lol

try this
Lua:
local sellable_items = {
    ["aol"]    = {money = 10000, itemid = 3057, amount = 1},
    ["backpack"] = {money = 100, itemid = 2854, amount = 1},
    ["food"] = {money = 10, itemid = 3725, amount = 100},
    ["rope"] = {money = 50, itemid = 3003, amount = 1},
    ["shovel"] = {money = 50, itemid = 3457, amount = 1},
    ["machete"] = {money = 250, itemid = 3308, amount = 1},
    ["pick"] = {money = 200, itemid = 3456, amount = 1},
    ["rod"] = {money = 500, itemid = 3483, amount = 1},
    ["worms"] = {money = 200, itemid = 3492, amount = 100}
}
 
function onSay(cid, words, param)
    local text = "Here's a list of items available to sell\nSell Name | Amount : Item Name = Price\n\n"
    if param == "" or param == nil then
        for k, v in pairs(sellable_items) do
            text = text .. k .. " | " .. v.amount .. " : " .. getItemNameById(v.itemid) .. " = " .. v.money .. "\n"
        end
        doShowTextDialog(cid, 2195, text)
        return true
    end
    
    sellItem = sellable_items[param]
    if not sellItem then
        doPlayerSendCancel(cid, param .. " is not a known sellable item. Please check your spelling and try again.")
        return true
    end
    
    if getPlayerItemCount(cid, sellItem.itemid) < sellItem.amount then
        doPlayerSendCancel(cid, "You require " .. sellItem.amount .. " " .. getItemNameById(sellItem.itemid) .. " to sell this item for " .. sellItem.money .. " gold coins.")
        return true
    end
    
    doPlayerRemoveItem(cid, sellItem.itemid, sellItem.amount)
    doPlayerAddMoney(cid, money)
    doSendMagicEffect(getCreaturePosition(cid), 14)
    doPlayerSendTextMessage(cid, 24, "You've sold " .. getItemNameById(sellItem.itemid) .. " for " .. sellItem.money .. " gold coins.")
    return true
end
 
Last edited:
This should work to your liking.

Lua:
local shop = {
    ["aol"] = {itemid = 3057, sellPrice = 5000}, -- Price for premium users --
    ["backpack"] = {itemid = 2854, sellPrice = 10}
}

local freePlayerPrice = .10 -- 10% less for free users

function onSay(player, words, param, channel)
    if param == "" then
        local text = "Here is a list of items you can sell:\n"
        for k, v in pairs(shop) do
            local itemName = k
            local price = 0
         
            if player:isPremium() then
                price = v.sellPrice
            else
                price = math.floor((v.sellPrice - (v.sellPrice * freePlayerPrice)))
                if price < 1 then
                    price = 1
                end
            end
         
            text = text..""..itemName.." | "..getItemNameById(v.itemid).." = "..price.. "\n"
        end
        player:showTextDialog(2195, text)
        return false
    else
     
        local item = shop[param:lower()]
     
        if not item then player:sendCancelMessage("That is not a sellable item. Type !sell for a list of sellable items.") return false end
     
        local itemAmount = player:getItemCount(shop.itemid)
     
        if itemAmount < 1 then player:sendCancelMessage("You do not have any "..ItemType(shop.itemid):getName().." to sell.") return false end
     
        local priceEach = 0
     
        if player:isPremium() then
            priceEach = shop.sellPrice
        else
            priceEach = math.floor((shop.sellPrice - (shop.sellPrice * freePlayerPrice)))
            if priceEach < 1 then
                priceEach = 1
            end
        end
     
        local addMoney = itemAmount * priceEach
     
        if player:removeItem(shop.itemid, itemAmount) then
            player:addMoney(addMoney)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have sold "..itemAmount.." "..ItemType(shop.itemid):getName().." for "..addMoney.." gold.")
        else
            player:sendCancelMessage("The shop was unable to buy your items. Report this to a gamemaster.")
        end
    end
return false
end
 
This should work to your liking.

Lua:
local shop = {
    ["aol"] = {itemid = 3057, sellPrice = 5000}, -- Price for premium users --
    ["backpack"] = {itemid = 2854, sellPrice = 10}
}

local freePlayerPrice = .10 -- 10% less for free users

function onSay(player, words, param, channel)
    if param == "" then
        local text = "Here is a list of items you can sell:\n"
        for k, v in pairs(shop) do
            local itemName = k
            local price = 0
       
            if player:isPremium() then
                price = v.sellPrice
            else
                price = math.floor((v.sellPrice - (v.sellPrice * freePlayerPrice)))
                if price < 1 then
                    price = 1
                end
            end
       
            text = text..""..itemName.." | "..getItemNameById(v.itemid).." = "..price.. "\n"
        end
        player:showTextDialog(2195, text)
        return false
    else
   
        local item = shop[param:lower()]
   
        if not item then player:sendCancelMessage("That is not a sellable item. Type !sell for a list of sellable items.") return false end
   
        local itemAmount = player:getItemCount(shop.itemid)
   
        if itemAmount < 1 then player:sendCancelMessage("You do not have any "..ItemType(shop.itemid):getName().." to sell.") return false end
   
        local priceEach = 0
   
        if player:isPremium() then
            priceEach = shop.sellPrice
        else
            priceEach = math.floor((shop.sellPrice - (shop.sellPrice * freePlayerPrice)))
            if priceEach < 1 then
                priceEach = 1
            end
        end
   
        local addMoney = itemAmount * priceEach
   
        if player:removeItem(shop.itemid, itemAmount) then
            player:addMoney(addMoney)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have sold "..itemAmount.." "..ItemType(shop.itemid):getName().." for "..addMoney.." gold.")
        else
            player:sendCancelMessage("The shop was unable to buy your items. Report this to a gamemaster.")
        end
    end
return false
end


 
Wups
Lua:
local shop = {
    ["aol"] = {itemid = 3057, sellPrice = 5000}, -- Price for premium users --
    ["backpack"] = {itemid = 2854, sellPrice = 10}
}

local freePlayerPrice = .10 -- 10% less for free users

function onSay(player, words, param, channel)
    if param == "" then
        local text = "Here is a list of items you can sell:\n"
        for k, v in pairs(shop) do
            local itemName = k
            local price = 0
       
            if player:isPremium() then
                price = v.sellPrice
            else
                price = math.floor((v.sellPrice - (v.sellPrice * freePlayerPrice)))
                if price < 1 then
                    price = 1
                end
            end
       
            text = text..""..itemName.." | "..getItemNameById(v.itemid).." = "..price.. "\n"
        end
        player:showTextDialog(2195, text)
        return false
    else
   
        local item = shop[param:lower()]
   
        if not item then player:sendCancelMessage("That is not a sellable item. Type !sell for a list of sellable items.") return false end
   
        local itemAmount = player:getItemCount(item.itemid)
   
        if itemAmount < 1 then player:sendCancelMessage("You do not have any "..ItemType(item.itemid):getName().." to sell.") return false end
   
        local priceEach = 0
   
        if player:isPremium() then
            priceEach = item.sellPrice
        else
            priceEach = math.floor((item.sellPrice - (item.sellPrice * freePlayerPrice)))
            if priceEach < 1 then
                priceEach = 1
            end
        end
   
        local addMoney = itemAmount * priceEach
   
        if player:removeItem(item.itemid, itemAmount) then
            player:addMoney(addMoney)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have sold "..itemAmount.." "..ItemType(item.itemid):getName().." for "..addMoney.." gold.")
        else
            player:sendCancelMessage("The shop was unable to buy your items. Report this to a gamemaster.")
        end
    end
return false
end
 
Wups
Lua:
local shop = {
    ["aol"] = {itemid = 3057, sellPrice = 5000}, -- Price for premium users --
    ["backpack"] = {itemid = 2854, sellPrice = 10}
}

local freePlayerPrice = .10 -- 10% less for free users

function onSay(player, words, param, channel)
    if param == "" then
        local text = "Here is a list of items you can sell:\n"
        for k, v in pairs(shop) do
            local itemName = k
            local price = 0
      
            if player:isPremium() then
                price = v.sellPrice
            else
                price = math.floor((v.sellPrice - (v.sellPrice * freePlayerPrice)))
                if price < 1 then
                    price = 1
                end
            end
      
            text = text..""..itemName.." | "..getItemNameById(v.itemid).." = "..price.. "\n"
        end
        player:showTextDialog(2195, text)
        return false
    else
  
        local item = shop[param:lower()]
  
        if not item then player:sendCancelMessage("That is not a sellable item. Type !sell for a list of sellable items.") return false end
  
        local itemAmount = player:getItemCount(item.itemid)
  
        if itemAmount < 1 then player:sendCancelMessage("You do not have any "..ItemType(item.itemid):getName().." to sell.") return false end
  
        local priceEach = 0
  
        if player:isPremium() then
            priceEach = item.sellPrice
        else
            priceEach = math.floor((item.sellPrice - (item.sellPrice * freePlayerPrice)))
            if priceEach < 1 then
                priceEach = 1
            end
        end
  
        local addMoney = itemAmount * priceEach
  
        if player:removeItem(item.itemid, itemAmount) then
            player:addMoney(addMoney)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have sold "..itemAmount.." "..ItemType(item.itemid):getName().." for "..addMoney.." gold.")
        else
            player:sendCancelMessage("The shop was unable to buy your items. Report this to a gamemaster.")
        end
    end
return false
end




is almost there, more is giving this error there.
 
change

Code:
text = text..""..itemName.." | "..getItemNameById(v.itemid).." = "..price.. "\n"

to

Code:
text = text..""..itemName.." | "..ItemType(v.itemid):getName().." = "..price.. "\n"
 
Back
Top