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

TFS 0.X TFS 0.3.6 [LUA] COMMAND BUY SELL MARKET SELLER TRADE OFF IN GAME

samuel157

/root
Joined
Mar 19, 2010
Messages
518
Solutions
3
Reaction score
71
Location
São Paulo, Brazil
GitHub
Samuel10M
!buy demon armor, 3, 1, player name demo armor send only 3 demon armor !buy demon armor, 3, 1, player name

buy 3 demon armors for 1 vip coin at the price the player launches on the market as 3



@potinho

<talkaction words="!buy;!sell" event="script" value="buy.lua"/>
<talkaction words="!list" event="script" value="checkselllist.lua"/>

LUA:
-- Initialize global tables for active purchases and sales
activeBuys = activeBuys or {}
activeSells = activeSells or {}

-- Configurations
local config = {
    validCurrencyId = 11192, -- VIP coin ID
}

-- Function to list available items
local function listItems(cid)
    if #activeSells == 0 then
        doPlayerSendCancel(cid, "There are no items for sale at the moment.")
        return true
    end

    local message = "Items available for sale:\n"
    for i, sell in ipairs(activeSells) do
        message = message .. i .. ". " .. sell.itemName .. " (" .. sell.quantity .. "x) - Price: " .. sell.price .. " VIP Coins - Seller: " .. sell.seller .. "\n"
    end
    doPlayerPopupFYI(cid, message)
    return true
end

-- Function to sell an item
local function sellItem(cid, itemName, quantity, price)
    local itemId = getItemIdByName(itemName)
    if not itemId or itemId == 0 then
        doPlayerSendCancel(cid, "Item not found.")
        return true
    end

    if getPlayerItemCount(cid, itemId) < quantity then
        doPlayerSendCancel(cid, "You do not have the required quantity of items.")
        return true
    end

    table.insert(activeSells, {
        itemName = itemName,
        quantity = quantity,
        price = price,
        seller = getPlayerName(cid)
    })

    doPlayerRemoveItem(cid, itemId, quantity)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You listed " .. quantity .. "x " .. itemName .. " for sale at " .. price .. " VIP Coins.")
    return true
end

-- Function to buy an item
local function buyItem(cid, itemName, quantity, price, sellerName)
    for i, sell in ipairs(activeSells) do
        if sell.itemName:lower() == itemName:lower() and sell.seller:lower() == sellerName:lower() and sell.price == price and sell.quantity >= quantity then
            if getPlayerItemCount(cid, config.validCurrencyId) < price then
                doPlayerSendCancel(cid, "You do not have enough VIP Coins to make this purchase.")
                return true
            end

            doPlayerRemoveItem(cid, config.validCurrencyId, price) -- Remove VIP Coins from buyer
            doPlayerAddItem(cid, getItemIdByName(itemName), quantity) -- Add the item to the buyer

            -- Update the quantity of the item being sold
            sell.quantity = sell.quantity - quantity

            -- Notify buyer and seller
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You bought " .. quantity .. "x " .. itemName .. " from " .. sellerName .. " for " .. price .. " VIP Coins.")
            local sellerPlayer = getPlayerByName(sellerName)
            if sellerPlayer then
                doPlayerSendTextMessage(sellerPlayer, MESSAGE_INFO_DESCR, "Your item " .. itemName .. " was sold to " .. getPlayerName(cid) .. ".")
            end

            -- Remove from the list if quantity reaches zero
            if sell.quantity <= 0 then
                table.remove(activeSells, i)
            end

            return true
        end
    end

    doPlayerSendCancel(cid, "Item not found or invalid parameters.")
    return true
end

-- Main function
function onSay(cid, words, param)
    if words == "!sell" then
        local t = string.explode(param, ",")
        if #t ~= 3 then
            doPlayerSendCancel(cid, "Correct usage: !sell itemName, quantity, price")
            return true
        end

        local itemName = t[1]:trim()
        local quantity = tonumber(t[2])
        local price = tonumber(t[3])

        if not quantity or not price or quantity <= 0 or price <= 0 then
            doPlayerSendCancel(cid, "Invalid quantity or price.")
            return true
        end

        return sellItem(cid, itemName, quantity, price)
    elseif words == "!buy" then
        local t = string.explode(param, ",")
        if #t ~= 4 then
            doPlayerSendCancel(cid, "Correct usage: !buy itemName, quantity, price, sellerName")
            return true
        end

        local itemName = t[1]:trim()
        local quantity = tonumber(t[2])
        local price = tonumber(t[3])
        local sellerName = t[4]:trim()

        if not quantity or not price or quantity <= 0 or price <= 0 then
            doPlayerSendCancel(cid, "Invalid quantity or price.")
            return true
        end

        return buyItem(cid, itemName, quantity, price, sellerName)
    elseif words == "!list" then
        return listItems(cid)
    end

    return false
end
 
Last edited:
Samuel, as a brazilian i guess u need to improve ur way to ask, to get a better support here. Follow a script, didn't tested:

LUA:
-- Initialize global tables for active purchases and sales
activeBuys = activeBuys or {}
activeSells = activeSells or {}

-- Configurations
local config = {
    validCurrencyId = 11192, -- VIP coin ID
}

