Am si eu o problema cu itemshop ingame. Iti poti da MD direct din itemshop.
De exemplu sunt schimba bonus la vanzare si poti alege sa cumperi pana la 200. Daca pun - si un numar de exemplu -19 imi da suma in MD x19 cat costa schimba. Cum ar veni nu zice ca nai MD ci din contra iti da MD.
Presupun ca e din functia asta dar nu stium cum sa il pun. Las questul intreg mai jos si functia care cred eu.
Functia:
Cod: Selectaţi tot
if tonumber(date_[1]) != 0 then -- got an end date
timeLeft = itemshop_v2.currentTimeDiff(date_)
if itemshopItem[1].percent > 0 and timeLeft <= 0 then -- has percent and if the timeleft is <= 0 then set percent = 0
itemshopItem[1].percent = 0
end
end
local amount = tonumber(cmd[3])
if not pc.enough_inventory(itemshopItem[1].vnum) then syschat'No tienes suficiente espacio para hacer una compra.' return end
if amount > 200 then syschat'El numero maximo es 200.' return end
local coins = itemshop.get_coins()
local realPrice = math.floor((itemshopItem[1].price*amount) - (((itemshopItem[1].price*amount) / 100 ) * itemshopItem[1].percent))
if coins < realPrice then syschat'No tienes suficiente MD' return end
local newCoins = coins-realPriceCod: Selectaţi tot
quest itemshop_v2 begin
state start begin
when login begin
cmdchat('ITEMSHOP QID/'..q.getcurrentquestindex())
end
when button begin
local cmd = itemshop_v2.client_command(getinput('ITEMSHOP QUESTCMD'))
if cmd[1] == 'LOAD' and get_time() < pc.getqf("itemshop_open_time") then
syschat("Debes esperar 15 segundos para poder abrir la tienda de nuevo.")
return
end
local count, last_edit_result = mysql_direct_query("SELECT last_edit FROM player.itemshop_last_edit;")
if cmd[1] == 'LOAD' then
pc.setqf("itemshop_open_time", get_time()+15)
cmdchat('ITEMSHOP LOADING/0')
local count, last_edit_result = mysql_direct_query("SELECT last_edit FROM player.itemshop_last_edit;")
local updateTable = string.gsub(last_edit_result[1].last_edit,' ','-')
if cmd[2] != updateTable then
cmdchat('ITEMSHOP CLEAR_ITEMS')
local count, itemshopItems = mysql_direct_query("SELECT * FROM player.itemshop WHERE (end_date > CURRENT_TIMESTAMP) or (end_date < CURRENT_TIMESTAMP and after_run_out = 'BUYABLE') or (end_date = '0000-00-00 00:00:00') ORDER BY id ASC;")
cmdchat('ITEMSHOP LOADING/10')
local categorysCreated = {['ITEMSHOP'] = {}, ['VOTESHOP'] = {}, ['ACHIEVEMENTSHOP'] = {}}
local itemLen = table.getn(itemshopItems)
local mostBoughtCounter = 0
for i = 1, itemLen do
local typeId = ({['ITEMSHOP'] = 0, ['VOTESHOP'] = 1, ['ACHIEVEMENTSHOP'] = 2})[itemshopItems[i].shop]
local runOut = ({['BUYABLE'] = 0, ['NOT BUYABLE'] = 1, })[itemshopItems[i].after_run_out]
local date_ = itemshop_v2.convertToDateTable(itemshopItems[i].end_date)
local endDateSec = 0
local timeLeft = 0
if tonumber(date_[1]) != 0 then -- got an end date
endDateSec = os.time({day=tonumber(date_[3]),month=tonumber(date_[2]),year=tonumber(date_[1]),hour=tonumber(date_[4]),min=tonumber(date_[5]),sec=tonumber(date_[6])})
timeLeft = itemshop_v2.currentTimeDiff(date_)
if itemshopItems[i].percent > 0 and timeLeft <= 0 then -- has percent and if the timeleft is already 0 then set the percent to zero
itemshopItems[i].percent = 0
end
end
if itemshopItems[i].percent > 0 or timeLeft > 0 then -- is a hot offer
cmdchat('ITEMSHOP ADD_ITEM_HOTOFFERS/'..typeId..'/'..itemshopItems[i].id..'/'..itemshopItems[i].vnum..'/'..itemshopItems[i].socket0..','..itemshopItems[i].socket1..','..itemshopItems[i].socket2..'/'..itemshopItems[i].attrtype0..','..itemshopItems[i].attrvalue0..','..itemshopItems[i].attrtype1..','..itemshopItems[i].attrvalue1..','..itemshopItems[i].attrtype2..','..itemshopItems[i].attrvalue2..','..itemshopItems[i].attrtype3..','..itemshopItems[i].attrvalue3..','..itemshopItems[i].attrtype4..','..itemshopItems[i].attrvalue4..','..itemshopItems[i].attrtype5..','..itemshopItems[i].attrvalue5..','..itemshopItems[i].attrtype6..','..itemshopItems[i].attrvalue6..'/'..itemshopItems[i].price..'/'..itemshopItems[i].percent..'/'..endDateSec..'/'..runOut)
end
if typeId == 0 then -- itemshop item
if not itemshop_v2.is_in_table(categorysCreated.ITEMSHOP, itemshopItems[i].category_id) then
cmdchat('ITEMSHOP CREATE_CATEGORY/itemshop/'..itemshopItems[i].category_id)
table.insert(categorysCreated.ITEMSHOP, itemshopItems[i].category_id)
end
cmdchat('ITEMSHOP ADD_ITEM_IS/'..itemshopItems[i].category_id..'/'..typeId..'/'..itemshopItems[i].id..'/'..itemshopItems[i].vnum..'/'..itemshopItems[i].socket0..','..itemshopItems[i].socket1..','..itemshopItems[i].socket2..'/'..itemshopItems[i].attrtype0..','..itemshopItems[i].attrvalue0..','..itemshopItems[i].attrtype1..','..itemshopItems[i].attrvalue1..','..itemshopItems[i].attrtype2..','..itemshopItems[i].attrvalue2..','..itemshopItems[i].attrtype3..','..itemshopItems[i].attrvalue3..','..itemshopItems[i].attrtype4..','..itemshopItems[i].attrvalue4..','..itemshopItems[i].attrtype5..','..itemshopItems[i].attrvalue5..','..itemshopItems[i].attrtype6..','..itemshopItems[i].attrvalue6..'/'..itemshopItems[i].price..'/'..itemshopItems[i].percent..'/'..endDateSec..'/'..runOut)
elseif typeId == 1 then -- voteshop item
if not itemshop_v2.is_in_table(categorysCreated.VOTESHOP, itemshopItems.category_id[i]) then
cmdchat('ITEMSHOP CREATE_CATEGORY/voteshop/'..itemshopItems.category_id[i])
table.insert(categorysCreated.VOTESHOP, itemshopItems.category_id[i])
end
cmdchat('ITEMSHOP ADD_ITEM_VS/'..itemshopItems.category_id[i]..'/'..typeId..'/'..itemshopItems.id[i]..'/'..itemshopItems.vnum[i]..'/'..itemshopItems.socket0[i]..','..itemshopItems.socket1[i]..','..itemshopItems.socket2[i]..'/'..itemshopItems.attrtype0[i]..','..itemshopItems.attrvalue0[i]..','..itemshopItems.attrtype1[i]..','..itemshopItems.attrvalue1[i]..','..itemshopItems.attrtype2[i]..','..itemshopItems.attrvalue2[i]..','..itemshopItems.attrtype3[i]..','..itemshopItems.attrvalue3[i]..','..itemshopItems.attrtype4[i]..','..itemshopItems.attrvalue4[i]..','..itemshopItems.attrtype5[i]..','..itemshopItems.attrvalue5[i]..','..itemshopItems.attrtype6[i]..','..itemshopItems.attrvalue6[i]..'/'..itemshopItems.price[i]..'/'..itemshopItems.percent[i]..'/'..endDateSec..'/'..runOut)
elseif typeId == 2 then -- achievementshop item
if not itemshop_v2.is_in_table(categorysCreated.ACHIEVEMENTSHOP, itemshopItems.category_id[i]) then
cmdchat('ITEMSHOP CREATE_CATEGORY/achievementshop/'..itemshopItems.category_id[i])
table.insert(categorysCreated.ACHIEVEMENTSHOP, itemshopItems.category_id[i])
end
-- chat('ITEMSHOP ADD_ITEM_AS/'..itemshopItems.category_id[i]..'/'..typeId..'/'..itemshopItems.id[i]..'/'..itemshopItems.vnum[i]..'/'..itemshopItems.socket0[i]..','..itemshopItems.socket1[i]..','..itemshopItems.socket2[i]..'/'..itemshopItems.attrtype0[i]..','..itemshopItems.attrvalue0[i]..','..itemshopItems.attrtype1[i]..','..itemshopItems.attrvalue1[i]..','..itemshopItems.attrtype2[i]..','..itemshopItems.attrvalue2[i]..','..itemshopItems.attrtype3[i]..','..itemshopItems.attrvalue3[i]..','..itemshopItems.attrtype4[i]..','..itemshopItems.attrvalue4[i]..','..itemshopItems.attrtype5[i]..','..itemshopItems.attrvalue5[i]..','..itemshopItems.attrtype6[i]..','..itemshopItems.attrvalue6[i]..'/'..itemshopItems.price[i]..'/'..itemshopItems.percent[i]..'/'..endDateSec..'/'..runOut)
cmdchat('ITEMSHOP ADD_ITEM_AS/'..itemshopItems.category_id[i]..'/'..typeId..'/'..itemshopItems.id[i]..'/'..itemshopItems.vnum[i]..'/'..itemshopItems.socket0[i]..','..itemshopItems.socket1[i]..','..itemshopItems.socket2[i]..'/'..itemshopItems.attrtype0[i]..','..itemshopItems.attrvalue0[i]..','..itemshopItems.attrtype1[i]..','..itemshopItems.attrvalue1[i]..','..itemshopItems.attrtype2[i]..','..itemshopItems.attrvalue2[i]..','..itemshopItems.attrtype3[i]..','..itemshopItems.attrvalue3[i]..','..itemshopItems.attrtype4[i]..','..itemshopItems.attrvalue4[i]..','..itemshopItems.attrtype5[i]..','..itemshopItems.attrvalue5[i]..','..itemshopItems.attrtype6[i]..','..itemshopItems.attrvalue6[i]..'/'..itemshopItems.price[i]..'/'..itemshopItems.percent[i]..'/'..endDateSec..'/'..runOut)
end
if itemshopItems[i].bought > 0 then -- is a mostbought item
if mostBoughtCounter <= 20 then
cmdchat('ITEMSHOP ADD_ITEM_MOSTBOUGHT/'..typeId..'/'..itemshopItems[i].id..'/'..itemshopItems[i].vnum..'/'..itemshopItems[i].socket0..','..itemshopItems[i].socket1..','..itemshopItems[i].socket2..'/'..itemshopItems[i].attrtype0..','..itemshopItems[i].attrvalue0..','..itemshopItems[i].attrtype1..','..itemshopItems[i].attrvalue1..','..itemshopItems[i].attrtype2..','..itemshopItems[i].attrvalue2..','..itemshopItems[i].attrtype3..','..itemshopItems[i].attrvalue3..','..itemshopItems[i].attrtype4..','..itemshopItems[i].attrvalue4..','..itemshopItems[i].attrtype5..','..itemshopItems[i].attrvalue5..','..itemshopItems[i].attrtype6..','..itemshopItems[i].attrvalue6..'/'..itemshopItems[i].price..'/'..itemshopItems[i].percent..'/'..endDateSec..'/'..runOut)
mostBoughtCounter = mostBoughtCounter + 1
end
end
cmdchat('ITEMSHOP LOADING/'..math.floor((i/itemLen)*100-10))
end
cmdchat('ITEMSHOP UPDATETABLE_SET/'..updateTable)
end
cmdchat('ITEMSHOP LOADING/90')
local count, acc = mysql_direct_query("Select coins from account.account where id ="..pc.get_account_id()..";")
local count, banner = mysql_direct_query("Select * from player.itemshop_banner;")
cmdchat('ITEMSHOP LOADING/100')
cmdchat('ITEMSHOP OPEN/'..acc[1].coins..'/'..banner[1].banner_0..'/'..banner[1].banner_1)
elseif cmd[1] == 'BUY' then
if get_time() < pc.getqf("itemshop_buy_time") then
syschat("Debe esperar 15 segundos entre hacer compras.")
return
end
if cmd[1] == 0 or cmd[1] == nil or string.find(cmd[1], "nan") or string.find(cmd[1], "NaN") or string.find(cmd[1], "naN") or string.find(cmd[1], "nAN") or string.find(cmd[1], "NAN") or string.find(cmd[1], "Nan") or string.find(cmd[1], "NAn") or string.find(cmd[1], "nAn") then
syschat'Este articulo no existe.'
return
end
local itemshopItem = {}
local count, itemshopItem = mysql_direct_query("SELECT * FROM player.itemshop WHERE ((end_date > CURRENT_TIMESTAMP) or (end_date < CURRENT_TIMESTAMP and after_run_out = 'BUYABLE') or (end_date = '0000-00-00 00:00:00')) and id = "..tonumber(cmd[2])..";")
if table.getn(itemshopItem) == 0 then
syschat'Este articulo no existe.'
return
end
local curItem = {}
local count, curItem = mysql_direct_query('SELECT limittype0, flag FROM player.item_proto where vnum = '..itemshopItem[1].vnum)
if table.getn(curItem) == 0 then
--syschat'Fehler bitte einem GM melden. [error 005]'
return
end
local typeId = ({['ITEMSHOP'] = 0, ['ACHIEVEMENTSHOP'] = 1, })[itemshopItem[1].shop]
local date_ = itemshop_v2.convertToDateTable(itemshopItem[1].end_date)
local timeLeft = 0
if tonumber(date_[1]) != 0 then -- got an end date
timeLeft = itemshop_v2.currentTimeDiff(date_)
if itemshopItem[1].percent > 0 and timeLeft <= 0 then -- has percent and if the timeleft is <= 0 then set percent = 0
itemshopItem[1].percent = 0
end
end
local amount = tonumber(cmd[3])
if not pc.enough_inventory(itemshopItem[1].vnum) then syschat'No tienes suficiente espacio para hacer una compra.' return end
if amount > 200 then syschat'El numero maximo es 200.' return end
local coins = itemshop.get_coins()
local realPrice = math.floor((itemshopItem[1].price*amount) - (((itemshopItem[1].price*amount) / 100 ) * itemshopItem[1].percent))
if coins < realPrice then syschat'No tienes suficiente MD' return end
local newCoins = coins-realPrice
if typeId == 0 then
itemshop.set_coins(newCoins)
itemshop.log_buy(realPrice, itemshopItem[1].vnum, amount)
cmdchat('ITEMSHOP SET_IS_COINS/'..newCoins)
elseif typeId == 1 then
itemshop.set_votecoins(newCoins)
cmdchat('ITEMSHOP SET_VS_COINS/'..newCoins)
elseif typeId == 2 then
cmdchat('ITEMSHOP SET_AS_COINS/'..newCoins)
end
-- mostbought + 1
mysql_direct_query("Update player.itemshop SET bought = bought + "..amount.." where id = "..tonumber(cmd[2]).." ;")
pc.give_item2_select(itemshopItem[1].vnum,amount)
if curItem[1].limittype0 == 7 then -- realtime item?
item.set_socket(0,itemshopItem[1].socket0+os.time())
else
item.set_socket(0,itemshopItem[1].socket0)
end
item.set_socket(1,itemshopItem[1].socket1)
item.set_socket(2,itemshopItem[1].socket2)
item.set_value(0,itemshopItem[1].attrtype0,itemshopItem[1].attrvalue0)
item.set_value(1,itemshopItem[1].attrtype1,itemshopItem[1].attrvalue1)
item.set_value(2,itemshopItem[1].attrtype2,itemshopItem[1].attrvalue2)
item.set_value(3,itemshopItem[1].attrtype3,itemshopItem[1].attrvalue3)
item.set_value(4,itemshopItem[1].attrtype4,itemshopItem[1].attrvalue4)
item.set_value(5,itemshopItem[1].attrtype5,itemshopItem[1].attrvalue5)
item.set_value(6,itemshopItem[1].attrtype6,itemshopItem[1].attrvalue6)
syschat("El articulo ha sido agregado al inventario.")
pc.setqf("itemshop_buy_time", get_time()+15)
end
end
function is_in_table(tab,var)
for i = 1, table.getn(tab) do
if tab[i] == var then return true end
end
return false
end
function convertToDateTable(endDate)
return itemshop_v2.split_(string.gsub(endDate,'[ :]','-'),'-')
end
function currentTimeDiff(date_)
local t1 = os.time({day=os.date("%d"),month=os.date("%m"),year=os.date("%Y"),hour=os.date("%H"),min=os.date("%M"),sec=os.date("%S")})
local t2 = os.time({day=tonumber(date_[3]),month=tonumber(date_[2]),year=tonumber(date_[1]),hour=tonumber(date_[4]),min=tonumber(date_[5]),sec=tonumber(date_[6])})
return os.difftime(t2,t1)
end
function client_command(command_)
return itemshop_v2.split_(command_,'#')
end
function split_(string_, sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
string.gsub(string_,pattern, function(c) fields[table.getn(fields)+1] = c end)
return fields
end
function set_current_achievementpoints(points)
itemshop_v2.send_command_achievementsystem('UPDATE_STATISTIC_ACHIEVEMENTPOINTS_CURRENT/'..points)
end
function set_total_achievementpoints(points)
itemshop_v2.send_command_achievementsystem('UPDATE_STATISTIC_ACHIEVEMENTPOINTS_TOTAL/'..points)
end
function update_achievement_points()
itemshop_v2.set_total_achievementpoints(achievement.get_total_points())
itemshop_v2.set_current_achievementpoints(achievement.get_points())
end
function send_command_achievementsystem(command)
-- chat('send command: '..command)
cmdchat('achievementsystem '..command)
end
-- function split_(string_,delimiter)
-- local result = { }
-- local from = 1
-- local delim_from, delim_to = string.find( string_, delimiter, from )
-- while delim_from do
-- table.insert( result, string.sub( string_, from , delim_from-1 ) )
-- from = delim_to + 1
-- delim_from, delim_to = string.find( string_, delimiter, from )
-- end
-- table.insert( result, string.sub( string_, from ) )
-- return result
-- end
end
end



