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

TFS 0.X [LUA] Offer expire auction system - Not sending amount of items

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,404
Solutions
17
Reaction score
152
Location
Brazil
Hello everyone, everything good? I'm using the script from the post below but I found a bug: If an offer is for more then 1 items (20 SSA, for example) it only returns one within the parcel. Can you help me fix the script?

Lua:
 function getPlayerNameByGUID(guid)
local name = 0
      local resultId = db.getResult("SELECT `name` FROM `players` WHERE `id` = " .. guid)
      if(resultId:getID() ~= -1) then
    name = resultId.getDataString(resultId, "name")
          resultId:free()
      end
      return name
end

function onStartup()
   local result = db.getResult("SELECT `id`, `player`, `item_id`, `item_name`, `count`, `cost`, `date` FROM `auction_system` ORDER by `date` ASC;")
   local days = 30*3600*24
   local nowtime = os.date('*t')
   if (result and result:getID() ~= -1) then
     while(true) do
       local id = result:getDataInt("id")
       local player = result:getDataString("player")
       local item_id = result:getDataInt("item_id")
       local item_name = result:getDataString("item_name")
       local count = result:getDataInt("count")
       local cost = result:getDataInt("cost")
       local date = result:getDataInt("date")
       local chest = doCreateItemEx(2595)
       local time= os.time(nowtime) - date
       local duedate = time - days
       local town_id = 1
       if duedate >= 0 then
           doAddContainerItem(chest, item_id, count)
           doPlayerSendMailByName(getPlayerNameByGUID(player), chest, town_id)
           db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';")
       end
       if not(result:next()) then
           break
       end
        end
   end
end

 
Last edited:
There are some observations in that script

player guid is a int value, and you are taking it from database as string:

Lua:
result:getDataString("player")

Should be

Lua:
result:getDataInt("player")

Another thing is you are creating tons of chests from all offers list before check if there is an auction available to be deleted

Code:
local chest = doCreateItemEx(2595)

Another you are sending a mail parcel without verify if the deletion was successfull, also you are

Code:
if duedate >= 0 then
    doAddContainerItem(chest, item_id, count)
    doPlayerSendMailByName(getPlayerNameByGUID(player), chest, town_id)
    db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';")
end

And should be

Code:
 if duedate >= 0 then
     if db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';") then
        local chest = doCreateItemEx(2595)
        doAddContainerItem(chest, item_id, count)
        doPlayerSendMailByName(getPlayerNameByGUID(player), chest, town_id)
    end
end

Code:
function getPlayerNameByGUID(guid)
    local name = 0
    local resultId = db.getResult("SELECT `name` FROM `players` WHERE `id` = " .. guid)
    if(resultId:getID() ~= -1) then
        name = resultId.getDataString(resultId, "name")
        resultId:free()
    end
    return name
end

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

            local time = os.time(nowtime) - date
            local duedate = time - days
            local town_id = 1
            
            if duedate >= 0 then
                if db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';") then
                    local chest = doCreateItemEx(2595)
                    doAddContainerItem(chest, item_id, count)
                    doPlayerSendMailByName(getPlayerNameByGUID(player), chest, town_id)
                end
            end
            if not(result:next()) then
                break
            end
        end
    end
end
 
There are some observations in that script

player guid is a int value, and you are taking it from database as string:

Lua:
result:getDataString("player")

Should be

Lua:
result:getDataInt("player")

Another thing is you are creating tons of chests from all offers list before check if there is an auction available to be deleted

Code:
local chest = doCreateItemEx(2595)

Another you are sending a mail parcel without verify if the deletion was successfull, also you are

Code:
if duedate >= 0 then
    doAddContainerItem(chest, item_id, count)
    doPlayerSendMailByName(getPlayerNameByGUID(player), chest, town_id)
    db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';")
end

And should be

Code:
 if duedate >= 0 then
     if db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';") then
        local chest = doCreateItemEx(2595)
        doAddContainerItem(chest, item_id, count)
        doPlayerSendMailByName(getPlayerNameByGUID(player), chest, town_id)
    end
end
Thanks for answer, so the code should be like this, right?

Lua:
 function getPlayerNameByGUID(guid)
local name = 0
      local resultId = db.getResult("SELECT `name` FROM `players` WHERE `id` = " .. guid)
      if(resultId:getID() ~= -1) then
    name = resultId.getDataString(resultId, "name")
          resultId:free()
      end
      return name