-- Function to list available items
local function listItems(cid)
    if #activeSells == 0 then
        doPlayerSendCancel(cid, "There are no items for sale at the moment.")
        return true
    end

    local message = "Items available for sale:\n"
    for i, sell in ipairs(activeSells) do
        message = message .. i .. ". " .. sell.itemName .. " (" .. sell.quantity .. "x) - Price: " .. sell.price .. " VIP Coins each - Seller: " .. sell.seller .. "\n"
    end
    doPlayerPopupFYI(cid, message)
    return true
end

-- Function to sell an item
local function sellItem(cid, itemName, quantity, price)
    local itemId = getItemIdByName(itemName)
    if not itemId or itemId == 0 then
        doPlayerSendCancel(cid, "Item not found.")
        return true
    end

    if getPlayerItemCount(cid, itemId) < quantity then
        doPlayerSendCancel(cid, "You do not have the required quantity of items.")
        return true
    end

    table.insert(activeSells, {
        itemName = itemName,
        quantity = quantity,
        price = price,
        seller = getPlayerName(cid)
    })

    doPlayerRemoveItem(cid, itemId, quantity)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You listed " .. quantity .. "x " .. itemName .. " for sale at " .. price .. " VIP Coins each.")
    return true
end

-- Function to buy an item
local function buyItem(cid, itemName, quantity, pricePerItem, sellerName)
    for i, sell in ipairs(activeSells) do
        if sell.itemName:lower() == itemName:lower() and sell.seller:lower() == sellerName:lower() and sell.price == pricePerItem and sell.quantity >= quantity then
            local totalPrice = pricePerItem * quantity

            if getPlayerItemCount(cid, config.validCurrencyId) < totalPrice then
                doPlayerSendCancel(cid, "You do not have enough VIP Coins to make this purchase.")
                return true
            end

            doPlayerRemoveItem(cid, config.validCurrencyId, totalPrice) -- Remove VIP Coins from buyer
            doPlayerAddItem(cid, getItemIdByName(itemName), quantity) -- Add the item to the buyer

            -- Update the quantity of the item being sold
            sell.quantity = sell.quantity - quantity

            -- Notify buyer and seller
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You bought " .. quantity .. "x " .. itemName .. " from " .. sellerName .. " for " .. totalPrice .. " VIP Coins.")
            local sellerPlayer = getPlayerByName(sellerName)
            if sellerPlayer then
                doPlayerSendTextMessage(sellerPlayer, MESSAGE_INFO_DESCR, "Your item " .. itemName .. " was sold to " .. getPlayerName(cid) .. ".")
            end

            -- Remove from the list if quantity reaches zero
            if sell.quantity <= 0 then
                table.remove(activeSells, i)
            end

            return true
        end
    end

    doPlayerSendCancel(cid, "Item not found or invalid parameters.")
    return true
end

-- Main function
function onSay(cid, words, param)
    if words == "!sell" then
        local t = string.explode(param, ",")
        if #t ~= 3 then
            doPlayerSendCancel(cid, "Correct usage: !sell itemName, quantity, price")
            return true
        end

        local itemName = t[1]:trim()
        local quantity = tonumber(t[2])
        local price = tonumber(t[3])

        if not quantity or not price or quantity <= 0 or price <= 0 then
            doPlayerSendCancel(cid, "Invalid quantity or price.")
            return true
        end

        return sellItem(cid, itemName, quantity, price)

    elseif words == "!buy" then
        local t = string.explode(param, ",")
        if #t ~= 4 then
            doPlayerSendCancel(cid, "Correct usage: !buy itemName, quantity, price, sellerName")
            return true
        end

        local itemName = t[1]:trim()
        local quantity = tonumber(t[2])
        local price = tonumber(t[3])
        local sellerName = t[4]:trim()

        if not quantity or not price or quantity <= 0 or price <= 0 then
            doPlayerSendCancel(cid, "Invalid quantity or price.")
            return true
        end

        return buyItem(cid, itemName, quantity, price, sellerName)

    elseif words == "!list" then
        return listItems(cid)
    end

    return false
end
 
@potinho command !List

I want that when I sell 3 demon armors for 1 vip coin !sell demon armor 3, 1 I want the command !buy to buy the 3 demon armors for the example price !buy demon armor 3, 1, Player name

LUA:
-- Initialize activeSells if not already initialized
activeBuys = activeBuys or {}
activeSells = activeSells or {}

-- onSay function to show items for sale
function onSay(cid, words, param)
    if #activeSells == 0 then
        doPlayerSendCancel(cid, "No items are currently being sold.")
        return true
    end

    local message = "Items available for sale:\n"
    for i, sell in ipairs(activeSells) do
        -- Replacing the display of gold coins with the currency name based on ID
        local currencyName = getCurrencyName(sell.currencyId)
        message = message .. i .. ". " .. sell.itemName .. " (" .. sell.quantity .. "x) - Price: " .. sell.price .. " " .. currencyName .. " - Seller: " .. sell.seller .. "\n"
    end

    doPlayerPopupFYI(cid, message)
    return true
end

-- Function to get the currency name based on the ID
function getCurrencyName(currencyId)
    local currencyNames = {
        [11192] = "VIP Coin's"  -- Added VIP Coin with ID 11192
    }

    -- Returns the currency name corresponding to the ID, or "Unknown Currency" if not found
    return currencyNames[currencyId] or "VIP Coin's"
end
 
Last edited:
Back
Top