• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Shop.lua !! is crazy give a lot of items!!

Mariuskens

Sword Art Online 2D-MMORPG
Joined
Nov 21, 2008
Messages
1,009
Reaction score
119
Location
Spain
GitHub
Olimpotibia
my shop.lua is crazy otlanders!!

Give every second items !! help me !

[Error - GlobalEvent Interface]
[16/10/2012 09:01:22] data/globalevents/scripts/shop.luanThink
[16/10/2012 09:01:22] Description:
[16/10/2012 09:01:22] data/globalevents/scripts/shop.lua:22: attempt to call field 'executeQuery' (a nil value)
[16/10/2012 09:01:22] stack traceback:
[16/10/2012 09:01:22] data/globalevents/scripts/shop.lua:22: in function <data/globalevents/scripts/shop.lua:1>
[16/10/2012 09:01:22] [Error - GlobalEvents::think] Couldn't execute event: shop

Me using Modern Aac
I have z_ots_comunication table SQL.

- - - Updated - - -

This lua dont write in Processed Colum SQL help me!

Duplicate items every 30 secs
 
Last edited:
Try out this shop.lua and tell me if the problem still continues.

Shop.lua
PHP:
-- ### CONFIG ###
-- message send to player by script "type" (types you can check in "global.lua")
SHOP_MSG_TYPE = 19
-- time (in seconds) between connections to SQL database by shop script
SQL_interval = 30
-- ### END OF CONFIG ###
function onThink(interval, lastExecution)
    local result_plr = db.getResult("SELECT * FROM z_ots_comunication WHERE `type` = 'login';")
    if(result_plr:getID() ~= -1) then
        while(true) do
            id = tonumber(result_plr:getDataInt("id"))
            action = tostring(result_plr:getDataString("action"))
            delete = tonumber(result_plr:getDataInt("delete_it"))
            cid = getCreatureByName(tostring(result_plr:getDataString("name")))
            if isPlayer(cid) == TRUE then
                local itemtogive_id = tonumber(result_plr:getDataInt("param1"))
                local itemtogive_count = tonumber(result_plr:getDataInt("param2"))
                local container_id = tonumber(result_plr:getDataInt("param3"))
                local container_count = tonumber(result_plr:getDataInt("param4"))
                local add_item_type = tostring(result_plr:getDataString("param5"))
                local add_item_name = tostring(result_plr:getDataString("param6"))
                local received_item = 0
                local full_weight = 0
                if add_item_type == 'container' then
                    container_weight = getItemWeightById(container_id, 1)
                    if isItemRune(itemtogive_id) == TRUE then
                        items_weight = container_count * getItemWeightById(itemtogive_id, 1)
                    else
                        items_weight = container_count * getItemWeightById(itemtogive_id, itemtogive_count)
                    end
                    full_weight = items_weight + container_weight
                else
                    full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
                    if isItemRune(itemtogive_id) == TRUE then
                        full_weight = getItemWeightById(itemtogive_id, 1)
                    else
                        full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
                    end
                end
                local free_cap = getPlayerFreeCap(cid)
                if full_weight <= free_cap then
                    if add_item_type == 'container' then
                        local new_container = doCreateItemEx(container_id, 1)
                        local iter = 0
                        while iter ~= container_count do
                            doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
                            iter = iter + 1
                        end
                        received_item = doPlayerAddItemEx(cid, new_container)
                    else
                        local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
                        received_item = doPlayerAddItemEx(cid, new_item)
                    end
                    if received_item == RETURNVALUE_NOERROR then
                        doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received >> '.. add_item_name ..' << from OTS shop.')
                        db.executeQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
                        db.executeQuery("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
                    else
                        doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
                    end
                else
                    doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. It weight is '.. full_weight ..' oz., you have only '.. free_cap ..' oz. free capacity. Put some items in depot and wait about '.. SQL_interval ..' seconds to get it.')
                end
            end
            if not(result_plr:next()) then
                break
            end
        end
        result_plr:free()
    end
    return TRUE
end
 
i've use this
Shop.lua:21 attempt to index field 'db'

function onThink()
local r = db.getResult('SELECT * FROM shop_history WHERE processed=0')
if r:getID() ~= -1 then
repeat
local cid = getPlayerByName(r:getDataString('player'))
if isPlayer(cid) then
local bp = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).uid
if bp ~= 0 then
local j = db.getResult('SELECT * FROM shop_offer WHERE id='..r:getDataInt('product'))
if j:getID() ~= -1 then
local id = tonumber(j:getDataInt('item'))
local tid = tonumber(r:getDataInt('id'))
local count = tonumber(j:getDataInt('count'))
local tipe = tonumber(j:getDataInt('type'))
local name = j:getDataString('name')
if tipe == 5 or tipe == 8 then
local w = getItemInfo(id).weight * count
if getPlayerFreeCap(cid) >= w then
if doAddContainerItemEx(bp, doCreateItemEx(id, count)) == 1 then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You have received >> '..name..' << from our shop system')
db.db.query('UPDATE shop_history SET processed=1 WHERE id = ' .. tid)
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You don\'t have enough space in backpack to receive >> '..name..' <<')
end
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'Sorry, you don\'t have enough capacity to receive >> '..name..' << (You need: '..getItemInfo(id).weight * count..' Capacity)')
end
elseif tipe == 6 or tipe == 7 then
local bid, bcap =
tipe == 6 and 1987 or 1988,
tipe == 6 and 8 or 20
local w = getItemInfo(bid).weight + (getItemInfo(id).weight * count * bcap)
if getPlayerFreeCap(cid) >= w then
local c = doCreateItemEx(bid)
for i = 1, bcap do
doAddContainerItem(c, id, count)
end
if doPlayerAddItemEx(getPlayerSlotItem(cid, 3).uid, c) == RETURNVALUE_NOERROR then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You have received >> '..name..' << from our shop system')
db.db.query('UPDATE shop_history SET processed=1 WHERE id='..tid)
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'Sorry, you don\'t have enough space to receive >> '..name..' <<')
end
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'Sorry, you don\'t have enough capacity to receive >> '..name..' << (You need: '..w..' Capacity)')
end
end
j:free()
end
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You don\'t have a container in your backpack slot.')
end
end
until not r:next()
r:free()
end
return true
end

- - - Updated - - -

LucasFerraz your shop.lua is buged!

- - - Updated - - -

thnx but your script is bug too Steel Man

- - - Updated - - -

Summ don't work help me please!

- - - Updated - - -

my problem is that on the table 'Processed' of Shop_history not populated with 1 after the player receives the item
 
15:57 You received Elite Draken Mail in depot of your hometown.
15:57 You received Elite Draken Mail in depot of your hometown.
15:57 You received Elite Draken Mail in depot of your hometown.
15:58 You received Elite Draken Mail in depot of your hometown.
15:58 You received Elite Draken Mail in depot of your hometown.

now using your script help me man!

bugggggggg.jpg
 
i try db.query and nothing same error

LucasFerraz your script give a lot of items !!. the script don't writte '1' in colum Processed (Shop_history)
 
Last edited:
i try db.query and nothing same error

LucasFerraz your script give a lot of items !!. the script don't writte '1' in colum Processed (Shop_history)

Hey,

I have found ur problem...
can u send me ur 100-compat.lua so I can send edit and give u the new one.

100-compat.lua is located in: data/lib/
 
Back
Top