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

Lua Send item to depot offer owner

caquinha

Member
Joined
Aug 8, 2016
Messages
248
Solutions
1
Reaction score
24
I'm using this market system for 8.60
https://otland.net/threads/offline-player-to-player-item-trader-auction-system.51447/

And i need some help to if offer have more then 30 days, it be delete for offers lists and send item back to player depot...
@Stellow made this script to delete offers but it not send item back to owners:

There is a way to convert this script 1.0 to 0.4
https://otland.net/threads/automatic-znote-aac-shop-tfs-1-0.224483/
It send parcel...

Code:
<globalevent name="marketcleaner" type="startup" event="script" value="marketcleaner.lua"/>

marketcleaner.lua
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
           -- delete offer
           db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';")
       end
       if not(result:next()) then
           break
       end
   end
   end
   result:free()
end


Anyone know how to help me?
 
Last edited:
Here is the logic and how it should looks like. On heavy loaded servers it needs to be executed partially becouse if you send tons of queries your engine may corrupt your db. The script you made yourself was very good with one exception, cid works only on online players. So, you had to check player_id via db queries, not cid. Also making milions of parcels at the same time is bad idea. It's like 'the best way to self DDoSing'. Sing sing sing XD.

This script works exactly like that:
Code:
    1. checks expired auctions
    2. checks player's id of expired auction
    3. checks player's town of expired auction
    4. checks if player with id XXX opened his depot yet or have two important lines in db
        4.1. if not:
            4.1.1. !!!script unfinished!!!
                4.1.1.1. should add two new lines, the same as those what are generated by engine when you opens your dp for the first time
                4.1.1.2. repeat point 4
        4.2. if yes:
            4.2.1. checks sids and pids of containers
            4.2.2. adds new item/count equal to expired auction's item/count
            4.2.3. deletes expired auction
    5. ends script if no more expired auctions

For normal players, they will see a new item in blackbox depot, but it will be always in the last slot.

It may contain some code mistakes, but with info up what I wrote, your knowledge and help of people who hates bananas you will fix it very easly.

Code:
-- local banana = knowledge
-- not sure is `town_id` or `town id` and same with `item_id` or `item id` etc

function onStartup()
    local auctions = db.getResult("SELECT `id`, `player`, `date`, `item_id`, `count` FROM `auction_system` ORDER by `date` ASC;")
    local players = db.getResult("SELECT `id`, `town_id` FROM `players`;")
    local expireTime = 24 * 3600 * 1
    local nowTime = os.date('*t')
    if auctions:getID() ~= -1 then
        while(true) do
            local expired = time - expireTime
            if expired >= 0 then
                local a_id = auctions:getDataInt("id")
                local a_player_id = auctions:getDataInt("player")
                local a_itemid = auctions:getDataInt("item_id")
                local a_itemcount = auctions:getDataInt("count")
                local date = auctions:getDataInt("date")
 
                local player_town = players:getDataInt("town_id")
                local time = os.time(nowTime) - date
 
                -- send item back to old owner
                local depot_items = db.getResult("SELECT `sid` FROM `player_depotitems` WHERE `player_id` = `"..a_player_id.."` AND `pid` = `"..player_town.."`;")
                if depot_items:getID() ~= -1 then
                    local depotBlackBoxSid = depot_items:getDataInt("sid")
                    local black_depotbox_items = db.getResult("SELECT `sid` FROM `player_depotitems` WHERE `player_id` = `"..a_player_id.."` AND `pid` = `"..depotBlackBoxSid.."` ORDER by `sid` ASC;")
                    local newSid = #black_depotbox_items + 1 -- not sure this is the way to check it
                    db.executeQuery("INSERT INTO `player_depotitems` (`player_id`, `sid`, `pid`, `itemtype`, `count`) VALUES ("..a_player_id..", "..newSid..", "..depotBlackBoxSid..", "..a_itemid..", "..a_itemcount..")")
                    -- delete item
                    db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '"..a_id.."';")
                else
                    -- if player doesnt opened his depo yet, create new two lines in db then execute the same code up
                    -- bla bla bla
                    -- bla bla bla
                end
            end
            if not(auctions:next()) then
                break
            end
        end
        auctions:free()
    end
    return true
end


Result is: you didn't found banana.

@andu your script is not work
Code:
[12:45:02.944] [Error - GlobalEvent Interface]
[12:45:02.944] data/globalevents/scripts/marketcleaner.lua:onStartup
[12:45:02.944] Description:
[12:45:02.944] data/globalevents/scripts/marketcleaner.lua:10: attempt to perform arithmetic on global 'time' (a nil value)
[12:45:02.944] stack traceback:
[12:45:02.944]    data/globalevents/scripts/marketcleaner.lua:10: in function <data/globalevents/scripts/marketcleaner.lua:3>

And what should be this bla bla bla?

Ty

---

@Il Knight
Why you don't share the script you send to @caquinha here?
A lot people want this script!
 
Srry to this long
@Il Knight
Gave me this code:
Code:
function onStartup()
   local result = db.getResult("SELECT `id`, `date`, `player`, `item_id`,  `count`  FROM `auction_system` ORDER by `date` ASC;")
    local days = 1*3600*1
    --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 p = result:getDataInt("player")
            local time= os.time(nowtime) - date
            local duedate = time - days
            if duedate >= 0 then
               -- send item back to old owner
               local item = result:getDataInt("item_id")
    local count = result:getDataInt("count")
print(" .. item .. ")
print(" .. count .. ")
               -- delete item
                db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';")
            end
            if not(result:next()) then
                break
            end
        end
        result:free()
    end
end

With this return:
Code:
[14:9:30.237] >> Initializing game state and binding services...
 .. item ..
.. count ..
[14:9:32.230] > Global IP address: 127.0.0.1

And leave, i think he don't know how to do
Least I
Srry
 
Thank you...
@andu
Could you help us to finish it?
A lot people use this script and it's necessary to clean
Imagine a Otserver 3 years online, with never clean
 
Back
Top