• 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 TFs 1.2 nil value problem

Szafi

www.rookwar.pl
Joined
Mar 2, 2009
Messages
165
Reaction score
10
Location
Poland
Hello.

I convert tfs 0.4 my scripts to 1.2. I do not know what could be wrong.

Console:
Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/pomniki/pomnik_z_najlepszym_graczem.lua:onThink
...alevents/scripts/pomniki/pomnik_z_najlepszym_graczem.lua:13: attempt to call global 'getThingFromPos' (a nil value)
stack traceback:
        [C]: in function 'getThingFromPos'
        ...alevents/scripts/pomniki/pomnik_z_najlepszym_graczem.lua:13: in function <...alevents/scripts/pomniki/pomnik_z_najlepszym_graczem.lua:10>
[Error - GlobalEvents::think] Failed to execute event: hof

Script:
Code:
local tbl = {
    [1] = {pos= {x = 1036, y = 1025, z = 7, stackpos = 1}, prof = 'all', text2 = 'player'}, -- lvl
    -- [2] = {pos= {x = 1030, y = 1027, z = 7, stackpos = 1}, prof = '1, 5', text2 = 'sorcerer'}, -- sorcerer, ms
    -- [3] = {pos= {x = 1032, y = 1027, z = 7, stackpos = 1}, prof = '2, 6', text2 = 'druid'}, -- druid, ed
    -- [4] = {pos= {x = 1034, y = 1027, z = 7, stackpos = 1}, prof = '3, 7', text2 = 'paladin'}, -- palladin, rp
    -- [5] = {pos= {x = 1036, y = 1027, z = 7, stackpos = 1}, prof = '4, 8', text2 = 'knight'}, -- knight, ek
    --[index] = {pos = {pozycja, pamietaj o stackpos!}, prof = 'id profesji', text2 = 'string z nazwa profesji'},
}
function onThink(interval)
    local best, profe, kam = '', 0, 0
    for index, options in ipairs(tbl) do
        local kam = getThingFromPos(options.pos).uid
        if(options.prof == 'all') then
            best = db.getResult("SELECT `level`,`name` FROM `players` WHERE `group_id` < '2' AND `account_id` > '1' ORDER BY `experience` DESC LIMIT 1;")
            if(best:getID() ~= -1) then
                doItemSetAttribute(kam, 'description', 'Najwiekszy poziom na serwerze ma gracz '..best:getDataString('name')..'. Posiada '..best:getDataInt('level')..' level.')
            else
                doItemSetAttribute(kam, 'description', 'Aktualnie brak informacji')
            end
            doSendMagicEffect(options.pos, 66)
        else
            profe = string.explode(options.prof, ',')
            best = db.getResult("SELECT `level`,`name` FROM `players` WHERE (`vocation` = '"..tonumber(profe[1]).."' OR `vocation` = '"..tonumber(profe[2]).."') AND `group_id` < '2' AND `account_id` > '1' ORDER BY `experience` DESC LIMIT 1;")
            if(best:getID() ~= -1) then
                doItemSetAttribute(kam, 'description', 'Currently, the best '..options.text2..' is '..best:getDataString('name')..' ('..best:getDataInt('level')..' level)')
            else
                doItemSetAttribute(kam, 'description', 'Currently, on a server doesn\'t play none '..options.text2)
            end
            doSendMagicEffect(options.pos, 66)
        end
    end
    return true
end
 
add this to your data/lib/compat/compat.lua or data/global.lua
Code:
function getThingfromPos(pos)
    local tile = Tile(pos)
    if tile == nil then
        return pushThing(nil)
    end

    local thing
    if stackpos == STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE then
        thing = tile:getTopCreature()
        if thing == nil then
            local item = tile:getTopDownItem()
            if item ~= nil and item:getType():isMovable() then
                thing = item
            end
        end
    elseif stackpos == STACKPOS_TOP_FIELD then
        thing = tile:getFieldItem()
    elseif stackpos == STACKPOS_TOP_CREATURE then
        thing = tile:getTopCreature()
    else
        thing = tile:getThing(pos.stackpos)
    end
    return pushThing(thing)
end

also replace
Code:
getResult
for
Code:
storeQuery
 
I add your code to compat.lua (last line)

and script dont work

Console:
Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/pomniki/pomnik_z_najlepszym_graczem.lua:onThink
...alevents/scripts/pomniki/pomnik_z_najlepszym_graczem.lua:13: attempt to call global 'getThingFromPos' (a nil value)
stack traceback:
        [C]: in function 'getThingFromPos'
        ...alevents/scripts/pomniki/pomnik_z_najlepszym_graczem.lua:13: in function <...alevents/scripts/pomniki/pomnik_z_najlepszym_graczem.lua:10>
[Error - GlobalEvents::think] Failed to execute event: pomnik_best_exp_playera
 
Back
Top