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

command buy items !talkaction

addewe

New Member
Joined
Jan 14, 2015
Messages
25
Reaction score
2
command buy items !talkaction need spcirt buy shove rope backpack
 
Alright, I wrote this in 1.3 but I don't see why it wouldn't work for 1.2, it has a bonus cost for free accounts.

Save this as itemShop.lua
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

Add this to talkactions.xml
HTML:
<talkaction words="!buy" separator=" " script="itemShop.lua" />

And here is an example of it working, after saying just !buy
Code:
10:30 Please enter a shop item name to buy, prices are listed, free accounts pay 10% more than premium accounts.
10:30 rope: 50gp.
10:30 shovel: 6gp.
10:30 backpack: 22gp.
10:30 pick: 50gp.

This is after saying !buy backpack
Code:
10:31 Thank you for purchasing a backpack!
 
Back
Top