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

AAC Doubt get All Table count

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
this code check if player have more than 5 items in shop auction (trade offline). its 0.x
Code:
                 local check = db.getResult("SELECT `id` FROM `auction_system` WHERE `player` = " .. getPlayerGUID(cid) .. ";")
                if(check:getID() == -1) then
                elseif(check:getRows(true) >= 5) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry you can't add more offers (max. 5)")
                        return true
                end

i'm tring to pass it to 1.x, so i tested id:

Code:
                local check = db.storeQuery("SELECT `id` FROM `auction_system` WHERE `player` = " .. player:getGuid() .. ";")
                if check ~= false then
                    local resultId = result.getDataInt(check, "id")
                    if resultId and resultId >= 5 then
                        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Sorry you can't add more offers (max. 5)")
                        return true
                    end
                end

1572143099406.png
must return 2, because the player has 2 items in the shop
but it always return 1, why?
 
Because you're only using getDataInt once, here's a code snippet to understand how to iterate each result:
LUA:
repeat
    print(result.getDataInt(check, "id")
until not result.next(check)
result.free(check)
 
Because you're only using getDataInt once, here's a code snippet to understand how to iterate each result:
LUA:
repeat
    print(result.getDataInt(check, "id")
until not result.next(check)
result.free(check)
it is correct? it worked, but i dont know if is the better way

LUA:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local check = db.storeQuery("SELECT `id` FROM `auction_system` WHERE `player` = " .. player:getGuid() .. ";")
    local count = 0
    
    repeat
        count = count + 1
    until not result.next(check)
    result.free(check)
    
    print(count)
    return true
end

it printed 2, because the player that have player_id = 3, have 2 items in shop auction, but it is the better way?
1572589934053.png
 
Back
Top