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

Send item back to owner Auction System

leol

New Member
Joined
Apr 2, 2017
Messages
17
Reaction score
0
Hello boys, i'm using this script to auction system (is like a offline trade for 8x/7x servers)
TalkAction - Offline player to player item trader (Auction System).

But after a long time this been a full of trash items/absurd prices to just spam the pages...

So here in forum i found another one thing:
Code:
function onStartup()
   local result = db.getResult("SELECT `id`, `date` FROM `auction_system` ORDER by `date` ASC;")
   local days = 30*3600*24
   local nowtime = os.date('*t')
   if(result:getID() ~= -1) then
     while(true)
       local id = result:getDataInt("id")
       local date = result:getDataInt("date")
       local time= os.time(nowtime) - date
       local duedate = time - days
       if duedate >= 0 then
           -- send item back to the owner
          
           -- delete offer
           db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';")
       end
       if not(result:next()) then
           break
       end
   end
   end
   result:free()
end

This actually clean the old ones, after 30 days if no one buy...
It's sound perfect, but the part to send item to the owner is not done, so if i try to sell my demon armor to 500k after 31 days if no one buy, its just be destroyed

Anybody know how to send this item back to the owner DP?

A guy named audu said that needed to be on server save because to send items to player depot, the player need to be offline, but onstartup should work, right? because everybody is offline when startup
 
Last edited:
Guys i tried to test this script here and it's not working...

Code:
[23:7:36.979] mysql_real_query(): SELECT `id`, `date`, `player`, `itemid`, `count` FROM `auction_system` ORDER by `date` ASC; - MYSQL ERROR: Unknown column 'itemid' in 'field list' (1054)

[23:7:36.990] [Error - GlobalEvent Interface]
[23:7:36.990] data/globalevents/scripts/marketcleaner.lua:onStartup
[23:7:36.990] Description:
[23:7:36.990] data/lib/004-database.lua:100: [Result:free] Result not set!
[23:7:36.990] stack traceback:
[23:7:36.990]    [C]: in function 'error'
[23:7:36.990]    data/lib/004-database.lua:100: in function 'free'
[23:7:36.990]    data/globalevents/scripts/marketcleaner.lua:33: in function <data/globalevents/scripts/marketcleaner.lua:1>

Code:
function onStartup()
   local result = db.getResult("SELECT `id`, `date`, `player`, `itemid`, `count` FROM `auction_system` ORDER by `date` ASC;")
   local days = 30*3600*24
   local nowtime = os.date('*t')
   if(result:getID() ~= -1) then
     while(true) do
       local id = result:getDataInt("id")
       local date = result:getDataInt("date")
       local player = result:getDataInt("player")
       local itemid = result:getDataInt("itemid")
       local count = result:getDataInt("count")
       local depotid = player:getTown():getId()

       local resultId = db.storeQuery("SELECT `sid` FROM `player_depotitems` WHERE `player_id` = `" .. player:getId().. "` ORDER BY `sid` DESC LIMIT 1;")
       local sid = result.getNumber(resultId, "sid") + 1
       result.free(resultId)

       local pid = 101
       local time= os.time(nowtime) - date
       local duedate = time - days
       if duedate >= 0 then
           -- send item back to the owner
          db.storeQuery("SELECT `sid` FROM `player_depotitems` WHERE `player_id` = `" .. player:getId().. "`;")
          db.executeQuery("INSERT INTO `player_depotitems` (`player_id`, `depot_id`, `sid`, `pid`, `itemtype`, `count`, `attributes`) VALUES ('".. player .."', '".. depotid .."', '".. sid .."', '".. pid .."', '".. itemid .."', '".. count .."');")
           -- delete offer
           db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';")
       end
       if not(result:next()) then
           break
       end
   end
   end
   result:free()
end

bump
 
Before you call a method on an userdata/table you should always check if the object is not nil.

The only 2 values which are considered false is false and nil... everything else is considered true.
It doesn't matter if its an empty string/table, negative number or even 0, if you evaluate it by itself it will always evaluate to true.
 
Before you call a method on an userdata/table you should always check if the object is not nil.

The only 2 values which are considered false is false and nil... everything else is considered true.
It doesn't matter if its an empty string/table, negative number or even 0, if you evaluate it by itself it will always evaluate to true.

I'm sorry if it looks dumb, but isn't this:

function onStartup()
local result = db.getResult("SELECT `id`, `date`, `player`, `itemid`, `count` FROM `auction_system` ORDER by `date` ASC;")
local days = 30*3600*24
local nowtime = os.date('*t')
if(result:getID() ~= -1) then
while(true) do
local id = result:getDataInt("id")
local date = result:getDataInt("date")
local player = result:getDataInt("player")
local itemid = result:getDataInt("itemid")
local count = result:getDataInt("count")
local depotid = player:getTown():getId()
local resultId = db.storeQuery("SELECT `sid` FROM `player_depotitems` WHERE `player_id` = `" .. player:getId().. "` ORDER BY `sid` DESC LIMIT 1;")
local sid = result.getNumber(resultId, "sid") + 1
result.free(resultId)
local pid = 101
local time= os.time(nowtime) - date
local duedate = time - days
if duedate >= 0 then
-- send item back to the owner
db.storeQuery("SELECT `sid` FROM `player_depotitems` WHERE `player_id` = `" .. player:getId().. "`;")
db.executeQuery("INSERT INTO `player_depotitems` (`player_id`, `depot_id`, `sid`, `pid`, `itemtype`, `count`, `attributes`) VALUES ('".. player .."', '".. depotid .."', '".. sid .."', '".. pid .."', '".. itemid .."', '".. count .."');")
-- delete offer
db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';")
end
if not(result:next()) then
break
end
end
end
result:free()
end
 
This is bad
Lua:
if(result:getID() ~= -1) then
Should be, if and only if result is userdata
Code:
if(result and result:getID() ~= -1) then
If its a table then
Lua:
if(result and next(result) then
    if result:getID() ~= -1 then

If we don't know what result is we can always use type
Lua:
print( type( result ) )
 
Back
Top