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

owner of the item purchased in the game shop

2057623

Member
Joined
Jan 16, 2012
Messages
97
Reaction score
12
Good afternoon, I have a shop code inside otcv8, it is working everything I wanted, put that system that is in several gesio shops that has the name of the person who bought it in the item description, and only whoever bought the item can use it, If the item is dropped or lost, no one can use it, only the owner of the item.

my code
-- BETA VERSION, net tested yet
-- Instruction:
-- creaturescripts.xml <event type="extendedopcode" name="Shop" script="shop.lua" />
-- and in login.lua player:registerEvent("Shop")
-- create sql table shop_history
-- set variables
-- set up function init(), add there items and categories, follow examples
-- set up callbacks at the bottom to add player item/outfit/whatever you want

local SHOP_EXTENDED_OPCODE = 201
local SHOP_OFFERS = {}
local SHOP_CALLBACKS = {}
local SHOP_CATEGORIES = nil
local SHOP_BUY_URL = "http://mitserver.servegame.com/buypoints.php" -- can be empty
local SHOP_AD = { -- can be nil
image = "https://uploaddeimagens.com.br/images/004/582/968/original/MIT_Server.png?1692633354",
url = "mitserver.servegame.com",
text = ""
}
local MAX_PACKET_SIZE = 500

function init()
-- print(json.encode(g_game.getLocalPlayer():getOutfit())) -- in console in otclient, will print current outfit and mount

SHOP_CATEGORIES = {}

local category1 = addCategory({
type="item",
item=ItemType(24774):getClientId(),
count=100,
name="Items"
})

local category2 = addCategory({
type="outfit",
name="Outfits e Mount",
outfit={
mount=0,
feet=114,
legs=114,
body=116,
type=143,
auxType=0,
addons=3,
head=2,
rotating=true
}
})


local category3 = addCategory({
type="item",
item=ItemType(26475):getClientId(),
count=100,
name="Set Knight"
})

local category4 = addCategory({
type="item",
item=ItemType(26463):getClientId(),
count=100,
name="Set Palla"
})

local category5 = addCategory({
type="item",
item=ItemType(26483):getClientId(),
count=100,
name="Set Druid e Sorc"
})

local category6 = addCategory({
type="item",
item=ItemType(27082):getClientId(),
count=100,
name="Exercise Treiner"
})

local category7 = addCategory({
type="item",
item=ItemType(18423):getClientId(),
count=100,
name="Extras"
})

local category8 = addCategory({
type="item",
item=ItemType(26781):getClientId(),
count=100,
name="Itens House"
})


category1.addItem(50, 16101, 1, "Premium Scroll", "Receba 30 Dias de Premium.")
category1.addItem(80, 26744, 1, "Mit Magic loot", "Use nos itens para vender sem ir ao npc. Sobretaxa extra 15% ao npc.")
category1.addItem(15, 15515, 15, "Barra de ouro", "Uma barra de ouro e igual 1kk.")
category1.addItem(90, 15515, 100, "Barra de ouro", "Uma barra de ouro e igual 1kk.")
category1.addItem(60, 20129, 1, "Skull Remover", "Redefine os frags e remove o cranio.")
category1.addItem(20, 8978, 1, "Chave Vip Free 1", "Receba 30 Dias de VIP FREE 1.")
category1.addItem(10, 26333, 15, "15Un -Surprise Box", "Uma caixa misteriosa, pode da itens Raro e donates.")
category1.addItem(15, 26333, 28, "28Un -Surprise Box", "Uma caixa misteriosa, pode da itens Raro e donates.")
category1.addItem(20, 26333, 53, "53Un -Surprise Box", "Uma caixa misteriosa, pode da itens Raro e donates.")
category1.addItem(15, 24841, 50, "50Un -Teleport Pear", "Use para ser teleportado para o Templo.")
category1.addItem(8, 26626, 5, "5Un -Double Exp", "Double EXP por 24hrs.")
category1.addItem(25, 26626, 20, "20Un -Double Exp", "Double EXP por 24hrs.")
category1.addItem(35, 26626, 50, "50Un -Double Exp", "Double EXP por 24hrs.")
category1.addItem(20, 18426, 50, "50Un -Teleport House", "Use para ser teleportado na porta da sua House.")
category1.addItem(8, 21403, 1, "Restore Staminia Full", "description of cristal coin.")
category1.addItem(67, 21403, 10, "10Un -Restore Staminia Full", "description of cristal coin.")