end

function onStartup()
   local result = db.getResult("SELECT `id`, `player`, `item_id`, `item_name`, `count`, `cost`, `date` FROM `auction_system` ORDER by `date` ASC;")
   local days = 30*3600*24
   local nowtime = os.date('*t')
   if (result and result:getID() ~= -1) then
     while(true) do
       local id = result:getDataInt("id")
       local player = result:getDataInt("player")
       local item_id = result:getDataInt("item_id")
       local item_name = result:getDataString("item_name")
       local count = result:getDataInt("count")
       local cost = result:getDataInt("cost")
       local date = result:getDataInt("date")
       local time= os.time(nowtime) - date
       local duedate = time - days
       local town_id = 1
    if duedate >= 0 then
     if db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';") then
        local chest = doCreateItemEx(2595)
        doAddContainerItem(chest, item_id, count)
        doPlayerSendMailByName(getPlayerNameByGUID(player), chest, town_id)
    end
end
       if not(result:next()) then
           break
       end
        end
   end
end

I was thinking of something else: if I have an offer with 20 items (and those items are not stackable) and the parcel only has 10 slots, could this be a problem?
 
Thanks for answer, so the code should be like this, right?

Lua:
 function getPlayerNameByGUID(guid)
local name = 0
      local resultId = db.getResult("SELECT `name` FROM `players` WHERE `id` = " .. guid)
      if(resultId:getID() ~= -1) then
    name = resultId.getDataString(resultId, "name")
          resultId:free()
      end
      return name
end

function onStartup()
   local result = db.getResult("SELECT `id`, `player`, `item_id`, `item_name`, `count`, `cost`, `date` FROM `auction_system` ORDER by `date` ASC;")
   local days = 30*3600*24
   local nowtime = os.date('*t')
   if (result and result:getID() ~= -1) then
     while(true) do
       local id = result:getDataInt("id")
       local player = result:getDataInt("player")
       local item_id = result:getDataInt("item_id")
       local item_name = result:getDataString("item_name")
       local count = result:getDataInt("count")
       local cost = result:getDataInt("cost")
       local date = result:getDataInt("date")
       local time= os.time(nowtime) - date
       local duedate = time - days
       local town_id = 1
    if duedate >= 0 then
     if db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';") then
        local chest = doCreateItemEx(2595)
        doAddContainerItem(chest, item_id, count)
        doPlayerSendMailByName(getPlayerNameByGUID(player), chest, town_id)
    end
end
       if not(result:next()) then
           break
       end
        end
   end
end

I was thinking of something else: if I have an offer with 20 items (and those items are not stackable) and the parcel only has 10 slots, could this be a problem?

Non stackable items should have only count 1 if your auction system put offers 1 x 1 this code works to send 1 parcel per every offers as i can see, so, stone skin amulet has charges, you must verify if the item has charges, and then apply it using doSetItemAttribute(uid, "charges") if your distro support that function.
 
Last edited:
Non stackable items should have only count 1 if your auction system put offers 1 x 1 this code works to send 1 parcel per every offers as i can see, so, stone skin amulet has charges, you must verify if the item has charges, and then apply it.
You killed the charade! If I place 20 SSAs with 5 charges each, it returns me only one SSA with 20 charges (it gives me back in charges the number of items I should have). I have no idea how to fix it, can you help me?
Post automatically merged:

Maybe same solution applied here?

 
Lua:
getItemInfo(id).charges or 1
will verify is on items.xml the current item (SSA) has charges, so you can create a new itemEx and apply the charges

Lua:
function getPlayerNameByGUID(guid)
    local name = 0
    local resultId = db.getResult("SELECT `name` FROM `players` WHERE `id` = " .. guid)
    if(resultId:getID() ~= -1) then
        name = resultId.getDataString(resultId, "name")
        resultId:free()
    end
    return name
end

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

            local time = os.time(nowtime) - date
            local duedate = time - days
            local town_id = 1
          
            if duedate >= 0 then
                if db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';") then
                    local chest = doCreateItemEx(2595)
                    local item = doCreateItemEx(item_id, 1)
                    local charges = getItemInfo(item_id).charges or 0
                  
                    if charges > 0 then
                        doItemSetAttribute(item, "charges", charges)
                    end
                  
                    doAddContainerItemEx(chest, item)
                    doPlayerSendMailByName(getPlayerNameByGUID(player), chest, town_id)
                end
            end
            if not(result:next()) then
                break
            end
        end
    end
