• 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 attempt to index a nil value

nanduzenho

Member
Joined
Mar 21, 2021
Messages
190
Solutions
1
Reaction score
16
GitHub
nanduzenho
Good night, can anyone help me with this error?
1715120969354.png

Lua:
local function checkBlood(position)
    local tile = Tile(position)
    local items = tile:getItems()
    for i = 1, #items do
        local item = items[i]
        if not ItemType(item):isMovable() then
            item:remove()
        end
    end
end
local thornKnightDeath = CreatureEvent("ThornKnightDeath")
function thornKnightDeath.onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    if creature:getName():lower() == "mounted thorn knight" then
        creature:say("The thorn knight unmounts!", TALKTYPE_MONSTER_SAY)
        Game.createMonster("the shielded thorn knight", creature:getPosition(), true, true)
        Game.createMonster("thorn steed", creature:getPosition(), false, true)
        addEvent(checkBlood, 1, creature:getPosition())
        return true
    elseif creature:getName():lower() == "the shielded thorn knight" then
        Game.createMonster("the enraged thorn knight", creature:getPosition(), true, true)
        addEvent(checkBlood, 1, creature:getPosition())
        return true
    end
    return true
end

thornKnightDeath:register()
 
Solution
It hasn't been tested yet!!
try!
Lua:
local function checkBlood(position)
    local tile = Tile(position)
    local items = tile:getItems()
    for i = #items, 1, -1 do
        local item = items[i]
        if not ItemType(item:getId()):isMovable() then
            item:remove()
        end
    end
end

local function createThornKnight(position)
    Game.createMonster("the shielded thorn knight", position, true, true)
    Game.createMonster("thorn steed", position, false, true)
    addEvent(checkBlood, 1, position)
end

local function createEnragedThornKnight(position)
    Game.createMonster("the enraged thorn knight", position, true, true)
    addEvent(checkBlood, 1, position)
end

local thornKnightDeath =...
Good night, can anyone help me with this error?
View attachment 84460

Lua:
local function checkBlood(position)
    local tile = Tile(position)
    local items = tile:getItems()
    for i = 1, #items do
        local item = items[i]
        if not ItemType(item):isMovable() then
            item:remove()
        end
    end
end
local thornKnightDeath = CreatureEvent("ThornKnightDeath")
function thornKnightDeath.onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    if creature:getName():lower() == "mounted thorn knight" then
        creature:say("The thorn knight unmounts!", TALKTYPE_MONSTER_SAY)
        Game.createMonster("the shielded thorn knight", creature:getPosition(), true, true)
        Game.createMonster("thorn steed", creature:getPosition(), false, true)
        addEvent(checkBlood, 1, creature:getPosition())
        return true
    elseif creature:getName():lower() == "the shielded thorn knight" then
        Game.createMonster("the enraged thorn knight", creature:getPosition(), true, true)
        addEvent(checkBlood, 1, creature:getPosition())
        return true
    end
    return true
end

thornKnightDeath:register()
Lua:
local function checkBlood(position)
    local tile = Tile(position)
    local items = tile:getItems()
    for i = 1, #items do
        local item = items[i]
        if not ItemType(item):isMovable() then
            item:remove()
        end
    end
end
local thornKnightDeath = CreatureEvent("ThornKnightDeath")
function thornKnightDeath.onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    local targetMonster = creature:getMonster()
    if not targetMonster then
        return true
    end
    if targetMonster:getName():lower() == 'mounted thorn knight' then
        targetMonster:say('The thorn knight unmounts!', TALKTYPE_MONSTER_SAY)
        Game.createMonster('the shielded thorn knight', targetMonster:getPosition(), true, true)
        Game.createMonster('thorn steed', targetMonster:getPosition(), false, true)
        addEvent(checkBlood, 1, targetMonster:getPosition())
        return true
    elseif targetMonster:getName():lower() == 'the shielded thorn knight' then
        Game.createMonster('the enraged thorn knight', targetMonster:getPosition(), true, true)
        addEvent(checkBlood, 1, targetMonster:getPosition())
        return true
    end
    return true
end
thornKnightDeath:register()
 
Lua:
local function checkBlood(position)
    local tile = Tile(position)
    local items = tile:getItems()
    for i = 1, #items do
        local item = items[i]
        if not ItemType(item):isMovable() then
            item:remove()
        end
    end
end
local thornKnightDeath = CreatureEvent("ThornKnightDeath")
function thornKnightDeath.onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    local targetMonster = creature:getMonster()
    if not targetMonster then
        return true
    end
    if targetMonster:getName():lower() == 'mounted thorn knight' then
        targetMonster:say('The thorn knight unmounts!', TALKTYPE_MONSTER_SAY)
        Game.createMonster('the shielded thorn knight', targetMonster:getPosition(), true, true)
        Game.createMonster('thorn steed', targetMonster:getPosition(), false, true)
        addEvent(checkBlood, 1, targetMonster:getPosition())
        return true
    elseif targetMonster:getName():lower() == 'the shielded thorn knight' then
        Game.createMonster('the enraged thorn knight', targetMonster:getPosition(), true, true)
        addEvent(checkBlood, 1, targetMonster:getPosition())
        return true
    end
    return true
end
thornKnightDeath:register()
error continues on the line:
Lua:
if not ItemType(item):isMovable() then
 
It hasn't been tested yet!!
try!
Lua:
local function checkBlood(position)
    local tile = Tile(position)
    local items = tile:getItems()
    for i = #items, 1, -1 do
        local item = items[i]
        if not ItemType(item:getId()):isMovable() then
            item:remove()
        end
    end
end

local function createThornKnight(position)
    Game.createMonster("the shielded thorn knight", position, true, true)
    Game.createMonster("thorn steed", position, false, true)
    addEvent(checkBlood, 1, position)
end

local function createEnragedThornKnight(position)
    Game.createMonster("the enraged thorn knight", position, true, true)
    addEvent(checkBlood, 1, position)
end

local thornKnightDeath = CreatureEvent("ThornKnightDeath")

function thornKnightDeath.onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    local creatureName = creature:getName():lower()
    if creatureName == "mounted thorn knight" then
        creature:say("The thorn knight unmounts!", TALKTYPE_MONSTER_SAY)
        createThornKnight(creature:getPosition())
    elseif creatureName == "the shielded thorn knight" then
        createEnragedThornKnight(creature:getPosition())
    end
    return true
end

thornKnightDeath:register()
 
Solution
It hasn't been tested yet!!
try!
Lua:
local function checkBlood(position)
    local tile = Tile(position)
    local items = tile:getItems()
    for i = #items, 1, -1 do
        local item = items[i]
        if not ItemType(item:getId()):isMovable() then
            item:remove()
        end
    end
end

local function createThornKnight(position)
    Game.createMonster("the shielded thorn knight", position, true, true)
    Game.createMonster("thorn steed", position, false, true)
    addEvent(checkBlood, 1, position)
end

local function createEnragedThornKnight(position)
    Game.createMonster("the enraged thorn knight", position, true, true)
    addEvent(checkBlood, 1, position)
end

local thornKnightDeath = CreatureEvent("ThornKnightDeath")

function thornKnightDeath.onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    local creatureName = creature:getName():lower()
    if creatureName == "mounted thorn knight" then
        creature:say("The thorn knight unmounts!", TALKTYPE_MONSTER_SAY)
        createThornKnight(creature:getPosition())
    elseif creatureName == "the shielded thorn knight" then
        createEnragedThornKnight(creature:getPosition())
    end
    return true
end

thornKnightDeath:register()
Thx bro perfect
 
Back
Top