category2.addItem(50, 9693, 1, "Addon Doll", "Use o item, e escolha o Addon que deseja.\nEsse item funciona para todos os Addons.")
category2.addItem(50, 18511, 1, "Mount Doll Box", "Use o item em si mesmo, e escolha a montaria que deseja.\nEsse item funciona para todas as montarias.")

category3.addItem(16, 26468, 1, "Ceifadora Sombria Helmet", "")
category3.addItem(16, 26470, 1, "Ceifadora Sombria Armor", "")
category3.addItem(16, 26471, 1, "Ceifadora Sombria Legs", "")
category3.addItem(16, 26472, 1, "Ceifadora Sombria Boots", "")
category3.addItem(16, 26473, 1, "Ceifadora Sombria Shield", "")
category3.addItem(26, 26475, 1, "Ceifadora Sombria Sword", "")
category3.addItem(26, 26477, 1, "Ceifadora Sombria Axe", "")
category3.addItem(26, 26478, 1, "Ceifadora Sombria Club", "")
category3.addItem(25, 26530, 1, "Ceifadora Sombria Backpack", "")
category3.addItem(35, 18402, 1, "Ceifadora Sombria Colar", "")

category4.addItem(16, 26414, 1, "Radiante da Virtude Helmet", "")
category4.addItem(16, 26415, 1, "Radiante da Virtude Armor", "")
category4.addItem(16, 26416, 1, "Radiante da Virtude Legs", "")
category4.addItem(16, 26417, 1, "Radiante da Virtude Boots", "")
category4.addItem(20, 26486, 1, "Radiante da Virtude Shield", "")
category4.addItem(30, 26463, 1, "Radiante da Virtude Bow", "")
category4.addItem(8, 18304, 1, "Radiante da Virtude Arrow", "")
category4.addItem(25, 26533, 1, "Radiante da Virtude Backpack", "")
category4.addItem(35, 10220, 1, "Radiante da Virtude Colar", "")

category5.addItem(16, 26422, 1, "Arcanum Celeste Helmet", "")
category5.addItem(16, 26423, 1, "Arcanum Celeste Armor", "")
category5.addItem(16, 26424, 1, "Arcanum Celeste Legs", "")
category5.addItem(16, 26425, 1, "Arcanum Celeste Boots", "")
category5.addItem(18, 26499, 1, "Arcanum Celeste Spellbook", "")
category5.addItem(26, 26483, 1, "Arcanum Celeste Rod", "")
category5.addItem(25, 26531, 1, "Arcanum Celeste Backpack", "")
category5.addItem(35, 18407, 1, "Arcanum Celeste Colar", "")


category6.addItem(8, 27072, 1, "Exercise Sword (Somente Knight)", "2000 Cargas")
category6.addItem(8, 27073, 1, "Exercise Axe (Somente Knight)", "2000 Cargas")
category6.addItem(8, 27074, 1, "Exercise Club (Somente Knight)", "2000 Cargas")
category6.addItem(8, 27076, 1, "Exercise Rod (Somente Druid) ", "2000 Cargas")
category6.addItem(8, 27077, 1, "Exercise Wand (Somente Sorc) ", "2000 Cargas")
category6.addItem(8, 27075, 1, "Exercise Bow (Somente Palla)", "2000 Cargas")


category6.addItem(50, 27078, 1, "Exercise Sword (Somente Knight)", "15000 Cargas")
category6.addItem(50, 27079, 1, "Exercise Axe (Somente Knight)", "15000 Cargas")
category6.addItem(50, 27080, 1, "Exercise Club (Somente Knight)", "15000 Cargas")
category6.addItem(50, 27082, 1, "Exercise Rod (Somente Druid) ", "15000 Cargas")
category6.addItem(50, 27083, 1, "Exercise Wand (Somente Sorc) ", "15000 Cargas")
category6.addItem(50, 27081, 1, "Exercise Bow (Somente Palla)", "15000 Cargas")