end
 
Lua:
getItemInfo(id).charges or 1
will verify is on items.xml the current item (SSA) has charges, so you can create a new itemEx and apply the charges

Lua:
function getPlayerNameByGUID(guid)
    local name = 0
    local resultId = db.getResult("SELECT `name` FROM `players` WHERE `id` = " .. guid)
    if(resultId:getID() ~= -1) then
        name = resultId.getDataString(resultId, "name")
        resultId:free()
    end
    return name
end

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

            local time = os.time(nowtime) - date
            local duedate = time - days
            local town_id = 1
        
            if duedate >= 0 then
                if db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';") then
                    local chest = doCreateItemEx(2595)
                    local item = doCreateItemEx(item_id, 1)
                    local charges = getItemInfo(item_id).charges or 0
                
                    if charges > 0 then
                        doItemSetAttribute(item, "charges", charges)
                    end
                
                    doAddContainerItemEx(chest, item)
                    doPlayerSendMailByName(getPlayerNameByGUID(player), chest, town_id)
                end
            end
            if not(result:next()) then
                break
            end
        end
    end
end
It count charges ok now, but return just 1 item again. Maybe because this line? Must be
Lua:
count
?

Lua:
 local item = doCreateItemEx(item_id, 1)
Post automatically merged:

Its not this too, returning in correct charges but only 1 SSA
Post automatically merged:

This is the part of talkaction to remove offer (when player want to remove their offer and take itens back), now i realize, get problem too, is returning just one charge of SSA:

Lua:
        if(t[1] == "remove") then
                if((not tonumber(t[2]))) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
                        return true
                end
                                if(config.SendOffersOnlyInPZ) then    
                                        if(not getTilePzInfo(getPlayerPosition(cid))) then
                                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you remove offerts from database.")
                                                return true
                                        end
                end
                local delete = db.getResult("SELECT * FROM `auction_system` WHERE `id` = " .. (tonumber(t[2])) .. ";")        
                if(delete:getID() ~= -1) then
                        if(getPlayerGUID(cid) == delete:getDataInt("player")) then
                                db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. t[2] .. ";")
                                if(isItemStackable(delete:getDataString("item_id"))) then
                                        doPlayerAddItem(cid, delete:getDataString("item_id"), delete:getDataInt("count"))
                                else
                                        for i = 1, delete:getDataInt("count") do
                                                doPlayerAddItem(cid, delete:getDataString("item_id"), 1)
                                        end
                                end
                                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your offert has been deleted from offerts database.")
                        else
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This is not your offert!")
                        end
                delete:free()
                else
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
                end
        end
 
Last edited:
Lua:
function getPlayerNameByGUID(guid)
    local name = 0
    local resultId = db.getResult("SELECT `name` FROM `players` WHERE `id` = " .. guid)
    if(resultId:getID() ~= -1) then
        name = resultId.getDataString(resultId, "name")
        resultId:free()
    end
    return name
end
function onStartup()
    local result = db.getResult("SELECT `id`, `player`, `item_id`, `item_name`, `count`, `cost`, `date` FROM `auction_system` ORDER by `date` ASC;")
    local days = 30*3600*24
    local nowtime = os.date('*t')
    local town_id = 1
    if (result and result:getID() ~= -1) then
        while(true) do
            local id = result:getDataInt("id")
            local player = result:getDataInt("player")
            local item_id = result:getDataInt("item_id")
            local item_name = result:getDataString("item_name")
            local count = result:getDataInt("count")
            local cost = result:getDataInt("cost")
            local date = result:getDataInt("date")
            local time= os.time(nowtime) - date
            local duedate = time - days
            if duedate >= 0 then
                if db.executeQuery("DELETE FROM `auction_system` WHERE `id` = '".. id .."';") then
                    while count > 0 do
                        local chest = doCreateItemEx(2595)
                        doAddContainerItem(chest, item_id, (count > 20 and 20 or count))
                        doPlayerSendMailByName(getPlayerNameByGUID(player), chest, town_id)
                        count = count - 20
                    end
                end
            end
            if not(result:next()) then
                break
            end
        end
    end
end
 
Last edited by a moderator:
Back
Top