• 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 Automatic Don. Castle System Error

Leyla Cullin

Honey
Joined
Jul 13, 2015
Messages
36
Reaction score
1
Location
Germany
Hello Guys, can you help me again please?

I want to use this Don. Castle System for my Server but i get the following error when starting the server:
Code:
data/globalevents/scripts/Castles.lua:2: attempt to call field 'getResult' (a nil value)
I searched on OTLand for some useful ideas but nothing did work. As example i tried to use db.storeQuery
instead of db.getResult. But this just occurs the error:
Code:
data/globalevents/scripts/Castles.lua:3: attempt to index local 'castles' (a number value)
If needed, here is the code of the Castles.lua:
Code:
function onThink()
    local castles = db.storeQuery("SELECT id FROM houses WHERE `town` = '4';")
    if(castles:getID() == -1) then
        return true
    end

    local p = getPlayersOnline()[1]
    repeat
        local hid = castles:getDataInt('id')
        local h = getHouseInfo(hid)
        if h.owner == 0 then
            setHouseOwner(hid, 3)
        elseif p then
            local n = tonumber(h.name:sub(-2)) or 0
            h.entry.x = h.entry.x + (n % 2 == 0 and 3 or -3)
            doCreatureSay(p, getPlayerNameByGUID(h.owner), TALKTYPE_ORANGE_1, false, 0, h.entry)
        end
    until not castles:next()
    castles:free()

    return true
end

Thank you very much for every help!

Feel loved by me, Leyla.
 
have fun
Code:
function onThink()
    local castles = db.storeQuery('SELECT id FROM houses WHERE town_id=4')
    if not castles then
        return false
    end
    repeat
        local hid = tonumber(result.getDataInt(castles, "id"))
        local house_pos = getHouseEntry(hid)
        if getHouseOwner(hid) == 0 then
            setHouseOwner(hid, 3)
        end
    until not result.next(castles)
result.free(castles)
    return true
end
 
Last edited:
Thank you very much! Can you help me again? Or someone else? I found several problems i fixed by myself but now i have found one i do not understand again.
Code:
    local acc = db.storeQuery('SELECT id FROM players WHERE account_id = '.. getPlayerAccountId(cid) .. ' AND id != ' .. id)
    if acc:getID() ~= -1 then
        repeat
            if table.find(owners, acc:getDataInt('id')) then
                return doPlayerSendCancel(cid, 'Your account already owns a castle.')
            end
        until not acc:next()
        acc:free()
    end
This code occurs the following error:
Code:
attempt to index 'acc' (a bolean value)

Thanks for help!
 
have fun
Code:
    local acc = db.storeQuery('SELECT id FROM players WHERE account_id = '.. getPlayerAccountId(cid) .. ' AND id != ' .. id)
    if acc ~= false then
        repeat
            if table.find(owners,result.getDataInt(acc, "id")) then
                return doPlayerSendCancel(cid, 'Your account already owns a castle.')
            end
        until not result.next(acc)
         result.free(acc)
    end
 
Last edited:
Hey i just fixed it before i read your answer. but im not sure that this is 100% correct.
At the moment all works, but maybe my code will causes new bugs? What do you think?
Code:
    local acc = db.storeQuery('SELECT id FROM players WHERE account_id = '.. getPlayerAccountId(cid) .. ' AND id != ' .. id)
    if acc then
        repeat
            if table.find(owners, acc:getDataInt('id')) then
                return doPlayerSendCancel(cid, 'Your account already owns a castle.')
            end
        until not acc:next()
        acc:free()
    end
 
Back
Top