• 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 TFS 7.72 - Downgrade Nekiro Need Talkaction !buyer items

Forkz

Well-Known Member
Joined
Jun 29, 2020
Messages
380
Solutions
1
Reaction score
89
Hi otlanders,

I need a talkactions to buy items mentioned, as in the model below, but for the TFS 1.5 version.


XML:
    <!-- Buy Command -->
    <config name="command-buy-config"><![CDATA[
        items = {
            ['brown backpack'] = {cost = 500, id = 1988},
            ['backpack'] = {cost = 500, id = 1988},
            ['bp'] = {cost = 500, id = 1988},
            ['green backpack'] = {cost = 500, id = 1998},
            ['yellow backpack'] = {cost = 500, id = 1999},
            ['red backpack'] = {cost = 500, id = 2000},
            ['purple backpack'] = {cost = 500, id = 2001},
            ['grey backpack'] = {cost = 500, id = 2003},
            ['blue backpack'] = {cost = 500, id = 2002},
            ['gold backpack'] = {cost = 500, id = 2004},
            ['rope'] = {cost = 500, id = 2120},
            ['shovel'] = {cost = 500, id = 2554},
            ['machete'] = {cost = 500, id = 2420},
            ['aol'] = {cost = 100000, id = 2173}
        }
    ]]></config>
    <talkaction words="!buy;/buy" event="script"><![CDATA[
        domodlib('command-buy-config')
        local config = {
            items = items
        }

        function onSay(cid, words, param, channel)
            if(param == '') then
                local str = ""
                for name, options in pairs(config.items) do
                    str = str .. "\n" .. name
                end

                doShowTextDialog(cid, 1950, "/buy or !buy:\n" .. str)
                return true
            end

            local item = config.items[param]
            if(item ~= nil) then
                if(not doPlayerRemoveMoney(cid, item.cost)) then
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Not enough money to buy " .. param .. ".\n(" .. item.cost .. "gp)")
                    return true
                end

                local amount = item.amount and item.amount or 1
                doPlayerAddItem(cid, item.id, amount)
                doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
            else
                doPlayerSendCancel(cid, "Item not found. Use '!buy' to see the list.")
            end

            return true
        end
    ]]></talkaction>
 
Solution
Everything would work as is thanks to compat.lua, here you are:
Lua:
local config = {
    items = {
        ['brown backpack'] = {cost = 500, id = 1988},
        ['backpack'] = {cost = 500, id = 1988},
        ['bp'] = {cost = 500, id = 1988},
        ['green backpack'] = {cost = 500, id = 1998},
        ['yellow backpack'] = {cost = 500, id = 1999},
        ['red backpack'] = {cost = 500, id = 2000},
        ['purple backpack'] = {cost = 500, id = 2001},
        ['grey backpack'] = {cost = 500, id = 2003},
        ['blue backpack'] = {cost = 500, id = 2002},
        ['gold backpack'] = {cost = 500, id = 2004},
        ['rope'] = {cost = 500, id = 2120},
        ['shovel'] = {cost = 500, id = 2554},
        ['machete'] = {cost...
Lua:
local config = {
    items = {
        ['brown backpack'] = {cost = 500, id = 1988},
        ['backpack'] = {cost = 500, id = 1988},
        ['bp'] = {cost = 500, id = 1988},
        ['green backpack'] = {cost = 500, id = 1998},
        ['yellow backpack'] = {cost = 500, id = 1999},
        ['red backpack'] = {cost = 500, id = 2000},
        ['purple backpack'] = {cost = 500, id = 2001},
        ['grey backpack'] = {cost = 500, id = 2003},
        ['blue backpack'] = {cost = 500, id = 2002},
        ['gold backpack'] = {cost = 500, id = 2004},
        ['rope'] = {cost = 500, id = 2120},
        ['shovel'] = {cost = 500, id = 2554},
        ['machete'] = {cost = 500, id = 2420},
        ['aol'] = {cost = 100000, id = 2173}
    }
}

local shop = TalkAction("/buy", "!buy")

function shop.onSay(cid, words, param, channel)
    local player = Player(cid)
   
    if words == "" or param == "" then
        return false
    end

    if param == 'list' then
        local str = ""
        for name, options in pairs(config.items) do
            str = str .. "\n- " .. name .. " (" .. options.cost .. "gp)"
        end
        player:showTextDialog(1950, "List of items available for purchase:" .. str)
        return true
    end

    local item = config.items[param]
    if item ~= nil then
        if not player:removeTotalMoney(item.cost) then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have enough money to buy " .. param .. ".\n(" .. item.cost .. "gp)")
            return true
        end

        player:addItem(item.id, 1)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You bought " .. param .. " for " .. item.cost .. "gp.")
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "The item '" .. param .. "' was not found. Use '!buy list' to see the list of available items.")
    end

    return true
end

shop:separator(" ")
shop:register()
 
Last edited:
Lua:
local shop = TalkAction("/buy")

function shop.onSay(cid, words, param, channel)
    local player = Player(cid)
   
    if words == "" or param == "" then
        return false
    end

    local config = {
        items = {
            ['brown backpack'] = {cost = 500, id = 1988},
            ['backpack'] = {cost = 500, id = 1988},
            ['bp'] = {cost = 500, id = 1988},
            ['green backpack'] = {cost = 500, id = 1998},
            ['yellow backpack'] = {cost = 500, id = 1999},
            ['red backpack'] = {cost = 500, id = 2000},
            ['purple backpack'] = {cost = 500, id = 2001},
            ['grey backpack'] = {cost = 500, id = 2003},
            ['blue backpack'] = {cost = 500, id = 2002},
            ['gold backpack'] = {cost = 500, id = 2004},
            ['rope'] = {cost = 500, id = 2120},
            ['shovel'] = {cost = 500, id = 2554},
            ['machete'] = {cost = 500, id = 2420},
            ['aol'] = {cost = 100000, id = 2173}
        }
    }

    if param == 'list' then
        local str = ""
        for name, options in pairs(config.items) do
            str = str .. "\n- " .. name .. " (" .. options.cost .. "gp)"
        end
        player:showTextDialog(1950, "List of items available for purchase:" .. str)
        return true
    end

    local item = config.items[param]
    if item ~= nil then
        if not player:removeTotalMoney(item.cost) then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have enough money to buy " .. param .. ".\n(" .. item.cost .. "gp)")
            return true
        end

        player:addItem(item.id, 1)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You bought " .. param .. " for " .. item.cost .. "gp.")
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "The item '" .. param .. "' was not found. Use '!buy list' to see the list of available items.")
    end

    return true
end

shop:separator(" ")
shop:register()
working thanks!
 
Everything would work as is thanks to compat.lua, here you are:
Lua:
local config = {
    items = {
        ['brown backpack'] = {cost = 500, id = 1988},
        ['backpack'] = {cost = 500, id = 1988},
        ['bp'] = {cost = 500, id = 1988},
        ['green backpack'] = {cost = 500, id = 1998},
        ['yellow backpack'] = {cost = 500, id = 1999},
        ['red backpack'] = {cost = 500, id = 2000},
        ['purple backpack'] = {cost = 500, id = 2001},
        ['grey backpack'] = {cost = 500, id = 2003},
        ['blue backpack'] = {cost = 500, id = 2002},
        ['gold backpack'] = {cost = 500, id = 2004},
        ['rope'] = {cost = 500, id = 2120},
        ['shovel'] = {cost = 500, id = 2554},
        ['machete'] = {cost = 500, id = 2420},
        ['aol'] = {cost = 100000, id = 2173}
    }
}

local talk = TalkAction("/buy", "!buy")

function talk.onSay(player, words, param)
    if #param < 1 then
        local str = ""
        for name, _ in pairs(config.items) do
            str = str .. "\n" .. name
        end

        player:showTextDialog(1950, "/buy or !buy:\n" .. str)
        return true
    end

    local itemName = param:trim():lower()
    local item = config.items[itemName]
    if not item then
        player:sendCancelMessage("Item not found. Use '!buy' to see the list.")
        return true
    end

    if not player:removeMoney(item.cost) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Not enough money to buy " .. itemName .. ".\n(" .. item.cost .. "gp)")
        return true
    end

    local amount = item.amount and item.amount or 1
    player:addItem(item.id, amount)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)

    return true