category7.addItem(1, 18423, 1, "Mit Token", "")
category7.addItem(10, 18423, 10, "Mit Token", "")
category7.addItem(20, 18423, 22, "Mit Token", "")
category7.addItem(50, 18423, 55, "Mit Token", "5 Mit Token Bonus")
category7.addItem(100, 18423, 135, "Mit Token", "35 Mit Token Bonus")
category7.addItem(250, 18423, 350, "Mit Token", "100 Mit Token Bonus")


category8.addItem(3, 26787, 1, "Retching Doll", "")
category8.addItem(3, 26786, 1, "Ogre Rowdy Doll", "")
category8.addItem(3, 26785, 1, "Vexclaw Doll", "")
category8.addItem(3, 26781, 1, "Demon Doll", "")
category8.addItem(2, 27036, 1, "Tigre Trophy", "")
category8.addItem(2, 27037, 1, "Jacare Trophy", "")
category8.addItem(2, 27038, 1, "Pantera Negra Trophy", "")
category8.addItem(2, 26803, 1, "Bladespark Figurine", "")
category8.addItem(2, 26802, 1, "Mossmasher Figurine", "")
category8.addItem(2, 26801, 1, "Sandscourge Figurine", "")
category8.addItem(2, 26800, 1, "Snowbash Figurine", "")
category8.addItem(1, 26805, 5, "Folded Lilac Carpet", "Kit 5 UN")
category8.addItem(1, 26807, 5, "Folded Colourful Pom-Pom Carpet", "Kit 5 UN")
category8.addItem(1, 26809, 5, "Folded Natural Pom-Pom Carpet", "Kit 5 UN")
category8.addItem(1, 26811, 5, "Folded Owin Rug", "Kit 5 UN")
category8.addItem(1, 26813, 5, "Folded Midnight Panther Rug", "Kit 5 UN")
category8.addItem(1, 26815, 5, "Folded Romantic Carpet", "Kit 5 UN")
category8.addItem(1, 26819, 5, "Folded Grass", "Kit 5 UN")
category8.addItem(1, 26822, 5, "Folded Dragon Lord Carpet", "Kit 5 UN")
category8.addItem(1, 26825, 5, "Folded Dragon Carpet", "Kit 5 UN")
category8.addItem(1, 26826, 5, "Folded Elemental Carpet", "Kit 5 UN")
category8.addItem(1, 26828, 5, "Folded Morgaroth Carpet", "Kit 5 UN")
category8.addItem(1, 26830, 5, "Folded Ghazbaran Carpet", "Kit 5 UN")
category8.addItem(1, 26832, 5, "Folded Orshabaal Carpet", "Kit 5 UN")


end

function addCategory(data)
data['offers'] = {}
table.insert(SHOP_CATEGORIES, data)
table.insert(SHOP_CALLBACKS, {})
local index = #SHOP_CATEGORIES
return {

addItem = function(cost, itemId, count, title, description, callback)
if not callback then
callback = defaultItemBuyAction
end
table.insert(SHOP_CATEGORIES[index]['offers'], {
cost=cost,
type="item",
item=ItemType(itemId):getClientId(), -- displayed
itemId=itemId,
count=count,
title=title,
description=description
})
table.insert(SHOP_CALLBACKS[index], callback)
end,

addOutfit = function(cost, outfit, title, description, callback)
if not callback then
callback = defaultOutfitBuyAction
end
table.insert(SHOP_CATEGORIES[index]['offers'], {
cost=cost,
type="outfit",
outfit=outfit,
title=title,
description=description
})
table.insert(SHOP_CALLBACKS[index], callback)
end,

addImage = function(cost, image, title, description, callback)
if not callback then
callback = defaultImageBuyAction
end
table.insert(SHOP_CATEGORIES[index]['offers'], {
cost=cost,
type="image",
image=image,
title=title,
description=description
})
table.insert(SHOP_CALLBACKS[index], callback)
end
}
end

function getPoints(player)
local points = 0
local resultId = db.storeQuery("SELECT points FROM znote_accounts WHERE id = " .. player:getAccountId())
if resultId ~= false then
points = result.getDataInt(resultId, "points")
result.free(resultId)
end
return points
end

function getStatus(player)
local status = {
ad = SHOP_AD,
points = getPoints(player),
buyUrl = SHOP_BUY_URL
}
return status
end

