• 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:
Look at the schema to see where the itemid is stored, then fetch that from the database before deleting and use doPlayerAddItem(cid, itemid, count)
 
Look at the schema to see where the itemid is stored, then fetch that from the database before deleting and use doPlayerAddItem(cid, itemid, count)

I think the itemid is it:
local id = result:getDataInt("id")

But i need to know how to send the item back to old owner

doPlayerAddItem should add item in player backpack right? And if player be online, i think it's not how to do bro
 
I think the itemid is it:
local id = result:getDataInt("id")

But i need to know how to send the item back to old owner

doPlayerAddItem should add item in player backpack right? And if player be online, i think it's not how to do bro

Insert the item into the depot box in that case.
 
Insert the item into the depot box in that case.

Thats what i asked help for bro, idk how to do it:
If Player Is Online:
Send Player Parcel, there is a function for this on 0.4?

Else if player is not Online:
Insert on DB (i saw on internet player need to be offline to do this)
 
Thats what i asked help for bro, idk how to do it:
If Player Is Online:
Send Player Parcel, there is a function for this on 0.4?

Else if player is not Online:
Insert on DB (i saw on internet player need to be offline to do this)

0.x does not have the functions like 1.x does, so even if the player is online you have to use a query;
SQL:
CREATE TABLE `player_depotitems`
(
`player_id` INT NOT NULL,
`depot_id` INT NOT NULL DEFAULT 0,
`sid` INT NOT NULL COMMENT 'any given range eg 0-100 will be reserved for depot lockers and all > 100 will be then normal items inside depots',
`pid` INT NOT NULL DEFAULT 0,
`itemtype` INT NOT NULL,
`count` INT NOT NULL DEFAULT 0,
`attributes` BLOB NOT NULL,
KEY (`player_id`, `depot_id`),
UNIQUE (`player_id`, `sid`),
FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE
) ENGINE = InnoDB;

Give it a try and quote me if you get any problems with the code you wrote.
 
0.x does not have the functions like 1.x does, so even if the player is online you have to use a query;
SQL:
CREATE TABLE `player_depotitems`
(
`player_id` INT NOT NULL,
`depot_id` INT NOT NULL DEFAULT 0,
`sid` INT NOT NULL COMMENT 'any given range eg 0-100 will be reserved for depot lockers and all > 100 will be then normal items inside depots',
`pid` INT NOT NULL DEFAULT 0,
`itemtype` INT NOT NULL,
`count` INT NOT NULL DEFAULT 0,
`attributes` BLOB NOT NULL,
KEY (`player_id`, `depot_id`),
UNIQUE (`player_id`, `sid`),
FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE
) ENGINE = InnoDB;

Give it a try and quote me if you get any problems with the code you wrote.
I have to do something like he need, could you make it on him script so i can get a example to make mine?
 
I have to do something like he need, could you make it on him script so i can get a example to make mine?

You need to modify it abit to ex be usable in a loop, but here is the gist of it;
Lua:
db.query("INSERT INTO `player_depotitems` (`player_id`, `depot_id`, `sid`, `pid`, `itemtype`, `count`, `attributes`) VALUES (playerId, 1, 1, 0, itemCount, itemId, '')")
 
You need to modify it abit to ex be usable in a loop, but here is the gist of it;
Lua:
db.query("INSERT INTO `player_depotitems` (`player_id`, `depot_id`, `sid`, `pid`, `itemtype`, `count`, `attributes`) VALUES (playerId, 1, 1, 0, itemCount, itemId, '')")

I want this too...
But i need some help...
Do i doing right?

PHP:
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)
       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 = ?
       local sid = ?
       local pid = ?
       local time= os.time(nowtime) - date
       local duedate = time - days
       if duedate >= 0 then
           -- send item back to the owner
          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

depotid is townid where items going on?
what is sid, pid what should i put?
 
I want this too...
But i need some help...
Do i doing right?

PHP:
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)
       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 = ?
       local sid = ?
       local pid = ?
       local time= os.time(nowtime) - date
       local duedate = time - days
       if duedate >= 0 then
           -- send item back to the owner
          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

depotid is townid where items going on?
what is sid, pid what should i put?

For the depot id you can use this;
Lua:
player:getTown():getId()
That will return the home town id, if you wanna use the inbox it's a diffrent query.

