Shoorkill
Member
- Joined
- Dec 17, 2018
- Messages
- 126
- Reaction score
- 21
Good, my dears! I made some unsuccessful attempts, I would like the store to deliver the items sold inside a backpack added by the store itself, the shop adds the backpack, but the items come outside of it!, can anyone help me with this?
Lua:
function processBuy(player, data)
local categoryId = tonumber(data["category"])
local offerId = tonumber(data["offer"])
local offer = SHOP_CATEGORIES[categoryId]['offers'][offerId]
local callback = SHOP_CALLBACKS[categoryId][offerId]
if not offer or not callback or data["title"] ~= offer["title"] or data["cost"] ~= offer["cost"] then
sendJSON(player, "categories", SHOP_CATEGORIES) -- refresh categories, maybe invalid
return sendMessage(player, "Error!", "Invalid offer")
end
local points = getPoints(player)
if not offer['cost'] or offer['cost'] > points or points < 1 then
return sendMessage(player, "Error!", "You don't have enough points to buy " .. offer['title'] .."!", true)
end
-- Criar uma mochila para itens comuns
local backpack = nil
if offer['type'] == 'item' then -- Check if it is a common item
backpack = player:addItem(1988) -- Replace 1988 with backpack ID
if backpack then
backpack:setAttribute(ITEM_ATTRIBUTE_NAME, "Store Purchase")
end
end
-- Call the callback to process the purchase
local status = callback(player, offer, backpack)
if status == true then
db.query("UPDATE `accounts` set `points` = `points` - " .. offer['cost'] .. " WHERE `id` = " .. player:getAccountId())
db.asyncQuery("INSERT INTO `shop_history` (`account`, `player`, `date`, `title`, `cost`, `details`) VALUES ('" .. player:getAccountId() .. "', '" .. player:getGuid() .. "', NOW(), " .. db.escapeString(offer['title']) .. ", " .. db.escapeString(offer['cost']) .. ", " .. db.escapeString(json.encode(offer)) .. ")")
return sendMessage(player, "Success!", "You bought " .. offer['title'] .."!", true)
end
if status == nil or status == false then
status = "Unknown error while buying " .. offer['title']
end
sendMessage(player, "Error!", status)
end