function sendJSON(player, action, data, forceStatus)
local status = nil
if not player:getStorageValue(1150001) or player:getStorageValue(1150001) + 10 < os.time() or forceStatus then
status = getStatus(player)
end
player:setStorageValue(1150001, os.time())


local buffer = json.encode({action = action, data = data, status = status})
local s = {}
for i=1, #buffer, MAX_PACKET_SIZE do
s[#s+1] = buffer:sub(i,i+MAX_PACKET_SIZE - 1)
end
local msg = NetworkMessage()
if #s == 1 then
msg:addByte(50)
msg:addByte(SHOP_EXTENDED_OPCODE)
msg:addString(s[1])
msg:sendToPlayer(player)
return
end
-- split message if too big
msg:addByte(50)
msg:addByte(SHOP_EXTENDED_OPCODE)
msg:addString("S" .. s[1])
msg:sendToPlayer(player)
for i=2,#s - 1 do
msg = NetworkMessage()
msg:addByte(50)
msg:addByte(SHOP_EXTENDED_OPCODE)
msg:addString("P" .. s)
msg:sendToPlayer(player)
end
msg = NetworkMessage()
msg:addByte(50)
msg:addByte(SHOP_EXTENDED_OPCODE)
msg:addString("E" .. s[#s])
msg:sendToPlayer(player)
end

function sendMessage(player, title, msg, forceStatus)
sendJSON(player, "message", {title=title, msg=msg}, forceStatus)
end

function onExtendedOpcode(player, opcode, buffer)
if opcode ~= SHOP_EXTENDED_OPCODE then
return false
end
local status, json_data = pcall(function() return json.decode(buffer) end)
if not status then
return false
end

local action = json_data['action']
local data = json_data['data']
if not action or not data then
return false
end

if SHOP_CATEGORIES == nil then
init()
end

if action == 'init' then
sendJSON(player, "categories", SHOP_CATEGORIES)
elseif action == 'buy' then
processBuy(player, data)
elseif action == "history" then
sendHistory(player)
end
return true
end

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!", "Voce nao tem pontos suficientes para comprar " .. offer['title'] .."!", true)
end
local status = callback(player, offer)
if status == true then
db.query("UPDATE znote_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, "Sucesso!", "Voce comprou " .. offer['title'] .."!. Muito Obrigado.", true)
end
if status == nil or status == false then
status = "Erro desconhecido ao comprar " .. offer['title']
end
sendMessage(player, "Error!", status)
end

function sendHistory(player)
if player:getStorageValue(1150002) and player:getStorageValue(1150002) + 10 > os.time() then
return -- min 10s delay
end
player:setStorageValue(1150002, os.time())

local history = {}
local resultId = db.storeQuery("SELECT * FROM shop_history WHERE account = " .. player:getAccountId() .. " order by id DESC")

if resultId ~= false then
repeat
local details = result.getDataString(resultId, "details")
local status, json_data = pcall(function() return json.decode(details) end)
if not status then
json_data = {
type = "image",
title = result.getDataString(resultId, "title"),
cost = result.getDataInt(resultId, "cost")
}
end
table.insert(history, json_data)
history[#history]["Descricao"] = "Comprado em " .. result.getDataString(resultId, "date") .. " Por " .. result.getDataInt(resultId, "cost") .. " points."
until not result.next(resultId)
result.free(resultId)
end

sendJSON(player, "history", history)
end

-- BUY CALLBACKS
-- May be useful: print(json.encode(offer))

function defaultItemBuyAction(player, offer)
-- todo: check if has capacity
if player:addItem(offer["itemId"], offer["count"], false) then
return true
end
return "Nao e possivel adicionar o item! Voce tem espaço suficiente?"
end

function defaultOutfitBuyAction(player, offer)
return "a acao de compra de roupa padrao não foi implementada"
end

function defaultImageBuyAction(player, offer)
return "a ação de compra de imagem padrão não foi implementada"
end

function customImageBuyAction(player, offer)
return "a ação de compra de imagem personalizada não foi implementada. Oferecer: " .. offer['title']
end


If anyone can do it for me from the heart I would appreciate it, I've already tried to change some things but it didn't work, I only managed to make the description of the name of the person who bought it appear.
 
Good afternoon, I have a shop code inside otcv8, it is working everything I wanted, put that system that is in several gesio shops that has the name of the person who bought it in the item description, and only whoever bought the item can use it, If the item is dropped or lost, no one can use it, only the owner of the item.

my code
-- BETA VERSION, net tested yet
-- Instruction:
-- creaturescripts.xml <event type="extendedopcode" name="Shop" script="shop.lua" />
-- and in login.lua player:registerEvent("Shop")
-- create sql table shop_history
-- set variables
-- set up function init(), add there items and categories, follow examples
-- set up callbacks at the bottom to add player item/outfit/whatever you want

local SHOP_EXTENDED_OPCODE = 201
local SHOP_OFFERS = {}
local SHOP_CALLBACKS = {}
local SHOP_CATEGORIES = nil
local SHOP_BUY_URL = "http://mitserver.servegame.com/buypoints.php" -- can be empty
local SHOP_AD = { -- can be nil
image = "https://uploaddeimagens.com.br/images/004/582/968/original/MIT_Server.png?1692633354",
url = "mitserver.servegame.com",
text = ""
}
local MAX_PACKET_SIZE = 500

function init()
-- print(json.encode(g_game.getLocalPlayer():getOutfit())) -- in console in otclient, will print current outfit and mount

SHOP_CATEGORIES = {}

local category1 = addCategory({
type="item",
item=ItemType(24774):getClientId(),
count=100,
name="Items"
})

local category2 = addCategory({
type="outfit",
name="Outfits e Mount",
outfit={
mount=0,
feet=114,
legs=114,
body=116,
type=143,
auxType=0,
addons=3,
head=2,
rotating=true
}
})


local category3 = addCategory({
type="item",
item=ItemType(26475):getClientId(),
count=100,
name="Set Knight"
})

local category4 = addCategory({
type="item",
item=ItemType(26463):getClientId(),
count=100,
name="Set Palla"
})

local category5 = addCategory({
type="item",
item=ItemType(26483):getClientId(),
count=100,
name="Set Druid e Sorc"
})

local category6 = addCategory({
type="item",
item=ItemType(27082):getClientId(),
count=100,
name="Exercise Treiner"
})

local category7 = addCategory({
type="item",
item=ItemType(18423):getClientId(),
count=100,
name="Extras"
})

local category8 = addCategory({
type="item",
item=ItemType(26781):getClientId(),
count=100,
name="Itens House"
})


category1.addItem(50, 16101, 1, "Premium Scroll", "Receba 30 Dias de Premium.")
category1.addItem(80, 26744, 1, "Mit Magic loot", "Use nos itens para vender sem ir ao npc. Sobretaxa extra 15% ao npc.")
category1.addItem(15, 15515, 15, "Barra de ouro", "Uma barra de ouro e igual 1kk.")
category1.addItem(90, 15515, 100, "Barra de ouro", "Uma barra de ouro e igual 1kk.")
category1.addItem(60, 20129, 1, "Skull Remover", "Redefine os frags e remove o cranio.")
category1.addItem(20, 8978, 1, "Chave Vip Free 1", "Receba 30 Dias de VIP FREE 1.")
category1.addItem(10, 26333, 15, "15Un -Surprise Box", "Uma caixa misteriosa, pode da itens Raro e donates.")
category1.addItem(15, 26333, 28, "28Un -Surprise Box", "Uma caixa misteriosa, pode da itens Raro e donates.")
category1.addItem(20, 26333, 53, "53Un -Surprise Box", "Uma caixa misteriosa, pode da itens Raro e donates.")
category1.addItem(15, 24841, 50, "50Un -Teleport Pear", "Use para ser teleportado para o Templo.")
category1.addItem(8, 26626, 5, "5Un -Double Exp", "Double EXP por 24hrs.")
category1.addItem(25, 26626, 20, "20Un -Double Exp", "Double EXP por 24hrs.")
category1.addItem(35, 26626, 50, "50Un -Double Exp", "Double EXP por 24hrs.")
category1.addItem(20, 18426, 50, "50Un -Teleport House", "Use para ser teleportado na porta da sua House.")
category1.addItem(8, 21403, 1, "Restore Staminia Full", "description of cristal coin.")
category1.addItem(67, 21403, 10, "10Un -Restore Staminia Full", "description of cristal coin.")


category2.addItem(50, 9693, 1, "Addon Doll", "Use o item, e escolha o Addon que deseja.\nEsse item funciona para todos os Addons.")
category2.addItem(50, 18511, 1, "Mount Doll Box", "Use o item em si mesmo, e escolha a montaria que deseja.\nEsse item funciona para todas as montarias.")

category3.addItem(16, 26468, 1, "Ceifadora Sombria Helmet", "")
category3.addItem(16, 26470, 1, "Ceifadora Sombria Armor", "")
category3.addItem(16, 26471, 1, "Ceifadora Sombria Legs", "")
category3.addItem(16, 26472, 1, "Ceifadora Sombria Boots", "")
category3.addItem(16, 26473, 1, "Ceifadora Sombria Shield", "")
category3.addItem(26, 26475, 1, "Ceifadora Sombria Sword", "")
category3.addItem(26, 26477, 1, "Ceifadora Sombria Axe", "")
category3.addItem(26, 26478, 1, "Ceifadora Sombria Club", "")
category3.addItem(25, 26530, 1, "Ceifadora Sombria Backpack", "")
category3.addItem(35, 18402, 1, "Ceifadora Sombria Colar", "")

category4.addItem(16, 26414, 1, "Radiante da Virtude Helmet", "")
category4.addItem(16, 26415, 1, "Radiante da Virtude Armor", "")
category4.addItem(16, 26416, 1, "Radiante da Virtude Legs", "")
category4.addItem(16, 26417, 1, "Radiante da Virtude Boots", "")
category4.addItem(20, 26486, 1, "Radiante da Virtude Shield", "")
category4.addItem(30, 26463, 1, "Radiante da Virtude Bow", "")
category4.addItem(8, 18304, 1, "Radiante da Virtude Arrow", "")
category4.addItem(25, 26533, 1, "Radiante da Virtude Backpack", "")
category4.addItem(35, 10220, 1, "Radiante da Virtude Colar", "")

category5.addItem(16, 26422, 1, "Arcanum Celeste Helmet", "")
category5.addItem(16, 26423, 1, "Arcanum Celeste Armor", "")
category5.addItem(16, 26424, 1, "Arcanum Celeste Legs", "")
category5.addItem(16, 26425, 1, "Arcanum Celeste Boots", "")
category5.addItem(18, 26499, 1, "Arcanum Celeste Spellbook", "")
category5.addItem(26, 26483, 1, "Arcanum Celeste Rod", "")
category5.addItem(25, 26531, 1, "Arcanum Celeste Backpack", "")
category5.addItem(35, 18407, 1, "Arcanum Celeste Colar", "")


category6.addItem(8, 27072, 1, "Exercise Sword (Somente Knight)", "2000 Cargas")
category6.addItem(8, 27073, 1, "Exercise Axe (Somente Knight)", "2000 Cargas")
category6.addItem(8, 27074, 1, "Exercise Club (Somente Knight)", "2000 Cargas")
category6.addItem(8, 27076, 1, "Exercise Rod (Somente Druid) ", "2000 Cargas")
category6.addItem(8, 27077, 1, "Exercise Wand (Somente Sorc) ", "2000 Cargas")
category6.addItem(8, 27075, 1, "Exercise Bow (Somente Palla)", "2000 Cargas")


category6.addItem(50, 27078, 1, "Exercise Sword (Somente Knight)", "15000 Cargas")
category6.addItem(50, 27079, 1, "Exercise Axe (Somente Knight)", "15000 Cargas")
category6.addItem(50, 27080, 1, "Exercise Club (Somente Knight)", "15000 Cargas")
category6.addItem(50, 27082, 1, "Exercise Rod (Somente Druid) ", "15000 Cargas")
category6.addItem(50, 27083, 1, "Exercise Wand (Somente Sorc) ", "15000 Cargas")
category6.addItem(50, 27081, 1, "Exercise Bow (Somente Palla)", "15000 Cargas")

category7.addItem(1, 18423, 1, "Mit Token", "")
category7.addItem(10, 18423, 10, "Mit Token", "")
category7.addItem(20, 18423, 22, "Mit Token", "")
category7.addItem(50, 18423, 55, "Mit Token", "5 Mit Token Bonus")
category7.addItem(100, 18423, 135, "Mit Token", "35 Mit Token Bonus")
category7.addItem(250, 18423, 350, "Mit Token", "100 Mit Token Bonus")


category8.addItem(3, 26787, 1, "Retching Doll", "")
category8.addItem(3, 26786, 1, "Ogre Rowdy Doll", "")
category8.addItem(3, 26785, 1, "Vexclaw Doll", "")
category8.addItem(3, 26781, 1, "Demon Doll", "")
category8.addItem(2, 27036, 1, "Tigre Trophy", "")
category8.addItem(2, 27037, 1, "Jacare Trophy", "")
category8.addItem(2, 27038, 1, "Pantera Negra Trophy", "")
category8.addItem(2, 26803, 1, "Bladespark Figurine", "")
category8.addItem(2, 26802, 1, "Mossmasher Figurine", "")
category8.addItem(2, 26801, 1, "Sandscourge Figurine", "")
category8.addItem(2, 26800, 1, "Snowbash Figurine", "")
category8.addItem(1, 26805, 5, "Folded Lilac Carpet", "Kit 5 UN")
category8.addItem(1, 26807, 5, "Folded Colourful Pom-Pom Carpet", "Kit 5 UN")
category8.addItem(1, 26809, 5, "Folded Natural Pom-Pom Carpet", "Kit 5 UN")
category8.addItem(1, 26811, 5, "Folded Owin Rug", "Kit 5 UN")
category8.addItem(1, 26813, 5, "Folded Midnight Panther Rug", "Kit 5 UN")
category8.addItem(1, 26815, 5, "Folded Romantic Carpet", "Kit 5 UN")
category8.addItem(1, 26819, 5, "Folded Grass", "Kit 5 UN")
category8.addItem(1, 26822, 5, "Folded Dragon Lord Carpet", "Kit 5 UN")
category8.addItem(1, 26825, 5, "Folded Dragon Carpet", "Kit 5 UN")
category8.addItem(1, 26826, 5, "Folded Elemental Carpet", "Kit 5 UN")
category8.addItem(1, 26828, 5, "Folded Morgaroth Carpet", "Kit 5 UN")
category8.addItem(1, 26830, 5, "Folded Ghazbaran Carpet", "Kit 5 UN")
category8.addItem(1, 26832, 5, "Folded Orshabaal Carpet", "Kit 5 UN")


end

function addCategory(data)
data['offers'] = {}
table.insert(SHOP_CATEGORIES, data)
table.insert(SHOP_CALLBACKS, {})
local index = #SHOP_CATEGORIES
return {

addItem = function(cost, itemId, count, title, description, callback)
if not callback then
callback = defaultItemBuyAction
end
table.insert(SHOP_CATEGORIES[index]['offers'], {
cost=cost,
type="item",
item=ItemType(itemId):getClientId(), -- displayed
itemId=itemId,
count=count,
title=title,
description=description
})
table.insert(SHOP_CALLBACKS[index], callback)
end,

addOutfit = function(cost, outfit, title, description, callback)
if not callback then
callback = defaultOutfitBuyAction
end
table.insert(SHOP_CATEGORIES[index]['offers'], {
cost=cost,
type="outfit",
outfit=outfit,
title=title,
description=description
})
table.insert(SHOP_CALLBACKS[index], callback)
end,

addImage = function(cost, image, title, description, callback)
if not callback then
callback = defaultImageBuyAction
end
table.insert(SHOP_CATEGORIES[index]['offers'], {
cost=cost,
type="image",
image=image,
title=title,
description=description
})
table.insert(SHOP_CALLBACKS[index], callback)
end
}
end

function getPoints(player)
local points = 0
local resultId = db.storeQuery("SELECT points FROM znote_accounts WHERE id = " .. player:getAccountId())
if resultId ~= false then
points = result.getDataInt(resultId, "points")
result.free(resultId)
end
return points
end

function getStatus(player)
local status = {
ad = SHOP_AD,
points = getPoints(player),
buyUrl = SHOP_BUY_URL
}
return status
end

function sendJSON(player, action, data, forceStatus)
local status = nil
if not player:getStorageValue(1150001) or player:getStorageValue(1150001) + 10 < os.time() or forceStatus then
status = getStatus(player)
end
player:setStorageValue(1150001, os.time())


local buffer = json.encode({action = action, data = data, status = status})
local s = {}
for i=1, #buffer, MAX_PACKET_SIZE do
s[#s+1] = buffer:sub(i,i+MAX_PACKET_SIZE - 1)
end
local msg = NetworkMessage()
if #s == 1 then
msg:addByte(50)
msg:addByte(SHOP_EXTENDED_OPCODE)
msg:addString(s[1])
msg:sendToPlayer(player)
return
end
-- split message if too big
msg:addByte(50)
msg:addByte(SHOP_EXTENDED_OPCODE)
msg:addString("S" .. s[1])
msg:sendToPlayer(player)
for i=2,#s - 1 do
msg = NetworkMessage()
msg:addByte(50)
msg:addByte(SHOP_EXTENDED_OPCODE)
msg:addString("P" .. s)
msg:sendToPlayer(player)
end
msg = NetworkMessage()
msg:addByte(50)
msg:addByte(SHOP_EXTENDED_OPCODE)
msg:addString("E" .. s[#s])
msg:sendToPlayer(player)
end

function sendMessage(player, title, msg, forceStatus)
sendJSON(player, "message", {title=title, msg=msg}, forceStatus)
end

function onExtendedOpcode(player, opcode, buffer)
if opcode ~= SHOP_EXTENDED_OPCODE then
return false
end
local status, json_data = pcall(function() return json.decode(buffer) end)
if not status then
return false
end

local action = json_data['action']
local data = json_data['data']
if not action or not data then
return false
end

if SHOP_CATEGORIES == nil then
init()
end

if action == 'init' then
sendJSON(player, "categories", SHOP_CATEGORIES)
elseif action == 'buy' then
processBuy(player, data)
elseif action == "history" then
sendHistory(player)
end
return true
end

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!", "Voce nao tem pontos suficientes para comprar " .. offer['title'] .."!", true)
end
local status = callback(player, offer)
if status == true then
db.query("UPDATE znote_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, "Sucesso!", "Voce comprou " .. offer['title'] .."!. Muito Obrigado.", true)
end
if status == nil or status == false then
status = "Erro desconhecido ao comprar " .. offer['title']
end
sendMessage(player, "Error!", status)
end

function sendHistory(player)
if player:getStorageValue(1150002) and player:getStorageValue(1150002) + 10 > os.time() then
return -- min 10s delay
end
player:setStorageValue(1150002, os.time())

local history = {}
local resultId = db.storeQuery("SELECT * FROM shop_history WHERE account = " .. player:getAccountId() .. " order by id DESC")

if resultId ~= false then
repeat
local details = result.getDataString(resultId, "details")
local status, json_data = pcall(function() return json.decode(details) end)
if not status then
json_data = {
type = "image",
title = result.getDataString(resultId, "title"),
cost = result.getDataInt(resultId, "cost")
}
end
table.insert(history, json_data)
history[#history]["Descricao"] = "Comprado em " .. result.getDataString(resultId, "date") .. " Por " .. result.getDataInt(resultId, "cost") .. " points."
until not result.next(resultId)
result.free(resultId)
end

sendJSON(player, "history", history)
end

-- BUY CALLBACKS
-- May be useful: print(json.encode(offer))

function defaultItemBuyAction(player, offer)
-- todo: check if has capacity
if player:addItem(offer["itemId"], offer["count"], false) then
return true
end
return "Nao e possivel adicionar o item! Voce tem espaço suficiente?"
end

function defaultOutfitBuyAction(player, offer)
return "a acao de compra de roupa padrao não foi implementada"
end

function defaultImageBuyAction(player, offer)
return "a ação de compra de imagem padrão não foi implementada"
end

function customImageBuyAction(player, offer)
return "a ação de compra de imagem personalizada não foi implementada. Oferecer: " .. offer['title']
end

If anyone can do it for me from the heart I would appreciate it, I've already tried to change some things but it didn't work, I only managed to make the description of the name of the person who bought it appear.
let me check
 
Back
Top