Not 100% sure, so you might have to try it out by testing.
But if I understand the schema correctly (forgottenserver/schema.sql at master · otland/forgottenserver · GitHub)

Sid should be 100 + the amount of items?, since it's an item inside the depot box.
Pid must be the position, so try 1 or maybe 101?

Give that a try and come back with the results :p
 
For the depot id you can use this;
Lua:
player:getTown():getId()
That will return the home town id, if you wanna use the inbox it's a diffrent query.

Not 100% sure, so you might have to try it out by testing.
But if I understand the schema correctly (forgottenserver/schema.sql at master · otland/forgottenserver · GitHub)

Sid should be 100 + the amount of items?, since it's an item inside the depot box.
Pid must be the position, so try 1 or maybe 101?

Give that a try and come back with the results :p

I've create a character enter put a plate armor (2463) inside the depot and create this columns:

Code:
player_id | sid | pid | itemtype | count | attributes
2 | 101 | 1 |    2589 | 1 |
2 | 102 | 101 | 2463 | 1 |
2 | 103 | 101 | 2594 | 1 |

Sid looks be the last item...
Sid i think need to be 101

Idk how to do this, could you help me?
PHP:
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)
       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 sid = ?
       local pid = 101
       local time= os.time(nowtime) - date
       local duedate = time - days
       if duedate >= 0 then
           -- send item back to the owner
          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
 
I've create a character enter put a plate armor (2463) inside the depot and create this columns:

Code:
player_id | sid | pid | itemtype | count | attributes
2 | 101 | 1 |    2589 | 1 |
2 | 102 | 101 | 2463 | 1 |
2 | 103 | 101 | 2594 | 1 |

Sid looks be the last item...
Sid i think need to be 101

Idk how to do this, could you help me?
PHP:
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)
       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 sid = ?
       local pid = 101
       local time= os.time(nowtime) - date
       local duedate = time - days
       if duedate >= 0 then
           -- send item back to the owner
          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

You might need to run a query to see what sid should be, sort it by the highest number then increase it by 1.
 
You might need to run a query to see what sid should be, sort it by the highest number then increase it by 1.

And need to be the next item of that player id, because i created a new character and enter on DP to test and create this new tables:

Code:
player_id | sid | pid | itemtype | count | attributes
5 | 101 | 1 |    2589 | 1 |
5 | 102 | 101 | 2594 | 1 |

Could you give me the line? Idk how to do...
 
And need to be the next item of that player id, because i created a new character and enter on DP to test and create this new tables:

Code:
player_id | sid | pid | itemtype | count | attributes
5 | 101 | 1 |    2589 | 1 |
5 | 102 | 101 | 2594 | 1 |

Could you give me the line? Idk how to do...

This should work;
Lua:
db.storeQuery("SELECT `sid` FROM `player_depotitems` WHERE `player_id` = `" .. player:getId().. "`;")
 
This should work;
Lua:
db.storeQuery("SELECT `sid` FROM `player_depotitems` WHERE `player_id` = `" .. player:getId().. "`;")

It dont need that limit 1 and how to get the last one?
And how to use the result in the next query (the insert)
Code:
db.executeQuery("INSERT INTO `player_depotitems` (`player_id`, `depot_id`, `sid`, `pid`, `itemtype`, `count`, `attributes`) VALUES ('".. player .."', '".. depotid .."', '".. sid .."', '".. pid .."', '".. itemid .."', '".. count .."');")
 
It dont need that limit 1 and how to get the last one?
And how to use the result in the next query (the insert)
Code:
db.executeQuery("INSERT INTO `player_depotitems` (`player_id`, `depot_id`, `sid`, `pid`, `itemtype`, `count`, `attributes`) VALUES ('".. player .."', '".. depotid .."', '".. sid .."', '".. pid .."', '".. itemid .."', '".. count .."');")

Lua:
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)
 
Do i doing something dumb?

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)
       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

Code:
[10:52:41.985] [Error - LuaInterface::loadFile] data/globalevents/scripts/marketcleaner.lua:7: 'do' expected near 'local'
[10:52:41.985] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/marketcleaner.lua)
[10:52:41.986] data/globalevents/scripts/marketcleaner.lua:7: 'do' expected near 'local'
 
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
 
Back
Top