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

Shop by command

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
Hi, i try make shop in command, but i dont know how to check player have items or no, and if have remove it and add item. I have it:

Code:
local mindcontrol = TalkAction("!shop")

function mindcontrol.onSay(player, words, param)

    if param == '' then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'None')
        return true
    elseif param == 'test1' then 
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'test')
        player:addItem(12661,1)
        player:removeItem(2173,1)
        return true
    elseif param == 'test2' then 
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'test')
        player:addItem(12662,1)
        player:removeItem(2173,1)
        return true
    end
end


mindcontrol:separator(" ")
mindcontrol:register()
 
Hi, i try make shop in command, but i dont know how to check player have items or no, and if have remove it and add item. I have it:

Code:
local mindcontrol = TalkAction("!shop")

function mindcontrol.onSay(player, words, param)

    if param == '' then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'None')
        return true
    elseif param == 'test1' then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'test')
        player:addItem(12661,1)
        player:removeItem(2173,1)
        return true
    elseif param == 'test2' then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'test')
        player:addItem(12662,1)
        player:removeItem(2173,1)
        return true
    end
end


mindcontrol:separator(" ")
mindcontrol:register()

Try this. Just add the items to the table.
Lua:
local items = {
    ['demon armor'] = {itemid = 2494, count = 1, payment = "money", payment_id = 0, price = 300000},
    ['mastermind shield'] = {itemid = 2514, count = 1, payment = "item", payment_id = 2520, price = 2}
}

local items_list = {}

for index, value in pairs(items) do
    table.insert(items_list, 'x' .. value.count .. ' ' .. index .. ' : Price ' .. value.price .. ' ' .. (value.payment == "money" and "gps" or ItemType(value.payment_id):getName()))
end

local str = ''

for index, value in ipairs(items_list) do
    str = str .. value .. ((#items_list > 1 and index < #items_list) and '\n' or '')
end

local talkaction = TalkAction('!shop')

function talkaction.onSay(player, words, param)
    if param == '' or param == 'list' then
        player:popupFYI("To buy an item, type the command !shop, followed by the item's name.\n\nItems list:\n\n" .. str)
        return false
    end

    local value = items[param:lower()]
    if not value then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "This item does not exist in the shop list.")
        return false
    end

    if value.payment == "money" then
        if player:getMoney() < value.price then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need " .. value.price .. " gps to buy this item.")
            return false
        end
        player:removeMoney(value.price)
    elseif value.payment == "item" then
        if player:getItemCount(value.payment_id) < value.price then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need " .. value.price .. " " .. ItemType(value.payment_id):getName() .. " to buy this item.")
            return false
        end
        player:removeItem(value.payment_id, value.price)
    end

    player:addItem(value.itemid, value.count)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have bought a " .. ItemType(value.itemid):getName() .. ".")
    return false
end

talkaction:separator(" ")
talkaction:register()
 
Back
Top