end

talk:separator(" ")
talk:register()

EDIT: Didn't notice earlier reply, must've happen while I've been cleaning up the code
 
Solution
Everything would work as is thanks to compat.lua, here you are:
Lua:
local config = {
    items = {
        ['brown backpack'] = {cost = 500, id = 1988},
        ['backpack'] = {cost = 500, id = 1988},
        ['bp'] = {cost = 500, id = 1988},
        ['green backpack'] = {cost = 500, id = 1998},
        ['yellow backpack'] = {cost = 500, id = 1999},
        ['red backpack'] = {cost = 500, id = 2000},
        ['purple backpack'] = {cost = 500, id = 2001},
        ['grey backpack'] = {cost = 500, id = 2003},
        ['blue backpack'] = {cost = 500, id = 2002},
        ['gold backpack'] = {cost = 500, id = 2004},
        ['rope'] = {cost = 500, id = 2120},
        ['shovel'] = {cost = 500, id = 2554},
        ['machete'] = {cost = 500, id = 2420},
        ['aol'] = {cost = 100000, id = 2173}
    }
}

local talk = TalkAction("/buy", "!buy")

function talk.onSay(player, words, param)
    if #param < 1 then
        local str = ""
        for name, _ in pairs(config.items) do
            str = str .. "\n" .. name
        end

        player:showTextDialog(1950, "/buy or !buy:\n" .. str)
        return true
    end

    local itemName = param:trim():lower()
    local item = config.items[itemName]
    if not item then
        player:sendCancelMessage("Item not found. Use '!buy' to see the list.")
        return true
    end

    if not player:removeMoney(item.cost) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Not enough money to buy " .. itemName .. ".\n(" .. item.cost .. "gp)")
        return true
    end

    local amount = item.amount and item.amount or 1
    player:addItem(item.id, amount)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)

    return true
end

talk:separator(" ")
talk:register()

EDIT: Didn't notice earlier reply, must've happen while I've been cleaning up the code
I added data/scripts/talkactions

But it didn't work
 
I added data/scripts/talkactions

But it didn't work
It's not like TFS 1.x supports 0.4 mods. What I meant by that was the main talkaction' code would work but not the mods syntax.
All you had to do was to set config and copy the talkaction' main code and adopt it to new boilerplate.
So it's mainly to take the "sauce" and put into new syntax.
 
Não é como se o TFS 1.x suporta mods 0,4. O que eu quis dizer com isso foi que o código principal do talkaction funcionava, mas não a sintaxe dos mods.
Tudo o que você precisava fazer era definir a configuração e copiar o código principal do talkaction e adotá-lo para o novo padrão.
Então é principalmente pegar o "molho" e colocar na nova sintaxe.
script worked correctly, thanks!
 
Back
Top