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

Use an item, get castle not working, error in console

elementrix

New Member
Joined
Feb 28, 2017
Messages
20
Reaction score
0
TFS 0.3.6

this is the error
Code:
[01/03/2017 22:57:06] [Error - GlobalEvent Interface]
[01/03/2017 22:57:06] data/globalevents/scripts/castles.lua:onThink
[01/03/2017 22:57:06] Description:
[01/03/2017 22:57:06] data/globalevents/scripts/castles.lua:2: attempt to call field 'getResult' (a nil value)
[01/03/2017 22:57:06] stack traceback:
[01/03/2017 22:57:06]     data/globalevents/scripts/castles.lua:2: in function <data/globalevents/scripts/castles.lua:1>
[01/03/2017 22:57:06] [Error - GlobalEvents::think] Couldn't execute event: castles

And this is the script globalevents/scripts/castles.lua

Lua:
function onThink()
    local castles = db.getResult('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, 2)
        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

EDIT: New error now

Code:
[02/03/2017 00:27:30] [Error - Action Interface] 
[02/03/2017 00:27:30] data/actions/scripts/castle.lua:onUse
[02/03/2017 00:27:30] Description: 
[02/03/2017 00:27:30] data/actions/scripts/castle.lua:10: attempt to call field 'getResult' (a nil value)
[02/03/2017 00:27:30] stack traceback:
[02/03/2017 00:27:30]     data/actions/scripts/castle.lua:10: in function <data/actions/scripts/castle.lua:3>

And this is the script actions/scripts/castle.lua

Lua:
local lvl = getConfigInfo('levelToBuyHouse')

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerLevel(cid) < lvl then
        return doPlayerSendCancel(cid, 'You have to be at least Level ' .. lvl .. ' to purchase a house.')
    elseif isPlayerPzLocked(cid) then
        return doPlayerSendCancel(cid, 'You cannot use this while PZlocked.')
    end

    local castles = db.getResult('SELECT id FROM houses WHERE town=4')
    if castles:getID() == -1 then
        return true
    end

    local owners, id, castle = {}, getPlayerGUID(cid), nil
    repeat
        local hid = castles:getDataInt('id')
        local owner = getHouseInfo(hid).owner
        if owner == id then
            return doPlayerSendCancel(cid, 'Your character already owns a castle.')
        elseif owner == 0 or owner == 2 then
            if castle == nil then
                castle = hid
            end
        else
            table.insert(owners, owner)
        end
    until not castles:next()
    castles:free()

    if not castle then
        return doPlayerSendCancel(cid, 'There are no castles available at this moment.')
    end

    local acc = db.getResult('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

    doRemoveItem(item.uid)

    local k = getHouseInfo(castle)
    setHouseOwner(castle, id)
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Welcome to your new home, ' .. k.name .. '! You can now step into the teleport. To get here again, enter the teleport in Temple +1')
    doBroadcastMessage(getCreatureName(cid) .. ' has bought ' .. k.name .. ' using a Castle Box.', MESSAGE_EVENT_ADVANCE)

    local old = getThingPos(cid)
    doTeleportThing(cid, k.entry)
    doSendMagicEffect(old, CONST_ME_TELEPORT)
    doSendMagicEffect(k.entry, CONST_ME_TELEPORT)
    return true
end
 
Last edited:
Check your database, do you have a table called houses, does it contain a town and id, if it does are the houses in town no 4?
 
And you got id aswell in the houses table? Please check the names, even copy paste them if you need to since even an A insted of an a can be enough for it to bug.
Can you clarify a bit? Where should I check? houses.xml?

EDIT: what is "lastwarning" the number that first 2 castles have, 1488207686 and 1488207695 before the name. Should i set in DB myself as an owner?
 
In the database, either extract your schema and post ONLY the houses table (to avoid giving out passwords etc) or take a full SS of the houses table.
Probbly not needed, but im not 100% sure about 0.x versions, but give it a try
 
Back
Top